@ac-kit/format-zip 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/README.md +77 -19
  3. package/dist/_producer-stream.d.ts +14 -0
  4. package/dist/_producer-stream.d.ts.map +1 -0
  5. package/dist/_producer-stream.js +80 -0
  6. package/dist/_producer-stream.js.map +1 -0
  7. package/dist/_zip-directory.d.ts +97 -0
  8. package/dist/_zip-directory.d.ts.map +1 -0
  9. package/dist/_zip-directory.js +541 -0
  10. package/dist/_zip-directory.js.map +1 -0
  11. package/dist/_zip-entries.d.ts +31 -0
  12. package/dist/_zip-entries.d.ts.map +1 -0
  13. package/dist/_zip-entries.js +192 -0
  14. package/dist/_zip-entries.js.map +1 -0
  15. package/dist/_zip-format.d.ts +33 -0
  16. package/dist/_zip-format.d.ts.map +1 -1
  17. package/dist/_zip-format.js +33 -0
  18. package/dist/_zip-format.js.map +1 -1
  19. package/dist/_zip-headers.d.ts +49 -0
  20. package/dist/_zip-headers.d.ts.map +1 -0
  21. package/dist/_zip-headers.js +158 -0
  22. package/dist/_zip-headers.js.map +1 -0
  23. package/dist/index.d.ts +2 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +2 -0
  26. package/dist/index.js.map +1 -1
  27. package/dist/zip-archive.d.ts +41 -1
  28. package/dist/zip-archive.d.ts.map +1 -1
  29. package/dist/zip-archive.js +14 -197
  30. package/dist/zip-archive.js.map +1 -1
  31. package/dist/zip-error.d.ts +3 -2
  32. package/dist/zip-error.d.ts.map +1 -1
  33. package/dist/zip-error.js +3 -2
  34. package/dist/zip-error.js.map +1 -1
  35. package/dist/zip-source.d.ts +59 -0
  36. package/dist/zip-source.d.ts.map +1 -0
  37. package/dist/zip-source.js +149 -0
  38. package/dist/zip-source.js.map +1 -0
  39. package/dist/zip-stream-writer.d.ts +61 -0
  40. package/dist/zip-stream-writer.d.ts.map +1 -0
  41. package/dist/zip-stream-writer.js +419 -0
  42. package/dist/zip-stream-writer.js.map +1 -0
  43. package/dist/zip-writer.d.ts +52 -21
  44. package/dist/zip-writer.d.ts.map +1 -1
  45. package/dist/zip-writer.js +18 -206
  46. package/dist/zip-writer.js.map +1 -1
  47. package/package.json +6 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,81 @@
1
1
  # @ac-kit/format-zip
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [065cf8d]
8
+ - Updated dependencies [065cf8d]
9
+ - Updated dependencies [065cf8d]
10
+ - @ac-kit/core@0.11.0
11
+ - @ac-kit/noncrypto-hash@0.2.1
12
+
13
+ ## 0.3.0
14
+
15
+ ### Minor Changes
16
+
17
+ - 5152230: Streamed and ZIP64 writing, and reading by ranges.
18
+
19
+ - `createZipStream(entries, options?)`: the archive `createZip` writes, as a
20
+ `ReadableStream` produced as it is read. `entries` may be an async iterable,
21
+ pulled one entry at a time once the previous entry's content has ended.
22
+ - `ZipEntryInit.content` accepts a `ReadableStream`: read as the archive is,
23
+ deflated through `CompressionStream` unless `method` is stored, its CRC-32
24
+ and sizes in a data descriptor after it (general purpose bit 3). New
25
+ `ZipEntryInit.size` (checked: `TypeError` against content in memory,
26
+ `RangeError` when a stream ends elsewhere) and `ZipEntryInit.zip64` (ZIP64
27
+ sizes in the local header and descriptor, so a stream of unknown size may
28
+ pass 4 GiB; without it, `ZipLimitError` at 4 GiB).
29
+ - **Behaviour change:** `createZip` and `createZipStream` write ZIP64 (extra
30
+ fields, end record and locator) where a count, size or offset needs it,
31
+ instead of failing with `ZipLimitError`: 65 535 entries or more, past 4 GiB.
32
+ An archive that needs no ZIP64 is byte for byte what 0.2.0 wrote. An entry
33
+ with ZIP64 sizes in its local header has them in its central header too.
34
+ `createZip` also accepts an async iterable.
35
+ - `openZipSource(source, limits, signal?)`: reads an archive by ranges from a
36
+ `Blob`, bytes, or a `ZipSource` (`size`, `read(offset, length, signal?)`,
37
+ optional `stream(offset, length, signal?)`), with the new
38
+ `ZipSourceLimits.maxDirectorySize`. One read of the end records, one of the
39
+ directory, one of each entry's local header the first time it is read.
40
+ - `ZipArchive.stream(entry, signal?)`: an entry's content as a stream, size and
41
+ CRC-32 checked at its end, not bounded by `maxEntrySize`.
42
+ `ZipArchive.streamRange(entry, start, length, signal?)`: a byte range of a
43
+ stored entry. **Breaking:** code implementing `ZipArchive` itself must add both `stream` and
44
+ `streamRange`.
45
+ - Stricter reading, in `openZip` and `openZipSource` alike: the end record must
46
+ agree with the directory's place and contents. Unrecognized trailing bytes
47
+ are rejected; a digital signature record is allowed. Malformed end records
48
+ in the archive comment are skipped, but an over-limit directory is not
49
+ replaced with another candidate. End records naming more than four distinct
50
+ directories (or ZIP64 records to fetch) are refused as ambiguous, so forged
51
+ records cannot multiply the directory's parsing or reads. An exact count of
52
+ 65 535 without ZIP64 records is accepted, ZIP64 disk fields and record
53
+ extent are checked (multi-disk is `UnsupportedError`), and an entry whose local header or data overlaps another entry or the central
54
+ directory fails with `ZipFormatError` when read. UTF-8 names and comments keep
55
+ a leading U+FEFF. Aborting `read` or `createZip` now rejects with the abort
56
+ reason instead of resolving with partial bytes.
57
+
58
+ ### Patch Changes
59
+
60
+ - Updated dependencies [2a0fe74]
61
+ - Updated dependencies [5152230]
62
+ - Updated dependencies [2a0fe74]
63
+ - Updated dependencies [5152230]
64
+ - Updated dependencies [5152230]
65
+ - Updated dependencies [2a0fe74]
66
+ - Updated dependencies [2a0fe74]
67
+ - Updated dependencies [5152230]
68
+ - Updated dependencies [5152230]
69
+ - Updated dependencies [5152230]
70
+ - Updated dependencies [5152230]
71
+ - Updated dependencies [5152230]
72
+ - Updated dependencies [5152230]
73
+ - Updated dependencies [5152230]
74
+ - Updated dependencies [5152230]
75
+ - Updated dependencies [5152230]
76
+ - @ac-kit/core@0.10.0
77
+ - @ac-kit/noncrypto-hash@0.2.0
78
+
3
79
  ## 0.2.0
4
80
 
5
81
  ### Minor Changes
package/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # @ac-kit/format-zip
2
2
 
3
3
  ZIP archives: the central directory, ZIP64 included, and each entry's content
4
- read on demand within limits; and archives written whole, stored or deflated.
4
+ read on demand within limits, from bytes in memory or by ranges from a `Blob`
5
+ or a ranged source; and archives written whole or streamed, stored or deflated,
6
+ with ZIP64 where they need it.
5
7
 
6
8
  ```ts
7
9
  import { createZip, openZip } from "@ac-kit/format-zip";
@@ -22,34 +24,90 @@ const written = await createZip([
22
24
  ]);
23
25
  ```
24
26
 
27
+ An archive too large to hold in memory is written as a stream, its entries'
28
+ content streamed too, and read back by ranges:
29
+
30
+ ```ts
31
+ import { createZipStream, openZipSource, ZipMethod } from "@ac-kit/format-zip";
32
+
33
+ const recording = new Blob(["WARC/1.1\r\n..."]).stream();
34
+ const output = createZipStream(
35
+ (async function* () {
36
+ // Stored, so a reader can seek inside it; ZIP64 sizes, so it may pass 4 GiB.
37
+ yield {
38
+ name: "archive/data.warc",
39
+ content: recording,
40
+ method: ZipMethod.STORED,
41
+ zip64: true,
42
+ };
43
+ yield { name: "indexes/index.cdx", content: new TextEncoder().encode("") };
44
+ })(),
45
+ );
46
+ const file = new Blob([await new Response(output).arrayBuffer()]);
47
+
48
+ const archive = await openZipSource(file, {
49
+ maxEntries: 1_000,
50
+ maxEntrySize: 64 * 1024 * 1024,
51
+ maxCompressionRatio: 200,
52
+ maxDirectorySize: 1024 * 1024,
53
+ });
54
+ const warc = archive.entry("archive/data.warc")!;
55
+ // Bytes 0 to 7 of the stored entry, read from the Blob alone.
56
+ const head = await new Response(archive.streamRange(warc, 0, 8)).text();
57
+ ```
58
+
25
59
  ## What it exposes
26
60
 
27
61
  - `openZip` — reads the end of central directory and the directory itself
28
- (APPNOTE 6.3, ZIP64 included) and returns the entries. Names are UTF-8 when
29
- flagged, from an Info-ZIP Unicode Path field when present, code page 437
30
- otherwise.
62
+ (APPNOTE 6.3, ZIP64 included) from bytes in memory and returns the entries.
63
+ Names are UTF-8 when flagged, from an Info-ZIP Unicode Path field when
64
+ present, code page 437 otherwise.
65
+ - `openZipSource` — the same from a `Blob` (a `File`, Node's `fs.openAsBlob`) or
66
+ a `ZipSource` (`size`, `read(offset, length)`, optionally
67
+ `stream(offset, length)`: a file, HTTP `Range` requests, storage): one read of
68
+ the end records, one of the directory (bounded by `maxDirectorySize`), and
69
+ one of each entry's local header the first time it is read, cached after.
31
70
  - `ZipArchive.read` — an entry's content, stored or deflated, inflated with
32
71
  `DecompressionStream` and checked against its size and CRC-32.
72
+ - `ZipArchive.stream` — the same as a stream, inflated as it is pulled, its
73
+ size and CRC-32 checked when it ends; memory is one chunk whatever the size.
74
+ - `ZipArchive.streamRange` — a byte range of a stored entry, read from the
75
+ source as it is pulled (one record of a WARC stored in a WACZ).
33
76
  - `createZip` — an archive of the entries given, in their order, each deflated
34
- with `CompressionStream` or stored, with its CRC-32 and sizes in its local
35
- header. A name or comment holding anything but ASCII is written in UTF-8 and
36
- flagged so. Without a `lastModified`, an entry is dated 1980-01-01, so the
37
- same entries always make the same bytes.
77
+ with `CompressionStream` or stored. Content in memory gets its CRC-32 and
78
+ sizes in its local header; a name or comment holding anything but ASCII is
79
+ written in UTF-8 and flagged so. Without a `lastModified`, an entry is dated
80
+ 1980-01-01, so the same entries always make the same bytes.
81
+ - `createZipStream` — the same archive as a `ReadableStream`, produced as it is
82
+ read. Entries may come from an async iterable, pulled one at a time, and
83
+ content may be a `ReadableStream`, read as the archive is, its CRC-32 and
84
+ sizes in a data descriptor after it.
38
85
  - `ZipMethod` — the stored and deflate method numbers.
39
86
  - `ZipFormatError`, `ZipLimitError` — a broken archive, and one past a limit.
40
87
 
41
88
  Every limit is required, since an archive states its own sizes: the number of
42
- entries, an entry's uncompressed size, and its compression ratio, which stops a
43
- zip bomb before it inflates. Encrypted entries, methods other than stored and
44
- deflate, and archives split across disks are refused. An entry's name is data,
45
- not a safe path: check it before writing anything out.
46
-
47
- `createZip` writes no ZIP64 structures: an archive of more than 65 534 entries
48
- (65 535 is the count that announces ZIP64),
49
- or past 4 GiB, fails with `ZipLimitError`. Its time and memory are linear in
50
- the entries' total size, the whole archive being built in memory. Entry names
51
- must be relative and `/`-separated, each given once; the archive's comment must
52
- be ASCII, since the format has no flag for its encoding.
89
+ entries, an entry's uncompressed size, its compression ratio, which stops a zip
90
+ bomb before it inflates, and for ranged reads the central directory's size.
91
+ Encrypted entries, methods other than stored and deflate, and archives split
92
+ across disks are refused. An entry's name is data, not a safe path: check it
93
+ before writing anything out.
94
+
95
+ The writers use ZIP64 where a count, size or offset needs it, and nowhere else:
96
+ 65 535 entries or more, a directory, entry or offset past 4 GiB. A content
97
+ stream of unknown size needs `zip64: true` to pass 4 GiB, since its local header
98
+ is written before its size is known; without it, it fails with `ZipLimitError`
99
+ there. An archive that needs no ZIP64 is byte for byte what version 0.2.0
100
+ wrote. Entry names must be relative and `/`-separated, each given once; the
101
+ archive's comment must be ASCII, since the format has no flag for its encoding.
102
+
103
+ A streamed entry is followed by a data descriptor, which readers working from
104
+ the central directory (Info-ZIP, Python's `zipfile`, 7-Zip, wabac.js, this
105
+ package) read; readers walking local headers one after the other (Java's
106
+ `ZipInputStream`) cannot read a stored one. `createZipStream` reads a content
107
+ stream only a few chunks ahead of its reader, so its memory is the central
108
+ directory, O(entries), plus those chunks and the deflate window. Cancelling the
109
+ output or aborting the signal cancels the content stream being read; the bytes
110
+ already read are then a truncated archive.
53
111
 
54
112
  Portable: no Node.js built-ins.
55
113
 
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A pull-driven stream over the chunks `produce` yields: nothing runs until a
3
+ * read, and no chunk is queued ahead of one (`ReadableStream.from`, high-water
4
+ * mark 0).
5
+ *
6
+ * `produce` receives a signal that aborts when `signal` does or when the stream
7
+ * is cancelled, with that reason; it must stop its pending work on it. A read
8
+ * pending when that happens fails with the reason at once, without waiting for
9
+ * the producer, and never ends as if complete. The producer is then returned so
10
+ * its `finally` blocks release what it holds: at once when it is suspended at a
11
+ * `yield`, or as soon as its pending work settles otherwise.
12
+ */
13
+ export declare function producerStream_<T>(produce: (signal: AbortSignal) => AsyncGenerator<T, void, undefined>, signal: AbortSignal | undefined): ReadableStream<T>;
14
+ //# sourceMappingURL=_producer-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_producer-stream.d.ts","sourceRoot":"","sources":["../src/_producer-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAChC,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EACpE,MAAM,EAAE,WAAW,GAAG,SAAS,GAC7B,cAAc,CAAC,CAAC,CAAC,CA+CnB"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * A pull-driven stream over the chunks `produce` yields: nothing runs until a
3
+ * read, and no chunk is queued ahead of one (`ReadableStream.from`, high-water
4
+ * mark 0).
5
+ *
6
+ * `produce` receives a signal that aborts when `signal` does or when the stream
7
+ * is cancelled, with that reason; it must stop its pending work on it. A read
8
+ * pending when that happens fails with the reason at once, without waiting for
9
+ * the producer, and never ends as if complete. The producer is then returned so
10
+ * its `finally` blocks release what it holds: at once when it is suspended at a
11
+ * `yield`, or as soon as its pending work settles otherwise.
12
+ */
13
+ export function producerStream_(produce, signal) {
14
+ const cancelled = new AbortController();
15
+ const combined = signal === undefined
16
+ ? cancelled.signal
17
+ : AbortSignal.any([signal, cancelled.signal]);
18
+ const generator = produce(combined);
19
+ // The producer's step in flight, which a raced read may have left behind.
20
+ let running = null;
21
+ const finish = () => generator.return(undefined).catch(() => { });
22
+ const handleAbort = () => void finish();
23
+ combined.addEventListener("abort", handleAbort, { once: true });
24
+ const iterator = {
25
+ next: async () => {
26
+ try {
27
+ combined.throwIfAborted();
28
+ const step = generator.next();
29
+ running = step;
30
+ const settle = () => {
31
+ if (running === step) {
32
+ running = null;
33
+ }
34
+ };
35
+ step.then(settle, settle);
36
+ const result = await raceAbort_(step, combined);
37
+ if (result.done === true) {
38
+ combined.removeEventListener("abort", handleAbort);
39
+ }
40
+ return result;
41
+ }
42
+ catch (error) {
43
+ combined.removeEventListener("abort", handleAbort);
44
+ throw combined.aborted ? combined.reason : error;
45
+ }
46
+ },
47
+ return: async (reason) => {
48
+ cancelled.abort(reason);
49
+ // A producer suspended at a yield finishes now; one still running
50
+ // finishes when its pending work settles, which is not awaited here.
51
+ if (running === null) {
52
+ await finish();
53
+ }
54
+ return { done: true, value: undefined };
55
+ },
56
+ };
57
+ return ReadableStream.from({ [Symbol.asyncIterator]: () => iterator });
58
+ }
59
+ /** `promise`, or a rejection with `signal`'s reason as soon as it aborts. */
60
+ function raceAbort_(promise, signal) {
61
+ return new Promise((resolve, reject) => {
62
+ const handleAbort = () => reject(signal.reason);
63
+ // The step may have aborted the signal itself, synchronously, before
64
+ // this listener could hear it.
65
+ if (signal.aborted) {
66
+ handleAbort();
67
+ }
68
+ else {
69
+ signal.addEventListener("abort", handleAbort, { once: true });
70
+ }
71
+ promise.then((value) => {
72
+ signal.removeEventListener("abort", handleAbort);
73
+ resolve(value);
74
+ }, (error) => {
75
+ signal.removeEventListener("abort", handleAbort);
76
+ reject(error);
77
+ });
78
+ });
79
+ }
80
+ //# sourceMappingURL=_producer-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_producer-stream.js","sourceRoot":"","sources":["../src/_producer-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAC9B,OAAoE,EACpE,MAA+B;IAE/B,MAAM,SAAS,GAAG,IAAI,eAAe,EAAE,CAAC;IACxC,MAAM,QAAQ,GACb,MAAM,KAAK,SAAS;QACnB,CAAC,CAAC,SAAS,CAAC,MAAM;QAClB,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,MAAM,SA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CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,97 @@
1
+ import type { ZipEntry, ZipLimits } from "./zip-archive.js";
2
+ /**
3
+ * Most bytes from the end of an archive that hold its end records: the classic
4
+ * record with the longest comment, the ZIP64 locator and a version 1 ZIP64
5
+ * record.
6
+ */
7
+ export declare const MAX_TAIL_: number;
8
+ /** Where the central directory is, as the end records state it. */
9
+ export type DirectoryLocation_ = {
10
+ readonly count: number;
11
+ readonly directorySize: number;
12
+ readonly directoryOffset: number;
13
+ };
14
+ /** The classic end record, and where its ZIP64 record is when it defers to one. */
15
+ export type EndRecord_ = DirectoryLocation_ & {
16
+ readonly comment: string;
17
+ /** Archive offset of the ZIP64 end record, or `null` without ZIP64. */
18
+ readonly zip64RecordOffset: number | null;
19
+ /** Archive offset of the ZIP64 locator, or `null` without ZIP64. */
20
+ readonly zip64LocatorOffset: number | null;
21
+ };
22
+ /** A read of `length` bytes at archive offset `offset`. */
23
+ export type ReadRequest_ = {
24
+ readonly offset: number;
25
+ readonly length: number;
26
+ };
27
+ /** The central directory, read and parsed, and the archive's comment. */
28
+ export type ArchiveDirectory_ = {
29
+ readonly comment: string;
30
+ readonly entries: ZipEntry[];
31
+ readonly directoryOffset: number;
32
+ };
33
+ /**
34
+ * Finds and reads the central directory of an archive of `archiveSize` bytes
35
+ * whose last bytes are `tail`, yielding each further read it needs (a ZIP64 end
36
+ * record, the directory) and receiving its bytes, so a synchronous and an
37
+ * asynchronous caller share it.
38
+ *
39
+ * Candidates sharing a directory offset and entry count parse their headers
40
+ * once, then check their own declared extent and trailer. Groups are checked by
41
+ * decreasing directory end to reuse overlapping reads. Errors and ambiguity are
42
+ * still reported in end-record order. If the byte limit precludes fetching a
43
+ * directory for validation, the reader fails closed, as it does past
44
+ * {@link MAX_CANDIDATE_DIRECTORIES_} directories or ZIP64 records to fetch.
45
+ *
46
+ * @throws {ZipFormatError} When no candidate is valid (the error of the
47
+ * earliest candidate), multiple are valid and the earliest valid one is
48
+ * within limits, or the end records name too many directories.
49
+ * @throws {ZipLimitError} When the earliest valid candidate exceeds a limit or
50
+ * the byte limit prevents selecting a directory.
51
+ * @throws {UnsupportedError} When the earliest candidate spans several disks.
52
+ */
53
+ export declare function readArchiveDirectory_(tail: Uint8Array, archiveSize: number, limits: ZipLimits & {
54
+ readonly maxDirectorySize?: number;
55
+ }): Generator<ReadRequest_, ArchiveDirectory_, Uint8Array>;
56
+ /**
57
+ * The end of central directory record at `end` in `tail` (which starts at
58
+ * archive offset `tailOffset`), and the ZIP64 locator before it when the
59
+ * classic layout does not hold: the central directory ends where the record
60
+ * starts, or a ZIP64 locator before it points before itself. A count of exactly
61
+ * 65 535 without a locator is taken literally when the classic layout holds.
62
+ * Disk fields are 0, or the 0xFFFF sentinel where ZIP64 applies.
63
+ *
64
+ * @throws {ZipFormatError} When the layout it states does not hold.
65
+ * @throws {UnsupportedError} When it states several disks.
66
+ */
67
+ export declare function readEndCandidate_(tail: Uint8Array, end: number, tailOffset: number): EndRecord_;
68
+ /**
69
+ * Reads the ZIP64 end of central directory record in `record` (its first 56
70
+ * bytes at least), which starts at archive offset `recordOffset`, the locator
71
+ * being at `locatorOffset`. The record may carry an extensible data sector, as
72
+ * long as it ends exactly at the locator; the directory must end where it
73
+ * starts.
74
+ *
75
+ * @throws {ZipFormatError} When it is truncated, has another signature, or
76
+ * contradicts the layout.
77
+ * @throws {UnsupportedError} When it states several disks.
78
+ */
79
+ export declare function readZip64EndRecord_(record: Uint8Array, recordOffset: number, locatorOffset: number): DirectoryLocation_;
80
+ /**
81
+ * Reads `count` central headers from `directory`, which starts at archive
82
+ * offset `directoryOffset`, then validates any trailing records. Linear in the
83
+ * directory's size.
84
+ *
85
+ * @throws {ZipFormatError} When a header is truncated, has another signature,
86
+ * holds a broken ZIP64 field or UTF-8 name, or leaves unrecognized bytes.
87
+ */
88
+ export declare function readCentralDirectory_(directory: Uint8Array, directoryOffset: number, count: number): ZipEntry[];
89
+ /**
90
+ * The archive offset of an entry's data, after the local header in `header`
91
+ * (its first 30 bytes) at archive offset `headerOffset` and the name and extra
92
+ * field whose lengths it states.
93
+ *
94
+ * @throws {ZipFormatError} When it is truncated or has another signature.
95
+ */
96
+ export declare function readLocalHeader_(header: Uint8Array, headerOffset: number): number;
97
+ //# sourceMappingURL=_zip-directory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_zip-directory.d.ts","sourceRoot":"","sources":["../src/_zip-directory.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAW5D;;;;GAIG;AACH,eAAO,MAAM,SAAS,QAIe,CAAC;AAEtC,mEAAmE;AACnE,MAAM,MAAM,kBAAkB,GAAG;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CACjC,CAAC;AAEF,mFAAmF;AACnF,MAAM,MAAM,UAAU,GAAG,kBAAkB,GAAG;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,uEAAuE;IACvE,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,oEAAoE;IACpE,QAAQ,CAAC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3C,CAAC;AA8BF,2DAA2D;AAC3D,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhF,yEAAyE;AACzE,MAAM,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;IAC7B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CACjC,CAAC;AAQF;;;;;;;;;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