@ac-kit/format-zip 0.1.2 → 0.3.0
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.
- package/CHANGELOG.md +88 -0
- package/README.md +85 -9
- package/dist/_producer-stream.d.ts +14 -0
- package/dist/_producer-stream.d.ts.map +1 -0
- package/dist/_producer-stream.js +80 -0
- package/dist/_producer-stream.js.map +1 -0
- package/dist/_zip-directory.d.ts +97 -0
- package/dist/_zip-directory.d.ts.map +1 -0
- package/dist/_zip-directory.js +541 -0
- package/dist/_zip-directory.js.map +1 -0
- package/dist/_zip-entries.d.ts +31 -0
- package/dist/_zip-entries.d.ts.map +1 -0
- package/dist/_zip-entries.js +192 -0
- package/dist/_zip-entries.js.map +1 -0
- package/dist/_zip-format.d.ts +48 -0
- package/dist/_zip-format.d.ts.map +1 -0
- package/dist/_zip-format.js +49 -0
- package/dist/_zip-format.js.map +1 -0
- package/dist/_zip-headers.d.ts +49 -0
- package/dist/_zip-headers.d.ts.map +1 -0
- package/dist/_zip-headers.js +158 -0
- package/dist/_zip-headers.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/zip-archive.d.ts +45 -2
- package/dist/zip-archive.d.ts.map +1 -1
- package/dist/zip-archive.js +14 -202
- package/dist/zip-archive.js.map +1 -1
- package/dist/zip-error.d.ts +5 -1
- package/dist/zip-error.d.ts.map +1 -1
- package/dist/zip-error.js +5 -1
- package/dist/zip-error.js.map +1 -1
- package/dist/zip-method.d.ts +11 -0
- package/dist/zip-method.d.ts.map +1 -0
- package/dist/zip-method.js +12 -0
- package/dist/zip-method.js.map +1 -0
- package/dist/zip-source.d.ts +59 -0
- package/dist/zip-source.d.ts.map +1 -0
- package/dist/zip-source.js +149 -0
- package/dist/zip-source.js.map +1 -0
- package/dist/zip-stream-writer.d.ts +61 -0
- package/dist/zip-stream-writer.d.ts.map +1 -0
- package/dist/zip-stream-writer.js +419 -0
- package/dist/zip-stream-writer.js.map +1 -0
- package/dist/zip-writer.d.ts +89 -0
- package/dist/zip-writer.d.ts.map +1 -0
- package/dist/zip-writer.js +35 -0
- package/dist/zip-writer.js.map +1 -0
- package/package.json +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,93 @@
|
|
|
1
1
|
# @ac-kit/format-zip
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5152230: Streamed and ZIP64 writing, and reading by ranges.
|
|
8
|
+
|
|
9
|
+
- `createZipStream(entries, options?)`: the archive `createZip` writes, as a
|
|
10
|
+
`ReadableStream` produced as it is read. `entries` may be an async iterable,
|
|
11
|
+
pulled one entry at a time once the previous entry's content has ended.
|
|
12
|
+
- `ZipEntryInit.content` accepts a `ReadableStream`: read as the archive is,
|
|
13
|
+
deflated through `CompressionStream` unless `method` is stored, its CRC-32
|
|
14
|
+
and sizes in a data descriptor after it (general purpose bit 3). New
|
|
15
|
+
`ZipEntryInit.size` (checked: `TypeError` against content in memory,
|
|
16
|
+
`RangeError` when a stream ends elsewhere) and `ZipEntryInit.zip64` (ZIP64
|
|
17
|
+
sizes in the local header and descriptor, so a stream of unknown size may
|
|
18
|
+
pass 4 GiB; without it, `ZipLimitError` at 4 GiB).
|
|
19
|
+
- **Behaviour change:** `createZip` and `createZipStream` write ZIP64 (extra
|
|
20
|
+
fields, end record and locator) where a count, size or offset needs it,
|
|
21
|
+
instead of failing with `ZipLimitError`: 65 535 entries or more, past 4 GiB.
|
|
22
|
+
An archive that needs no ZIP64 is byte for byte what 0.2.0 wrote. An entry
|
|
23
|
+
with ZIP64 sizes in its local header has them in its central header too.
|
|
24
|
+
`createZip` also accepts an async iterable.
|
|
25
|
+
- `openZipSource(source, limits, signal?)`: reads an archive by ranges from a
|
|
26
|
+
`Blob`, bytes, or a `ZipSource` (`size`, `read(offset, length, signal?)`,
|
|
27
|
+
optional `stream(offset, length, signal?)`), with the new
|
|
28
|
+
`ZipSourceLimits.maxDirectorySize`. One read of the end records, one of the
|
|
29
|
+
directory, one of each entry's local header the first time it is read.
|
|
30
|
+
- `ZipArchive.stream(entry, signal?)`: an entry's content as a stream, size and
|
|
31
|
+
CRC-32 checked at its end, not bounded by `maxEntrySize`.
|
|
32
|
+
`ZipArchive.streamRange(entry, start, length, signal?)`: a byte range of a
|
|
33
|
+
stored entry. **Breaking:** code implementing `ZipArchive` itself must add both `stream` and
|
|
34
|
+
`streamRange`.
|
|
35
|
+
- Stricter reading, in `openZip` and `openZipSource` alike: the end record must
|
|
36
|
+
agree with the directory's place and contents. Unrecognized trailing bytes
|
|
37
|
+
are rejected; a digital signature record is allowed. Malformed end records
|
|
38
|
+
in the archive comment are skipped, but an over-limit directory is not
|
|
39
|
+
replaced with another candidate. End records naming more than four distinct
|
|
40
|
+
directories (or ZIP64 records to fetch) are refused as ambiguous, so forged
|
|
41
|
+
records cannot multiply the directory's parsing or reads. An exact count of
|
|
42
|
+
65 535 without ZIP64 records is accepted, ZIP64 disk fields and record
|
|
43
|
+
extent are checked (multi-disk is `UnsupportedError`), and an entry whose local header or data overlaps another entry or the central
|
|
44
|
+
directory fails with `ZipFormatError` when read. UTF-8 names and comments keep
|
|
45
|
+
a leading U+FEFF. Aborting `read` or `createZip` now rejects with the abort
|
|
46
|
+
reason instead of resolving with partial bytes.
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- Updated dependencies [2a0fe74]
|
|
51
|
+
- Updated dependencies [5152230]
|
|
52
|
+
- Updated dependencies [2a0fe74]
|
|
53
|
+
- Updated dependencies [5152230]
|
|
54
|
+
- Updated dependencies [5152230]
|
|
55
|
+
- Updated dependencies [2a0fe74]
|
|
56
|
+
- Updated dependencies [2a0fe74]
|
|
57
|
+
- Updated dependencies [5152230]
|
|
58
|
+
- Updated dependencies [5152230]
|
|
59
|
+
- Updated dependencies [5152230]
|
|
60
|
+
- Updated dependencies [5152230]
|
|
61
|
+
- Updated dependencies [5152230]
|
|
62
|
+
- Updated dependencies [5152230]
|
|
63
|
+
- Updated dependencies [5152230]
|
|
64
|
+
- Updated dependencies [5152230]
|
|
65
|
+
- Updated dependencies [5152230]
|
|
66
|
+
- @ac-kit/core@0.10.0
|
|
67
|
+
- @ac-kit/noncrypto-hash@0.2.0
|
|
68
|
+
|
|
69
|
+
## 0.2.0
|
|
70
|
+
|
|
71
|
+
### Minor Changes
|
|
72
|
+
|
|
73
|
+
- 20341eb: `createZip(entries, { comment?, signal? })`: a ZIP archive (APPNOTE 6.3) of
|
|
74
|
+
the entries given, in their order, each deflated through `CompressionStream`
|
|
75
|
+
or stored — deflated by default, stored when deflating would not shrink it —
|
|
76
|
+
with its CRC-32 and sizes in its local header. Names and comments holding
|
|
77
|
+
anything but ASCII are written in UTF-8 and flagged so; modification times are
|
|
78
|
+
MS-DOS local times, 1980-01-01 by default so the same entries make the same
|
|
79
|
+
bytes. No ZIP64 is written: more than 65 534 entries, or an archive past
|
|
80
|
+
4 GiB, fails with `ZipLimitError`. Invalid names (empty, absolute, holding
|
|
81
|
+
`\`, given twice, a directory with content) fail with `TypeError`.
|
|
82
|
+
`ZipMethod` names the stored and deflate method numbers `ZipEntry.method`
|
|
83
|
+
holds.
|
|
84
|
+
|
|
85
|
+
### Patch Changes
|
|
86
|
+
|
|
87
|
+
- Updated dependencies [20341eb]
|
|
88
|
+
- @ac-kit/core@0.9.0
|
|
89
|
+
- @ac-kit/noncrypto-hash@0.1.8
|
|
90
|
+
|
|
3
91
|
## 0.1.2
|
|
4
92
|
|
|
5
93
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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
|
|
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
|
-
import { openZip } from "@ac-kit/format-zip";
|
|
9
|
+
import { createZip, openZip } from "@ac-kit/format-zip";
|
|
8
10
|
|
|
9
11
|
const archive = openZip(bytes, {
|
|
10
12
|
maxEntries: 1_000,
|
|
@@ -15,23 +17,97 @@ for (const entry of archive.entries) {
|
|
|
15
17
|
console.log(entry.name, entry.size);
|
|
16
18
|
}
|
|
17
19
|
const content = await archive.read(archive.entry("META-INF/container.xml")!);
|
|
20
|
+
|
|
21
|
+
const written = await createZip([
|
|
22
|
+
{ name: "META-INF/" },
|
|
23
|
+
{ name: "META-INF/container.xml", content },
|
|
24
|
+
]);
|
|
25
|
+
```
|
|
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();
|
|
18
57
|
```
|
|
19
58
|
|
|
20
59
|
## What it exposes
|
|
21
60
|
|
|
22
61
|
- `openZip` — reads the end of central directory and the directory itself
|
|
23
|
-
(APPNOTE 6.3, ZIP64 included) and returns the entries.
|
|
24
|
-
flagged, from an Info-ZIP Unicode Path field when
|
|
25
|
-
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.
|
|
26
70
|
- `ZipArchive.read` — an entry's content, stored or deflated, inflated with
|
|
27
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).
|
|
76
|
+
- `createZip` — an archive of the entries given, in their order, each deflated
|
|
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.
|
|
85
|
+
- `ZipMethod` — the stored and deflate method numbers.
|
|
28
86
|
- `ZipFormatError`, `ZipLimitError` — a broken archive, and one past a limit.
|
|
29
87
|
|
|
30
88
|
Every limit is required, since an archive states its own sizes: the number of
|
|
31
|
-
entries, an entry's uncompressed size,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
not a safe path: check it
|
|
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.
|
|
35
111
|
|
|
36
112
|
Portable: no Node.js built-ins.
|
|
37
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,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpC,0EAA0E;IAC1E,IAAI,OAAO,GAA4B,IAAI,CAAC;IAC5C,MAAM,MAAM,GAAG,GAAqB,EAAE,C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* 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,M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