@ac-kit/format-zip 0.2.0 → 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 +66 -0
- package/README.md +77 -19
- 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 +33 -0
- package/dist/_zip-format.d.ts.map +1 -1
- package/dist/_zip-format.js +33 -0
- package/dist/_zip-format.js.map +1 -1
- 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 +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/zip-archive.d.ts +41 -1
- package/dist/zip-archive.d.ts.map +1 -1
- package/dist/zip-archive.js +14 -197
- package/dist/zip-archive.js.map +1 -1
- package/dist/zip-error.d.ts +3 -2
- package/dist/zip-error.d.ts.map +1 -1
- package/dist/zip-error.js +3 -2
- package/dist/zip-error.js.map +1 -1
- 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 +52 -21
- package/dist/zip-writer.d.ts.map +1 -1
- package/dist/zip-writer.js +18 -206
- package/dist/zip-writer.js.map +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { readStreamBytes, readStreamChunks, UnsupportedError, } from "@ac-kit/core";
|
|
2
|
+
import { crc_32 } from "@ac-kit/noncrypto-hash";
|
|
3
|
+
import { producerStream_ } from "./_producer-stream.js";
|
|
4
|
+
import { readLocalHeader_ } from "./_zip-directory.js";
|
|
5
|
+
import { LOCAL_HEADER_SIZE_ } from "./_zip-format.js";
|
|
6
|
+
import { ZipFormatError, ZipLimitError } from "./zip-error.js";
|
|
7
|
+
import { ZipMethod } from "./zip-method.js";
|
|
8
|
+
/**
|
|
9
|
+
* Copies `chunk` into an `ArrayBuffer` of its own when it is backed by another
|
|
10
|
+
* kind of buffer, so callers get the type Web APIs take.
|
|
11
|
+
*/
|
|
12
|
+
export function ownBuffer_(chunk) {
|
|
13
|
+
return chunk.buffer instanceof ArrayBuffer
|
|
14
|
+
? chunk
|
|
15
|
+
: new Uint8Array(chunk);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The {@link ZipArchive} over `entries`, whose content is read from `ranges`.
|
|
19
|
+
* The data offset of each entry, read from its local header, is cached, so a
|
|
20
|
+
* ranged source pays that read once per entry; memory stays O(entries).
|
|
21
|
+
*
|
|
22
|
+
* Each entry's local header and data must lie before the next entry's local
|
|
23
|
+
* header, or before the central directory at `directoryOffset` for the last: an
|
|
24
|
+
* entry overlapping another (two names over the same data, a bomb's usual
|
|
25
|
+
* trick) or the directory is refused when read.
|
|
26
|
+
*/
|
|
27
|
+
export function createArchive_(entries, comment, ranges, limits, directoryOffset) {
|
|
28
|
+
const byName = new Map(entries.map((entry) => [entry.name, entry]));
|
|
29
|
+
const ends = entryEnds_(entries, directoryOffset);
|
|
30
|
+
const endOf = (entry) => ends.get(entry.offset) ?? directoryOffset;
|
|
31
|
+
// Resolved offsets only: concurrent first reads each fetch the header, so
|
|
32
|
+
// one caller's abort never fails another's read.
|
|
33
|
+
const dataOffsets = new Map();
|
|
34
|
+
const dataOffset = async (entry, signal) => {
|
|
35
|
+
const end = endOf(entry);
|
|
36
|
+
if (entry.offset + LOCAL_HEADER_SIZE_ > end) {
|
|
37
|
+
throw new ZipFormatError(`The local header of "${entry.name}" overlaps another entry or the central directory`, entry.offset);
|
|
38
|
+
}
|
|
39
|
+
let cached = dataOffsets.get(entry.offset);
|
|
40
|
+
if (cached === undefined) {
|
|
41
|
+
const header = await ranges.read(entry.offset, LOCAL_HEADER_SIZE_, signal);
|
|
42
|
+
cached = readLocalHeader_(header, entry.offset);
|
|
43
|
+
dataOffsets.set(entry.offset, cached);
|
|
44
|
+
}
|
|
45
|
+
if (cached + entry.compressedSize > end) {
|
|
46
|
+
throw new ZipFormatError(`The data of "${entry.name}" overlaps another entry or the central directory`, cached);
|
|
47
|
+
}
|
|
48
|
+
return cached;
|
|
49
|
+
};
|
|
50
|
+
const stream = (entry, signal) => {
|
|
51
|
+
checkReadable_(entry);
|
|
52
|
+
checkRatio_(entry, limits);
|
|
53
|
+
return producerStream_((combined) => inflateEntry_(entry, ranges, dataOffset, combined), signal);
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
entries,
|
|
57
|
+
comment,
|
|
58
|
+
entry: (name) => byName.get(name),
|
|
59
|
+
read: async (entry, signal) => {
|
|
60
|
+
checkReadable_(entry);
|
|
61
|
+
if (entry.size > limits.maxEntrySize) {
|
|
62
|
+
throw new ZipLimitError(`ZIP entry "${entry.name}" holds ${entry.size} bytes, more than ${limits.maxEntrySize}`);
|
|
63
|
+
}
|
|
64
|
+
return readStreamBytes(stream(entry, signal), entry.size, signal);
|
|
65
|
+
},
|
|
66
|
+
stream,
|
|
67
|
+
streamRange: (entry, start, length, signal) => {
|
|
68
|
+
checkReadable_(entry);
|
|
69
|
+
if (entry.method !== ZipMethod.STORED) {
|
|
70
|
+
throw new UnsupportedError(`A range of ZIP entry "${entry.name}", which is not stored`);
|
|
71
|
+
}
|
|
72
|
+
checkStoredSizes_(entry);
|
|
73
|
+
if (!Number.isSafeInteger(start) ||
|
|
74
|
+
!Number.isSafeInteger(length) ||
|
|
75
|
+
start < 0 ||
|
|
76
|
+
length < 0 ||
|
|
77
|
+
start + length > entry.size) {
|
|
78
|
+
throw new RangeError(`Range ${start}+${length} outside ZIP entry "${entry.name}" of ${entry.size} bytes`);
|
|
79
|
+
}
|
|
80
|
+
return producerStream_(async function* (combined) {
|
|
81
|
+
const offset = await dataOffset(entry, combined);
|
|
82
|
+
for await (const chunk of readStreamChunks(ranges.stream(offset + start, length, combined), combined)) {
|
|
83
|
+
yield chunk;
|
|
84
|
+
}
|
|
85
|
+
combined.throwIfAborted();
|
|
86
|
+
}, signal);
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Where each local header's room ends, by its offset: the next local header, or
|
|
92
|
+
* the directory for the last one. Offsets two entries share end where they
|
|
93
|
+
* start, so neither is read. O(n log n) in the entries.
|
|
94
|
+
*/
|
|
95
|
+
function entryEnds_(entries, directoryOffset) {
|
|
96
|
+
const offsets = entries
|
|
97
|
+
.map((entry) => entry.offset)
|
|
98
|
+
.sort((left, right) => left - right);
|
|
99
|
+
const ends = new Map();
|
|
100
|
+
for (let index = 0; index < offsets.length; index++) {
|
|
101
|
+
const offset = offsets[index];
|
|
102
|
+
const next = offsets[index + 1];
|
|
103
|
+
if (next === offset || offsets[index - 1] === offset) {
|
|
104
|
+
ends.set(offset, offset);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
ends.set(offset, Math.min(next ?? directoryOffset, directoryOffset));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return ends;
|
|
111
|
+
}
|
|
112
|
+
async function* inflateEntry_(entry, ranges, dataOffset, signal) {
|
|
113
|
+
const start = await dataOffset(entry, signal);
|
|
114
|
+
const isStored = entry.method === ZipMethod.STORED;
|
|
115
|
+
if (isStored) {
|
|
116
|
+
checkStoredSizes_(entry);
|
|
117
|
+
}
|
|
118
|
+
const raw = ranges.stream(start, entry.compressedSize, signal);
|
|
119
|
+
const content = isStored
|
|
120
|
+
? raw
|
|
121
|
+
: raw.pipeThrough(new DecompressionStream("deflate-raw"), { signal });
|
|
122
|
+
let size = 0;
|
|
123
|
+
let crc32 = 0;
|
|
124
|
+
try {
|
|
125
|
+
for await (const chunk of readStreamChunks(content, signal)) {
|
|
126
|
+
size += chunk.length;
|
|
127
|
+
if (size > entry.size) {
|
|
128
|
+
throw new ZipFormatError(`Entry "${entry.name}" inflates past its ${entry.size} bytes`, start);
|
|
129
|
+
}
|
|
130
|
+
crc32 = crc_32(chunk, { continueFrom: crc32 });
|
|
131
|
+
yield ownBuffer_(chunk);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
signal.throwIfAborted();
|
|
136
|
+
// DecompressionStream reports corrupt data as a TypeError.
|
|
137
|
+
if (error instanceof TypeError && !ranges.isSourceError(error)) {
|
|
138
|
+
throw new ZipFormatError(`Corrupt deflate data in "${entry.name}"`, start);
|
|
139
|
+
}
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
await content.cancel(signal.reason).catch(() => { });
|
|
144
|
+
}
|
|
145
|
+
signal.throwIfAborted();
|
|
146
|
+
if (size !== entry.size || crc32 !== entry.crc32) {
|
|
147
|
+
throw new ZipFormatError(`Entry "${entry.name}" does not match its size and CRC-32`, start);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function checkReadable_(entry) {
|
|
151
|
+
if (entry.isEncrypted) {
|
|
152
|
+
throw new UnsupportedError(`ZIP entry "${entry.name}" is encrypted`);
|
|
153
|
+
}
|
|
154
|
+
if (entry.method !== ZipMethod.STORED && entry.method !== ZipMethod.DEFLATE) {
|
|
155
|
+
throw new UnsupportedError(`ZIP compression method ${entry.method} of "${entry.name}"`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function checkRatio_(entry, limits) {
|
|
159
|
+
if (entry.size >
|
|
160
|
+
Math.max(entry.compressedSize, 1) * limits.maxCompressionRatio) {
|
|
161
|
+
throw new ZipLimitError(`ZIP entry "${entry.name}" is compressed past ${limits.maxCompressionRatio}:1`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function checkStoredSizes_(entry) {
|
|
165
|
+
if (entry.compressedSize !== entry.size) {
|
|
166
|
+
throw new ZipFormatError(`Stored entry "${entry.name}" with two sizes`, entry.offset);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** The ranges of an archive held in memory. */
|
|
170
|
+
export function bytesRanges_(bytes) {
|
|
171
|
+
const slice = (offset, length) => {
|
|
172
|
+
if (offset + length > bytes.length) {
|
|
173
|
+
throw new ZipFormatError("Truncated archive", offset);
|
|
174
|
+
}
|
|
175
|
+
return bytes.subarray(offset, offset + length);
|
|
176
|
+
};
|
|
177
|
+
return {
|
|
178
|
+
size: bytes.length,
|
|
179
|
+
read: async (offset, length) => slice(offset, length),
|
|
180
|
+
stream: (offset, length) => {
|
|
181
|
+
const chunk = slice(offset, length);
|
|
182
|
+
return new ReadableStream({
|
|
183
|
+
start(controller) {
|
|
184
|
+
controller.enqueue(chunk);
|
|
185
|
+
controller.close();
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
isSourceError: () => false,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=_zip-entries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_zip-entries.js","sourceRoot":"","sources":["../src/_zip-entries.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EACf,gBAAgB,EAChB,gBAAgB,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OA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C;AAC/C,MAAM,UAAU,YAAY,CAAC,KAA8B;IAC1D,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,MAAc,EAA2B,EAAE;QACzE,IAAI,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;YACpC,MAAM,IAAI,cAAc,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAChD,CAAC,CAAC;IAEF,OAAO;QACN,IAAI,EAAE,KAAK,CAAC,MAAM;QAClB,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC;QACrD,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;YAC1B,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YACpC,OAAO,IAAI,cAAc,CAAC;gBACzB,KAAK,CAAC,UAAU;oBACf,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;oBAC1B,UAAU,CAAC,KAAK,EAAE,CAAC;gBACpB,CAAC;aACD,CAAC,CAAC;QACJ,CAAC;QACD,aAAa,EAAE,GAAG,EAAE,CAAC,KAAK;KAC1B,CAAC;AACH,CAAC"}
|
package/dist/_zip-format.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** §4.3.7 local file header signature. */
|
|
2
2
|
export declare const LOCAL_HEADER_ = 67324752;
|
|
3
|
+
/** §4.3.9 data descriptor signature, which APPNOTE recommends writing. */
|
|
4
|
+
export declare const DATA_DESCRIPTOR_ = 134695760;
|
|
3
5
|
/** §4.3.12 central directory file header signature. */
|
|
4
6
|
export declare const CENTRAL_HEADER_ = 33639248;
|
|
5
7
|
/** §4.3.16 end of central directory record signature. */
|
|
@@ -8,8 +10,39 @@ export declare const END_OF_CENTRAL_DIRECTORY_ = 101010256;
|
|
|
8
10
|
export declare const ZIP64_END_LOCATOR_ = 117853008;
|
|
9
11
|
/** §4.3.14 ZIP64 end of central directory record signature. */
|
|
10
12
|
export declare const ZIP64_END_OF_CENTRAL_DIRECTORY_ = 101075792;
|
|
13
|
+
/** §4.3.7 size of a local header before its name and extra field. */
|
|
14
|
+
export declare const LOCAL_HEADER_SIZE_ = 30;
|
|
15
|
+
/** §4.3.12 size of a central header before its name, extra field and comment. */
|
|
16
|
+
export declare const CENTRAL_HEADER_SIZE_ = 46;
|
|
17
|
+
/** §4.3.16 size of the end of central directory record before its comment. */
|
|
18
|
+
export declare const END_OF_CENTRAL_DIRECTORY_SIZE_ = 22;
|
|
19
|
+
/** §4.3.15 size of the ZIP64 end of central directory locator. */
|
|
20
|
+
export declare const ZIP64_END_LOCATOR_SIZE_ = 20;
|
|
21
|
+
/** §4.3.14 size of a ZIP64 end of central directory record, version 1. */
|
|
22
|
+
export declare const ZIP64_END_OF_CENTRAL_DIRECTORY_SIZE_ = 56;
|
|
23
|
+
/** §4.3.16 longest archive comment. */
|
|
24
|
+
export declare const MAX_COMMENT_ = 65535;
|
|
11
25
|
/** §4.4.4 general purpose bit 0: the entry is encrypted. */
|
|
12
26
|
export declare const ENCRYPTED_FLAG_ = 1;
|
|
27
|
+
/** §4.4.4 general purpose bit 3: CRC-32 and sizes follow the data. */
|
|
28
|
+
export declare const DATA_DESCRIPTOR_FLAG_ = 8;
|
|
13
29
|
/** §4.4.4 general purpose bit 11: the name and comment are UTF-8. */
|
|
14
30
|
export declare const UTF8_FLAG_ = 2048;
|
|
31
|
+
/** §4.5.3 ZIP64 extended information extra field. */
|
|
32
|
+
export declare const ZIP64_EXTRA_ = 1;
|
|
33
|
+
/** §4.6.9 Info-ZIP Unicode Path extra field. */
|
|
34
|
+
export declare const UNICODE_PATH_EXTRA_ = 28789;
|
|
35
|
+
/** §4.4.3 version needed to extract a stored entry. */
|
|
36
|
+
export declare const VERSION_STORED_ = 10;
|
|
37
|
+
/** §4.4.3 version needed for a deflated entry or a directory. */
|
|
38
|
+
export declare const VERSION_DEFLATE_OR_DIRECTORY_ = 20;
|
|
39
|
+
/** §4.4.3 version needed for ZIP64 structures. */
|
|
40
|
+
export declare const VERSION_ZIP64_ = 45;
|
|
41
|
+
/**
|
|
42
|
+
* §4.4.8, §4.4.9, §4.4.16: a 32-bit size or offset holding this value is in the
|
|
43
|
+
* ZIP64 extra field instead, so it and anything larger need ZIP64.
|
|
44
|
+
*/
|
|
45
|
+
export declare const SATURATED_UINT32_ = 4294967295;
|
|
46
|
+
/** §4.4.21, §4.4.22: an entry count holding this value is in the ZIP64 record. */
|
|
47
|
+
export declare const SATURATED_UINT16_ = 65535;
|
|
15
48
|
//# sourceMappingURL=_zip-format.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_zip-format.d.ts","sourceRoot":"","sources":["../src/_zip-format.ts"],"names":[],"mappings":"AAEA,0CAA0C;AAC1C,eAAO,MAAM,aAAa,WAAa,CAAC;AACxC,uDAAuD;AACvD,eAAO,MAAM,eAAe,WAAa,CAAC;AAC1C,yDAAyD;AACzD,eAAO,MAAM,yBAAyB,YAAa,CAAC;AACpD,gEAAgE;AAChE,eAAO,MAAM,kBAAkB,YAAa,CAAC;AAC7C,+DAA+D;AAC/D,eAAO,MAAM,+BAA+B,YAAa,CAAC;AAE1D,4DAA4D;AAC5D,eAAO,MAAM,eAAe,IAAS,CAAC;AACtC,qEAAqE;AACrE,eAAO,MAAM,UAAU,OAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"_zip-format.d.ts","sourceRoot":"","sources":["../src/_zip-format.ts"],"names":[],"mappings":"AAEA,0CAA0C;AAC1C,eAAO,MAAM,aAAa,WAAa,CAAC;AACxC,0EAA0E;AAC1E,eAAO,MAAM,gBAAgB,YAAa,CAAC;AAC3C,uDAAuD;AACvD,eAAO,MAAM,eAAe,WAAa,CAAC;AAC1C,yDAAyD;AACzD,eAAO,MAAM,yBAAyB,YAAa,CAAC;AACpD,gEAAgE;AAChE,eAAO,MAAM,kBAAkB,YAAa,CAAC;AAC7C,+DAA+D;AAC/D,eAAO,MAAM,+BAA+B,YAAa,CAAC;AAE1D,qEAAqE;AACrE,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,iFAAiF;AACjF,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,8EAA8E;AAC9E,eAAO,MAAM,8BAA8B,KAAK,CAAC;AACjD,kEAAkE;AAClE,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,0EAA0E;AAC1E,eAAO,MAAM,oCAAoC,KAAK,CAAC;AACvD,uCAAuC;AACvC,eAAO,MAAM,YAAY,QAAS,CAAC;AAEnC,4DAA4D;AAC5D,eAAO,MAAM,eAAe,IAAS,CAAC;AACtC,sEAAsE;AACtE,eAAO,MAAM,qBAAqB,IAAS,CAAC;AAC5C,qEAAqE;AACrE,eAAO,MAAM,UAAU,OAAS,CAAC;AAEjC,qDAAqD;AACrD,eAAO,MAAM,YAAY,IAAS,CAAC;AACnC,gDAAgD;AAChD,eAAO,MAAM,mBAAmB,QAAS,CAAC;AAE1C,uDAAuD;AACvD,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,iEAAiE;AACjE,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAChD,kDAAkD;AAClD,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAC5C,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,QAAS,CAAC"}
|
package/dist/_zip-format.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// The APPNOTE 6.3 constants the reader and the writer share.
|
|
2
2
|
/** §4.3.7 local file header signature. */
|
|
3
3
|
export const LOCAL_HEADER_ = 0x04034b50;
|
|
4
|
+
/** §4.3.9 data descriptor signature, which APPNOTE recommends writing. */
|
|
5
|
+
export const DATA_DESCRIPTOR_ = 0x08074b50;
|
|
4
6
|
/** §4.3.12 central directory file header signature. */
|
|
5
7
|
export const CENTRAL_HEADER_ = 0x02014b50;
|
|
6
8
|
/** §4.3.16 end of central directory record signature. */
|
|
@@ -9,8 +11,39 @@ export const END_OF_CENTRAL_DIRECTORY_ = 0x06054b50;
|
|
|
9
11
|
export const ZIP64_END_LOCATOR_ = 0x07064b50;
|
|
10
12
|
/** §4.3.14 ZIP64 end of central directory record signature. */
|
|
11
13
|
export const ZIP64_END_OF_CENTRAL_DIRECTORY_ = 0x06064b50;
|
|
14
|
+
/** §4.3.7 size of a local header before its name and extra field. */
|
|
15
|
+
export const LOCAL_HEADER_SIZE_ = 30;
|
|
16
|
+
/** §4.3.12 size of a central header before its name, extra field and comment. */
|
|
17
|
+
export const CENTRAL_HEADER_SIZE_ = 46;
|
|
18
|
+
/** §4.3.16 size of the end of central directory record before its comment. */
|
|
19
|
+
export const END_OF_CENTRAL_DIRECTORY_SIZE_ = 22;
|
|
20
|
+
/** §4.3.15 size of the ZIP64 end of central directory locator. */
|
|
21
|
+
export const ZIP64_END_LOCATOR_SIZE_ = 20;
|
|
22
|
+
/** §4.3.14 size of a ZIP64 end of central directory record, version 1. */
|
|
23
|
+
export const ZIP64_END_OF_CENTRAL_DIRECTORY_SIZE_ = 56;
|
|
24
|
+
/** §4.3.16 longest archive comment. */
|
|
25
|
+
export const MAX_COMMENT_ = 0xffff;
|
|
12
26
|
/** §4.4.4 general purpose bit 0: the entry is encrypted. */
|
|
13
27
|
export const ENCRYPTED_FLAG_ = 0x0001;
|
|
28
|
+
/** §4.4.4 general purpose bit 3: CRC-32 and sizes follow the data. */
|
|
29
|
+
export const DATA_DESCRIPTOR_FLAG_ = 0x0008;
|
|
14
30
|
/** §4.4.4 general purpose bit 11: the name and comment are UTF-8. */
|
|
15
31
|
export const UTF8_FLAG_ = 0x0800;
|
|
32
|
+
/** §4.5.3 ZIP64 extended information extra field. */
|
|
33
|
+
export const ZIP64_EXTRA_ = 0x0001;
|
|
34
|
+
/** §4.6.9 Info-ZIP Unicode Path extra field. */
|
|
35
|
+
export const UNICODE_PATH_EXTRA_ = 0x7075;
|
|
36
|
+
/** §4.4.3 version needed to extract a stored entry. */
|
|
37
|
+
export const VERSION_STORED_ = 10;
|
|
38
|
+
/** §4.4.3 version needed for a deflated entry or a directory. */
|
|
39
|
+
export const VERSION_DEFLATE_OR_DIRECTORY_ = 20;
|
|
40
|
+
/** §4.4.3 version needed for ZIP64 structures. */
|
|
41
|
+
export const VERSION_ZIP64_ = 45;
|
|
42
|
+
/**
|
|
43
|
+
* §4.4.8, §4.4.9, §4.4.16: a 32-bit size or offset holding this value is in the
|
|
44
|
+
* ZIP64 extra field instead, so it and anything larger need ZIP64.
|
|
45
|
+
*/
|
|
46
|
+
export const SATURATED_UINT32_ = 0xffffffff;
|
|
47
|
+
/** §4.4.21, §4.4.22: an entry count holding this value is in the ZIP64 record. */
|
|
48
|
+
export const SATURATED_UINT16_ = 0xffff;
|
|
16
49
|
//# sourceMappingURL=_zip-format.js.map
|
package/dist/_zip-format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_zip-format.js","sourceRoot":"","sources":["../src/_zip-format.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAE7D,0CAA0C;AAC1C,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC;AACxC,uDAAuD;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC;AAC1C,yDAAyD;AACzD,MAAM,CAAC,MAAM,yBAAyB,GAAG,UAAU,CAAC;AACpD,gEAAgE;AAChE,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;AAC7C,+DAA+D;AAC/D,MAAM,CAAC,MAAM,+BAA+B,GAAG,UAAU,CAAC;AAE1D,4DAA4D;AAC5D,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AACtC,qEAAqE;AACrE,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAA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,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAClC,iEAAiE;AACjE,MAAM,CAAC,MAAM,6BAA6B,GAAG,EAAE,CAAC;AAChD,kDAAkD;AAClD,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AAEjC;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAC5C,kFAAkF;AAClF,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** The fields a local and a central header share. */
|
|
2
|
+
export type HeaderFields_ = {
|
|
3
|
+
readonly version: number;
|
|
4
|
+
readonly flags: number;
|
|
5
|
+
readonly method: number;
|
|
6
|
+
readonly time: number;
|
|
7
|
+
readonly date: number;
|
|
8
|
+
readonly crc32: number;
|
|
9
|
+
readonly compressedSize: number;
|
|
10
|
+
readonly size: number;
|
|
11
|
+
readonly nameBytes: Uint8Array;
|
|
12
|
+
};
|
|
13
|
+
/** Whether a 32-bit header field cannot hold `value`. */
|
|
14
|
+
export declare function needsZip64_(value: number): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* APPNOTE 6.3 §4.3.7: the local header, its name and, when `zip64`, a ZIP64
|
|
17
|
+
* extra field holding both sizes (§4.5.3 requires both in a local header) with
|
|
18
|
+
* the 32-bit fields saturated.
|
|
19
|
+
*/
|
|
20
|
+
export declare function writeLocalHeader_(fields: HeaderFields_, zip64: boolean): Uint8Array<ArrayBuffer>;
|
|
21
|
+
/**
|
|
22
|
+
* APPNOTE 6.3 §4.3.9: the data descriptor after an entry written with bit 3,
|
|
23
|
+
* with 8-byte sizes when its local header carried a ZIP64 extra field.
|
|
24
|
+
*/
|
|
25
|
+
export declare function writeDataDescriptor_(crc32: number, compressedSize: number, size: number, zip64: boolean): Uint8Array<ArrayBuffer>;
|
|
26
|
+
/**
|
|
27
|
+
* APPNOTE 6.3 §4.3.12: the central header, its name, a ZIP64 extra field
|
|
28
|
+
* holding each value its 32-bit field cannot (size, compressed size, offset, in
|
|
29
|
+
* that order, §4.5.3), and its comment.
|
|
30
|
+
*
|
|
31
|
+
* When `zip64Sizes`, set for an entry whose local header has a ZIP64 field,
|
|
32
|
+
* both sizes go in the ZIP64 field whatever their value. Readers that skip the
|
|
33
|
+
* local header when the central one has no extra field (wabac.js computes the
|
|
34
|
+
* data offset as `30 + name length` then) would otherwise miss the local
|
|
35
|
+
* field.
|
|
36
|
+
*/
|
|
37
|
+
export declare function writeCentralHeader_(fields: HeaderFields_ & {
|
|
38
|
+
readonly commentBytes: Uint8Array;
|
|
39
|
+
readonly externalAttributes: number;
|
|
40
|
+
readonly offset: number;
|
|
41
|
+
readonly zip64Sizes: boolean;
|
|
42
|
+
}): Uint8Array<ArrayBuffer>;
|
|
43
|
+
/**
|
|
44
|
+
* APPNOTE 6.3 §4.3.14-16: the end of central directory record, preceded by the
|
|
45
|
+
* ZIP64 record and locator when the entry count, the directory's size or its
|
|
46
|
+
* offset does not fit the classic record, whose fields are saturated then.
|
|
47
|
+
*/
|
|
48
|
+
export declare function writeEndRecords_(count: number, directorySize: number, directoryOffset: number, commentBytes: Uint8Array): Uint8Array<ArrayBuffer>;
|
|
49
|
+
//# sourceMappingURL=_zip-headers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_zip-headers.d.ts","sourceRoot":"","sources":["../src/_zip-headers.ts"],"names":[],"mappings":"AAqBA,qDAAqD;AACrD,MAAM,MAAM,aAAa,GAAG;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;CAC/B,CAAC;AAEF,yDAAyD;AACzD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,OAAO,GACZ,UAAU,CAAC,WAAW,CAAC,CA0BzB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,MAAM,EACb,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,GACZ,UAAU,CAAC,WAAW,CAAC,CAczB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,aAAa,GAAG;IACvB,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;IAClC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC7B,GACC,UAAU,CAAC,WAAW,CAAC,CAyDzB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,EACrB,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,UAAU,GACtB,UAAU,CAAC,WAAW,CAAC,CA+CzB"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { concatBytes } from "@ac-kit/core";
|
|
2
|
+
import { CENTRAL_HEADER_, CENTRAL_HEADER_SIZE_, DATA_DESCRIPTOR_, END_OF_CENTRAL_DIRECTORY_, END_OF_CENTRAL_DIRECTORY_SIZE_, LOCAL_HEADER_, LOCAL_HEADER_SIZE_, SATURATED_UINT16_, SATURATED_UINT32_, VERSION_DEFLATE_OR_DIRECTORY_, VERSION_ZIP64_, ZIP64_END_LOCATOR_, ZIP64_END_LOCATOR_SIZE_, ZIP64_END_OF_CENTRAL_DIRECTORY_, ZIP64_END_OF_CENTRAL_DIRECTORY_SIZE_, ZIP64_EXTRA_, } from "./_zip-format.js";
|
|
3
|
+
/** Whether a 32-bit header field cannot hold `value`. */
|
|
4
|
+
export function needsZip64_(value) {
|
|
5
|
+
return value >= SATURATED_UINT32_;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* APPNOTE 6.3 §4.3.7: the local header, its name and, when `zip64`, a ZIP64
|
|
9
|
+
* extra field holding both sizes (§4.5.3 requires both in a local header) with
|
|
10
|
+
* the 32-bit fields saturated.
|
|
11
|
+
*/
|
|
12
|
+
export function writeLocalHeader_(fields, zip64) {
|
|
13
|
+
const extraLength = zip64 ? 20 : 0;
|
|
14
|
+
const nameLength = fields.nameBytes.length;
|
|
15
|
+
const header = new Uint8Array(LOCAL_HEADER_SIZE_ + nameLength + extraLength);
|
|
16
|
+
const view = new DataView(header.buffer);
|
|
17
|
+
view.setUint32(0, LOCAL_HEADER_, true);
|
|
18
|
+
view.setUint16(4, fields.version, true);
|
|
19
|
+
view.setUint16(6, fields.flags, true);
|
|
20
|
+
view.setUint16(8, fields.method, true);
|
|
21
|
+
view.setUint16(10, fields.time, true);
|
|
22
|
+
view.setUint16(12, fields.date, true);
|
|
23
|
+
view.setUint32(14, fields.crc32, true);
|
|
24
|
+
view.setUint32(18, zip64 ? SATURATED_UINT32_ : fields.compressedSize, true);
|
|
25
|
+
view.setUint32(22, zip64 ? SATURATED_UINT32_ : fields.size, true);
|
|
26
|
+
view.setUint16(26, nameLength, true);
|
|
27
|
+
view.setUint16(28, extraLength, true);
|
|
28
|
+
header.set(fields.nameBytes, LOCAL_HEADER_SIZE_);
|
|
29
|
+
if (zip64) {
|
|
30
|
+
const extra = LOCAL_HEADER_SIZE_ + nameLength;
|
|
31
|
+
view.setUint16(extra, ZIP64_EXTRA_, true);
|
|
32
|
+
view.setUint16(extra + 2, 16, true);
|
|
33
|
+
view.setBigUint64(extra + 4, BigInt(fields.size), true);
|
|
34
|
+
view.setBigUint64(extra + 12, BigInt(fields.compressedSize), true);
|
|
35
|
+
}
|
|
36
|
+
return header;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* APPNOTE 6.3 §4.3.9: the data descriptor after an entry written with bit 3,
|
|
40
|
+
* with 8-byte sizes when its local header carried a ZIP64 extra field.
|
|
41
|
+
*/
|
|
42
|
+
export function writeDataDescriptor_(crc32, compressedSize, size, zip64) {
|
|
43
|
+
const descriptor = new Uint8Array(zip64 ? 24 : 16);
|
|
44
|
+
const view = new DataView(descriptor.buffer);
|
|
45
|
+
view.setUint32(0, DATA_DESCRIPTOR_, true);
|
|
46
|
+
view.setUint32(4, crc32, true);
|
|
47
|
+
if (zip64) {
|
|
48
|
+
view.setBigUint64(8, BigInt(compressedSize), true);
|
|
49
|
+
view.setBigUint64(16, BigInt(size), true);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
view.setUint32(8, compressedSize, true);
|
|
53
|
+
view.setUint32(12, size, true);
|
|
54
|
+
}
|
|
55
|
+
return descriptor;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* APPNOTE 6.3 §4.3.12: the central header, its name, a ZIP64 extra field
|
|
59
|
+
* holding each value its 32-bit field cannot (size, compressed size, offset, in
|
|
60
|
+
* that order, §4.5.3), and its comment.
|
|
61
|
+
*
|
|
62
|
+
* When `zip64Sizes`, set for an entry whose local header has a ZIP64 field,
|
|
63
|
+
* both sizes go in the ZIP64 field whatever their value. Readers that skip the
|
|
64
|
+
* local header when the central one has no extra field (wabac.js computes the
|
|
65
|
+
* data offset as `30 + name length` then) would otherwise miss the local
|
|
66
|
+
* field.
|
|
67
|
+
*/
|
|
68
|
+
export function writeCentralHeader_(fields) {
|
|
69
|
+
const wide = (value) => fields.zip64Sizes || needsZip64_(value);
|
|
70
|
+
const values = [
|
|
71
|
+
{ value: fields.size, isWide: wide(fields.size) },
|
|
72
|
+
{ value: fields.compressedSize, isWide: wide(fields.compressedSize) },
|
|
73
|
+
{ value: fields.offset, isWide: needsZip64_(fields.offset) },
|
|
74
|
+
];
|
|
75
|
+
const extended = values
|
|
76
|
+
.filter((field) => field.isWide)
|
|
77
|
+
.map((field) => field.value);
|
|
78
|
+
const extraLength = extended.length === 0 ? 0 : 4 + 8 * extended.length;
|
|
79
|
+
const nameLength = fields.nameBytes.length;
|
|
80
|
+
const commentLength = fields.commentBytes.length;
|
|
81
|
+
const header = new Uint8Array(CENTRAL_HEADER_SIZE_ + nameLength + extraLength + commentLength);
|
|
82
|
+
const view = new DataView(header.buffer);
|
|
83
|
+
view.setUint32(0, CENTRAL_HEADER_, true);
|
|
84
|
+
// Version made by: MS-DOS attributes, the APPNOTE version the entry needs.
|
|
85
|
+
// An entry whose central header alone needs ZIP64 (an offset past 4 GiB)
|
|
86
|
+
// still needs a reader that knows it.
|
|
87
|
+
const version = extended.length > 0
|
|
88
|
+
? Math.max(VERSION_ZIP64_, fields.version)
|
|
89
|
+
: fields.version;
|
|
90
|
+
view.setUint16(4, Math.max(VERSION_DEFLATE_OR_DIRECTORY_, version), true);
|
|
91
|
+
view.setUint16(6, version, true);
|
|
92
|
+
view.setUint16(8, fields.flags, true);
|
|
93
|
+
view.setUint16(10, fields.method, true);
|
|
94
|
+
view.setUint16(12, fields.time, true);
|
|
95
|
+
view.setUint16(14, fields.date, true);
|
|
96
|
+
view.setUint32(16, fields.crc32, true);
|
|
97
|
+
const [size, compressedSize, offset] = values.map((field) => field.isWide ? SATURATED_UINT32_ : field.value);
|
|
98
|
+
view.setUint32(20, compressedSize, true);
|
|
99
|
+
view.setUint32(24, size, true);
|
|
100
|
+
view.setUint16(28, nameLength, true);
|
|
101
|
+
view.setUint16(30, extraLength, true);
|
|
102
|
+
view.setUint16(32, commentLength, true);
|
|
103
|
+
view.setUint32(38, fields.externalAttributes, true);
|
|
104
|
+
view.setUint32(42, offset, true);
|
|
105
|
+
header.set(fields.nameBytes, CENTRAL_HEADER_SIZE_);
|
|
106
|
+
let cursor = CENTRAL_HEADER_SIZE_ + nameLength;
|
|
107
|
+
if (extraLength > 0) {
|
|
108
|
+
view.setUint16(cursor, ZIP64_EXTRA_, true);
|
|
109
|
+
view.setUint16(cursor + 2, extraLength - 4, true);
|
|
110
|
+
cursor += 4;
|
|
111
|
+
for (const value of extended) {
|
|
112
|
+
view.setBigUint64(cursor, BigInt(value), true);
|
|
113
|
+
cursor += 8;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
header.set(fields.commentBytes, cursor);
|
|
117
|
+
return header;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* APPNOTE 6.3 §4.3.14-16: the end of central directory record, preceded by the
|
|
121
|
+
* ZIP64 record and locator when the entry count, the directory's size or its
|
|
122
|
+
* offset does not fit the classic record, whose fields are saturated then.
|
|
123
|
+
*/
|
|
124
|
+
export function writeEndRecords_(count, directorySize, directoryOffset, commentBytes) {
|
|
125
|
+
const end = new Uint8Array(END_OF_CENTRAL_DIRECTORY_SIZE_ + commentBytes.length);
|
|
126
|
+
const view = new DataView(end.buffer);
|
|
127
|
+
const zip64 = count >= SATURATED_UINT16_ ||
|
|
128
|
+
needsZip64_(directorySize) ||
|
|
129
|
+
needsZip64_(directoryOffset);
|
|
130
|
+
const classicCount = Math.min(count, SATURATED_UINT16_);
|
|
131
|
+
view.setUint32(0, END_OF_CENTRAL_DIRECTORY_, true);
|
|
132
|
+
view.setUint16(8, classicCount, true);
|
|
133
|
+
view.setUint16(10, classicCount, true);
|
|
134
|
+
view.setUint32(12, Math.min(directorySize, SATURATED_UINT32_), true);
|
|
135
|
+
view.setUint32(16, Math.min(directoryOffset, SATURATED_UINT32_), true);
|
|
136
|
+
view.setUint16(20, commentBytes.length, true);
|
|
137
|
+
end.set(commentBytes, END_OF_CENTRAL_DIRECTORY_SIZE_);
|
|
138
|
+
if (!zip64) {
|
|
139
|
+
return end;
|
|
140
|
+
}
|
|
141
|
+
const records = new Uint8Array(ZIP64_END_OF_CENTRAL_DIRECTORY_SIZE_ + ZIP64_END_LOCATOR_SIZE_);
|
|
142
|
+
const recordView = new DataView(records.buffer);
|
|
143
|
+
recordView.setUint32(0, ZIP64_END_OF_CENTRAL_DIRECTORY_, true);
|
|
144
|
+
// The size of the record after this field.
|
|
145
|
+
recordView.setBigUint64(4, BigInt(ZIP64_END_OF_CENTRAL_DIRECTORY_SIZE_ - 12), true);
|
|
146
|
+
recordView.setUint16(12, VERSION_ZIP64_, true);
|
|
147
|
+
recordView.setUint16(14, VERSION_ZIP64_, true);
|
|
148
|
+
recordView.setBigUint64(24, BigInt(count), true);
|
|
149
|
+
recordView.setBigUint64(32, BigInt(count), true);
|
|
150
|
+
recordView.setBigUint64(40, BigInt(directorySize), true);
|
|
151
|
+
recordView.setBigUint64(48, BigInt(directoryOffset), true);
|
|
152
|
+
const locator = ZIP64_END_OF_CENTRAL_DIRECTORY_SIZE_;
|
|
153
|
+
recordView.setUint32(locator, ZIP64_END_LOCATOR_, true);
|
|
154
|
+
recordView.setBigUint64(locator + 8, BigInt(directoryOffset + directorySize), true);
|
|
155
|
+
recordView.setUint32(locator + 16, 1, true);
|
|
156
|
+
return concatBytes(records, end);
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=_zip-headers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_zip-headers.js","sourceRoot":"","sources":["../src/_zip-headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EACN,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,yBAAyB,EACzB,8BAA8B,EAC9B,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,6BAA6B,EAC7B,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,+BAA+B,EAC/B,oCAAoC,EACpC,YAAY,GACZ,MAA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AC;IAE5C,OAAO,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC"}
|
package/dist/zip-archive.d.ts
CHANGED
|
@@ -45,6 +45,8 @@ export type ZipArchive = {
|
|
|
45
45
|
entry(name: string): ZipEntry | undefined;
|
|
46
46
|
/**
|
|
47
47
|
* The uncompressed content of `entry`, checked against its size and CRC-32.
|
|
48
|
+
* Memory is the entry's size, bounded by `maxEntrySize`; reach for
|
|
49
|
+
* {@link ZipArchive.stream} past that.
|
|
48
50
|
*
|
|
49
51
|
* @throws {ZipLimitError} When it is larger than `maxEntrySize`, or
|
|
50
52
|
* compressed past `maxCompressionRatio`.
|
|
@@ -52,13 +54,51 @@ export type ZipArchive = {
|
|
|
52
54
|
* stored and deflate.
|
|
53
55
|
* @throws {ZipFormatError} When its local header, size or CRC-32 does not
|
|
54
56
|
* match the central directory.
|
|
57
|
+
* @throws When `signal` aborts, its reason; a source's own read error.
|
|
55
58
|
*/
|
|
56
59
|
read(entry: ZipEntry, signal?: AbortSignal): Promise<Uint8Array<ArrayBuffer>>;
|
|
60
|
+
/**
|
|
61
|
+
* The uncompressed content of `entry` as a stream, inflated as it is read:
|
|
62
|
+
* nothing is read before the first pull, and memory is one chunk plus the
|
|
63
|
+
* inflater's window, whatever the entry's size (`maxEntrySize` does not
|
|
64
|
+
* apply). Chunks may share memory with the bytes given to {@link openZip}.
|
|
65
|
+
*
|
|
66
|
+
* The size and CRC-32 are checked at the end: bytes delivered before it are
|
|
67
|
+
* unverified until the stream closes without an error.
|
|
68
|
+
*
|
|
69
|
+
* @throws {UnsupportedError} At once, when it is encrypted or uses a method
|
|
70
|
+
* other than stored and deflate.
|
|
71
|
+
* @throws {ZipLimitError} At once, when it is compressed past
|
|
72
|
+
* `maxCompressionRatio`.
|
|
73
|
+
* @throws The stream errors with {@link ZipFormatError} when the local header
|
|
74
|
+
* is broken, the data is corrupt, inflates past the size, or does not match
|
|
75
|
+
* the size and CRC-32; with `signal`'s reason when it aborts; and with a
|
|
76
|
+
* source's own read error.
|
|
77
|
+
*/
|
|
78
|
+
stream(entry: ZipEntry, signal?: AbortSignal): ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
79
|
+
/**
|
|
80
|
+
* `length` bytes of a stored entry from byte `start` of its content, read
|
|
81
|
+
* from the source as they are pulled and never checked against the CRC-32,
|
|
82
|
+
* since a part of an entry cannot be. This is how one record of a stored WARC
|
|
83
|
+
* inside a WACZ is read. Memory is one chunk.
|
|
84
|
+
*
|
|
85
|
+
* @throws {UnsupportedError} At once, when the entry is encrypted or not
|
|
86
|
+
* stored.
|
|
87
|
+
* @throws {RangeError} At once, when the range is not a pair of safe
|
|
88
|
+
* non-negative integers within the entry.
|
|
89
|
+
* @throws {ZipFormatError} At once, when a stored entry states two sizes; the
|
|
90
|
+
* stream errors with it when the local header is broken.
|
|
91
|
+
* @throws The stream errors with `signal`'s reason when it aborts, and with a
|
|
92
|
+
* source's own read error.
|
|
93
|
+
*/
|
|
94
|
+
streamRange(entry: ZipEntry, start: number, length: number, signal?: AbortSignal): ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
57
95
|
};
|
|
58
96
|
/**
|
|
59
97
|
* Reads a ZIP archive's central directory (APPNOTE 6.3), ZIP64 included, and
|
|
60
98
|
* returns its entries; their content is read on demand by
|
|
61
|
-
* {@link ZipArchive.read}, inflated with
|
|
99
|
+
* {@link ZipArchive.read} or {@link ZipArchive.stream}, inflated with
|
|
100
|
+
* `DecompressionStream`. {@link openZipSource} reads an archive by ranges
|
|
101
|
+
* instead, from a `Blob` or a ranged source.
|
|
62
102
|
*
|
|
63
103
|
* Names are decoded as UTF-8 when flagged so, from an Info-ZIP Unicode Path
|
|
64
104
|
* field when present, and as code page 437 otherwise. Archives split across
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zip-archive.d.ts","sourceRoot":"","sources":["../src/zip-archive.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zip-archive.d.ts","sourceRoot":"","sources":["../src/zip-archive.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACvB,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,4EAA4E;IAC5E,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;CACrC,CAAC;AAEF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