zip-writer 1.1.2 → 2.1.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/README.md +154 -132
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +32 -59
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +139 -148
- package/dist/index.js.map +1 -1
- package/dist/readable-from-bytes.d.ts +8 -0
- package/dist/readable-from-bytes.d.ts.map +1 -0
- package/dist/readable-from-bytes.js +25 -0
- package/dist/readable-from-bytes.js.map +1 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +49 -0
- package/dist/utils.js.map +1 -1
- package/dist/write-central-directory.d.ts +7 -3
- package/dist/write-central-directory.d.ts.map +1 -1
- package/dist/write-central-directory.js +97 -131
- package/dist/write-central-directory.js.map +1 -1
- package/dist/write-entry.d.ts +4 -23
- package/dist/write-entry.d.ts.map +1 -1
- package/dist/write-entry.js +13 -114
- package/dist/write-entry.js.map +1 -1
- package/package.json +31 -6
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getCDFH,
|
|
3
|
-
import {
|
|
4
|
-
import { noop } from "./utils.js";
|
|
1
|
+
import { getDataDescriptor, getLocalFileHeader } from "./write-entry.js";
|
|
2
|
+
import { getCDFH, getEOCD } from "./write-central-directory.js";
|
|
3
|
+
import { entryNeedsZip64, eocdNeedsZip64, getPublicEntryInfo, noop, validateEntryOptions, } from "./utils.js";
|
|
5
4
|
import { crc32 as crc32Default } from "#crc32";
|
|
5
|
+
import Mutex from "p-mutex";
|
|
6
6
|
const BUFFER_SIZE = 16 * 1024; // 16 KB
|
|
7
7
|
const bufferedQueue = new ByteLengthQueuingStrategy({
|
|
8
8
|
highWaterMark: BUFFER_SIZE,
|
|
9
9
|
});
|
|
10
|
+
const textEncoder = new TextEncoder();
|
|
10
11
|
export class ZipWriter {
|
|
11
12
|
#offset = BigInt(0);
|
|
12
13
|
#zipStream = new TransformStream({
|
|
@@ -21,10 +22,9 @@ export class ZipWriter {
|
|
|
21
22
|
// block the zip writing.
|
|
22
23
|
bufferedQueue);
|
|
23
24
|
#entries = [];
|
|
24
|
-
#queued = Promise.resolve();
|
|
25
|
-
#entryCount = 0;
|
|
26
|
-
#finalized = false;
|
|
27
25
|
#crc32;
|
|
26
|
+
#mutex = new Mutex();
|
|
27
|
+
#finalized = false;
|
|
28
28
|
/**
|
|
29
29
|
* @param crc Optional CRC32 function to use. Defaults to zlib.crc32 on Node and a pure JS implementation in browsers.
|
|
30
30
|
*/
|
|
@@ -34,44 +34,11 @@ export class ZipWriter {
|
|
|
34
34
|
get readable() {
|
|
35
35
|
return this.#zipStream.readable;
|
|
36
36
|
}
|
|
37
|
-
get entries() {
|
|
38
|
-
return this.#entries;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Wait until all currently queued entries have been written.
|
|
42
|
-
*/
|
|
43
|
-
async onceQueueEmpty() {
|
|
44
|
-
while (this.#entries.length < this.#entryCount) {
|
|
45
|
-
await this.#queued;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
37
|
/**
|
|
49
|
-
*
|
|
50
|
-
* Use `createEntryStream` for more efficient streaming writes. Calls to
|
|
51
|
-
* createEntry() will be queued internally and each will resolve once it's
|
|
52
|
-
* written to the archive.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```ts
|
|
56
|
-
* const data = new TextEncoder().encode("Hello, World!");
|
|
57
|
-
* const entryInfo = await zipWriter.createEntry(data, { name: "hello.txt" });
|
|
58
|
-
* console.log(entryInfo);
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* @param data Entry data
|
|
62
|
-
* @param options Entry filename, comment, compression method, etc.
|
|
63
|
-
* @returns Entry information once the entry has been written.
|
|
38
|
+
* Get an array of entry information for all entries added so far to the ZIP archive.
|
|
64
39
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const writer = entryWriter.writable.getWriter();
|
|
68
|
-
try {
|
|
69
|
-
await writer.write(data);
|
|
70
|
-
}
|
|
71
|
-
finally {
|
|
72
|
-
await writer.close();
|
|
73
|
-
}
|
|
74
|
-
return entryWriter.getEntryInfo();
|
|
40
|
+
entries() {
|
|
41
|
+
return this.#mutex.withLock(() => this.#entries.map((entry) => getPublicEntryInfo(entry)));
|
|
75
42
|
}
|
|
76
43
|
/**
|
|
77
44
|
* Create a new entry in the Zip archive. Use the returned
|
|
@@ -99,56 +66,104 @@ export class ZipWriter {
|
|
|
99
66
|
*
|
|
100
67
|
* @param options Entry options
|
|
101
68
|
*/
|
|
102
|
-
|
|
69
|
+
addEntry({ readable, ...entryOptions }) {
|
|
103
70
|
if (this.#finalized) {
|
|
104
71
|
throw new TypeError("Cannot add entry after finalize() has been called");
|
|
105
72
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// Wait for previous entry to complete
|
|
121
|
-
await prevQueued;
|
|
122
|
-
const writer = this.#zipStream.writable.getWriter();
|
|
123
|
-
const reader = readable.getReader();
|
|
73
|
+
// Encode now to catch range errors synchronously
|
|
74
|
+
const entryOptionsInternal = {
|
|
75
|
+
...entryOptions,
|
|
76
|
+
nameBytes: textEncoder.encode(entryOptions.name),
|
|
77
|
+
commentBytes: entryOptions.comment
|
|
78
|
+
? textEncoder.encode(entryOptions.comment)
|
|
79
|
+
: new Uint8Array(),
|
|
80
|
+
};
|
|
81
|
+
validateEntryOptions(entryOptionsInternal);
|
|
82
|
+
const entryInfoPromise = this.#mutex.withLock(async () => {
|
|
83
|
+
// -- Write local file header --
|
|
84
|
+
let writer = this.#zipStream.writable.getWriter();
|
|
85
|
+
await writer.ready;
|
|
86
|
+
const startOffset = this.#offset;
|
|
124
87
|
try {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
startOffset: this.#offset,
|
|
131
|
-
});
|
|
132
|
-
this.#entries.push(entryInfo);
|
|
133
|
-
entryDone();
|
|
134
|
-
return entryInfo;
|
|
88
|
+
// This is in a try...catch because if writing the local file header
|
|
89
|
+
// fails, we want to abort the output zip readable stream.
|
|
90
|
+
await writer.write(getLocalFileHeader(entryOptionsInternal));
|
|
91
|
+
// Await all data has been written before we releaseLock and read the offset
|
|
92
|
+
await writer.ready;
|
|
135
93
|
}
|
|
136
94
|
catch (err) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
95
|
+
// Let the readable size know we are no longer consuming data
|
|
96
|
+
/* istanbul ignore next -- @preserve */
|
|
97
|
+
readable.cancel(err);
|
|
98
|
+
// Put the zip stream writable into an error state, which will propogate
|
|
99
|
+
// to the readable side and anything consuming it
|
|
100
|
+
/* istanbul ignore next -- @preserve */
|
|
101
|
+
await writer.abort(err);
|
|
102
|
+
/* istanbul ignore next -- @preserve */
|
|
103
|
+
writer.releaseLock();
|
|
104
|
+
/* istanbul ignore next -- @preserve */
|
|
145
105
|
throw err;
|
|
146
106
|
}
|
|
147
|
-
|
|
148
|
-
|
|
107
|
+
writer.releaseLock();
|
|
108
|
+
const fileStartOffset = this.#offset;
|
|
109
|
+
// -- Write file data --
|
|
110
|
+
let uncompressedSize = BigInt(0);
|
|
111
|
+
let checksum = 0;
|
|
112
|
+
const crcAndSizeStream = new TransformStream({
|
|
113
|
+
transform: async (chunk, controller) => {
|
|
114
|
+
const byteLength = BigInt(chunk.byteLength);
|
|
115
|
+
uncompressedSize += byteLength;
|
|
116
|
+
checksum = this.#crc32(chunk, checksum);
|
|
117
|
+
controller.enqueue(chunk);
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
const compressionStream = entryOptions.store
|
|
121
|
+
? new TransformStream()
|
|
122
|
+
: new CompressionStream("deflate-raw");
|
|
123
|
+
await readable
|
|
124
|
+
.pipeThrough(crcAndSizeStream)
|
|
125
|
+
.pipeThrough(compressionStream)
|
|
126
|
+
.pipeTo(this.#zipStream.writable, { preventClose: true });
|
|
127
|
+
// -- Write data descriptor --
|
|
128
|
+
writer = this.#zipStream.writable.getWriter();
|
|
129
|
+
// Await here to ensure all data has been written, so we know this.#offset is accurate
|
|
130
|
+
await writer.ready;
|
|
131
|
+
const compressedSize = this.#offset - fileStartOffset;
|
|
132
|
+
const needsZip64 = entryNeedsZip64({
|
|
133
|
+
uncompressedSize,
|
|
134
|
+
compressedSize,
|
|
135
|
+
startOffset,
|
|
136
|
+
});
|
|
137
|
+
const entryInfo = {
|
|
138
|
+
...entryOptionsInternal,
|
|
139
|
+
startOffset,
|
|
140
|
+
crc32: checksum,
|
|
141
|
+
uncompressedSize,
|
|
142
|
+
compressedSize,
|
|
143
|
+
zip64: needsZip64,
|
|
144
|
+
};
|
|
145
|
+
try {
|
|
146
|
+
// This is in a try...catch because writing the data descriptor could fail,
|
|
147
|
+
// and we want to abort the output zip readable stream if that happens.
|
|
148
|
+
await writer.write(getDataDescriptor(entryInfo));
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
/* istanbul ignore next -- @preserve */
|
|
152
|
+
await writer.abort(err);
|
|
153
|
+
/* istanbul ignore next -- @preserve */
|
|
149
154
|
writer.releaseLock();
|
|
155
|
+
// The readable has already been fully consumed at this point, so no need to cancel it
|
|
156
|
+
/* istanbul ignore next -- @preserve */
|
|
157
|
+
throw err;
|
|
150
158
|
}
|
|
159
|
+
writer.releaseLock();
|
|
160
|
+
this.#entries.push(entryInfo);
|
|
161
|
+
return getPublicEntryInfo(entryInfo);
|
|
151
162
|
});
|
|
163
|
+
// Avoid an uncaught rejection if the user doesn't await entryInfoPromise
|
|
164
|
+
// - error handling can be done on the readable stream
|
|
165
|
+
entryInfoPromise.catch(noop);
|
|
166
|
+
return entryInfoPromise;
|
|
152
167
|
}
|
|
153
168
|
/**
|
|
154
169
|
* Set the entries of the Zip archive. This can be used to reorder,
|
|
@@ -159,7 +174,7 @@ export class ZipWriter {
|
|
|
159
174
|
#setEntries(entries) {
|
|
160
175
|
const currentEntriesByOffset = new Map();
|
|
161
176
|
for (const entry of this.#entries) {
|
|
162
|
-
currentEntriesByOffset.set(
|
|
177
|
+
currentEntriesByOffset.set(entry.startOffset, entry);
|
|
163
178
|
}
|
|
164
179
|
// Entries can't have their offset, crc32, compressed size, or uncompressed
|
|
165
180
|
// size changed, but they can be removed, reordered, or have the name and
|
|
@@ -172,14 +187,24 @@ export class ZipWriter {
|
|
|
172
187
|
if (existingEntry.crc32 !== entry.crc32) {
|
|
173
188
|
throw new Error(`Cannot set entries: entry at offset ${entry.startOffset} has different CRC32`);
|
|
174
189
|
}
|
|
175
|
-
if (existingEntry.uncompressedSize !== entry.uncompressedSize) {
|
|
190
|
+
if (existingEntry.uncompressedSize !== BigInt(entry.uncompressedSize)) {
|
|
176
191
|
throw new Error(`Cannot set entries: entry at offset ${entry.startOffset} has different uncompressed size`);
|
|
177
192
|
}
|
|
178
|
-
if (existingEntry.compressedSize !== entry.compressedSize) {
|
|
193
|
+
if (existingEntry.compressedSize !== BigInt(entry.compressedSize)) {
|
|
179
194
|
throw new Error(`Cannot set entries: entry at offset ${entry.startOffset} has different compressed size`);
|
|
180
195
|
}
|
|
181
196
|
}
|
|
182
|
-
|
|
197
|
+
// TODO: edge-case a user could pass an entry with an invalid zip64 flag
|
|
198
|
+
this.#entries = entries.map((entry) => ({
|
|
199
|
+
...entry,
|
|
200
|
+
uncompressedSize: BigInt(entry.uncompressedSize),
|
|
201
|
+
compressedSize: BigInt(entry.compressedSize),
|
|
202
|
+
startOffset: BigInt(entry.startOffset),
|
|
203
|
+
nameBytes: textEncoder.encode(entry.name),
|
|
204
|
+
commentBytes: entry.comment
|
|
205
|
+
? textEncoder.encode(entry.comment)
|
|
206
|
+
: new Uint8Array(0),
|
|
207
|
+
}));
|
|
183
208
|
}
|
|
184
209
|
/**
|
|
185
210
|
* Finalize the ZIP archive by writing the central directory and end of
|
|
@@ -196,23 +221,27 @@ export class ZipWriter {
|
|
|
196
221
|
*
|
|
197
222
|
* @returns Information about the finalized archive.
|
|
198
223
|
*/
|
|
199
|
-
|
|
224
|
+
finalize({ entries } = {}) {
|
|
200
225
|
if (this.#finalized) {
|
|
201
226
|
throw new TypeError("finalize() has already been called");
|
|
202
227
|
}
|
|
203
228
|
this.#finalized = true;
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
229
|
+
const zipInfoPromise = this.#mutex.withLock(async () => {
|
|
230
|
+
if (entries) {
|
|
231
|
+
try {
|
|
232
|
+
this.#setEntries(entries);
|
|
233
|
+
}
|
|
234
|
+
catch (err) {
|
|
235
|
+
// If setting entries fails, we still want to finalize the zip stream
|
|
236
|
+
// so that consumers don't hang waiting for data that will never come.
|
|
237
|
+
this.#zipStream.writable.abort(err);
|
|
238
|
+
throw err;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
213
241
|
// Write central directory headers for all entries
|
|
214
|
-
const centralDirectoryStart = this.#offset;
|
|
215
242
|
const writer = this.#zipStream.writable.getWriter();
|
|
243
|
+
await writer.ready;
|
|
244
|
+
const centralDirectoryStart = this.#offset;
|
|
216
245
|
try {
|
|
217
246
|
let entryUsesZip64 = false;
|
|
218
247
|
let uncompressedEntriesSize = BigInt(0);
|
|
@@ -223,25 +252,21 @@ export class ZipWriter {
|
|
|
223
252
|
}
|
|
224
253
|
uncompressedEntriesSize += BigInt(entry.uncompressedSize);
|
|
225
254
|
compressedEntriesSize += BigInt(entry.compressedSize);
|
|
255
|
+
await writer.ready;
|
|
226
256
|
await writer.write(getCDFH(entry));
|
|
227
257
|
}
|
|
258
|
+
await writer.ready;
|
|
228
259
|
const centralDirectorySize = this.#offset - centralDirectoryStart;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
eocd = getEOCDZip64(BigInt(this.#entries.length), centralDirectoryStart, centralDirectorySize);
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
eocd = getEOCDStandard(this.#entries.length, Number(centralDirectoryStart), Number(centralDirectorySize));
|
|
239
|
-
}
|
|
260
|
+
const eocdOptions = {
|
|
261
|
+
centralDirectoryStart,
|
|
262
|
+
centralDirectorySize,
|
|
263
|
+
entriesCount: this.#entries.length,
|
|
264
|
+
};
|
|
265
|
+
const eocd = getEOCD(eocdOptions);
|
|
240
266
|
await writer.write(eocd);
|
|
241
|
-
// Close the zip stream
|
|
242
267
|
await writer.close();
|
|
243
268
|
return {
|
|
244
|
-
zip64: eocdNeedsZip64 || entryUsesZip64,
|
|
269
|
+
zip64: eocdNeedsZip64(eocdOptions) || entryUsesZip64,
|
|
245
270
|
uncompressedEntriesSize,
|
|
246
271
|
compressedEntriesSize,
|
|
247
272
|
fileSize: this.#offset,
|
|
@@ -254,45 +279,11 @@ export class ZipWriter {
|
|
|
254
279
|
finally {
|
|
255
280
|
writer.releaseLock();
|
|
256
281
|
}
|
|
257
|
-
})();
|
|
258
|
-
finalizePromise.catch(noop); // prevent unhandled rejection
|
|
259
|
-
return finalizePromise;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
class EntryWriter {
|
|
263
|
-
#entryStream = new TransformStream(undefined, bufferedQueue, bufferedQueue);
|
|
264
|
-
#written;
|
|
265
|
-
/**
|
|
266
|
-
* @param enqueueAndPipe Function that enqueues the entry data readable, pipes it to the Zip stream, and returns a promise that resolves to the entry info once done.
|
|
267
|
-
*/
|
|
268
|
-
constructor(enqueueAndPipe) {
|
|
269
|
-
// We could try to pass the zipstream writable to EntryWriter, but then
|
|
270
|
-
// EntryWriter would not know when the entry has finished writing, and would
|
|
271
|
-
// not have a way to get the entry info.
|
|
272
|
-
this.#written = enqueueAndPipe(this.#entryStream.readable);
|
|
273
|
-
// abort the writable quickly if there is an error, and ensure we don't
|
|
274
|
-
// throw an uncaught error.
|
|
275
|
-
this.#written.catch((reason) => {
|
|
276
|
-
this.#entryStream.writable.abort(reason);
|
|
277
282
|
});
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
* @example
|
|
283
|
-
* ```ts
|
|
284
|
-
* ReadableStream.from([new TextEncoder().encode("Hello, World!")])
|
|
285
|
-
* .pipeTo(entryWriter.writable);
|
|
286
|
-
* ```
|
|
287
|
-
*/
|
|
288
|
-
get writable() {
|
|
289
|
-
return this.#entryStream.writable;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Get entry info. Resolves once all data has been written to the Zip stream.
|
|
293
|
-
*/
|
|
294
|
-
async getEntryInfo() {
|
|
295
|
-
return this.#written;
|
|
283
|
+
// Avoid an uncaught rejection if the user doesn't await finalize() - error
|
|
284
|
+
// handling can be done on the readable stream
|
|
285
|
+
zipInfoPromise.catch(noop);
|
|
286
|
+
return zipInfoPromise;
|
|
296
287
|
}
|
|
297
288
|
}
|
|
298
289
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EACL,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB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KAAK,CAAC;oBACnB,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;gBACrC,CAAC;gBAED,MAAM,MAAM,CAAC,KAAK,CAAC;gBACnB,MAAM,oBAAoB,GAAG,IAAI,CAAC,OAAO,GAAG,qBAAqB,CAAC;gBAClE,MAAM,WAAW,GAAG;oBAClB,qBAAqB;oBACrB,oBAAoB;oBACpB,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;iBACnC,CAAC;gBACF,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;gBAElC,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACzB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;gBAErB,OAAO;oBACL,KAAK,EAAE,cAAc,CAAC,WAAW,CAAC,IAAI,cAAc;oBACpD,uBAAuB;oBACvB,qBAAqB;oBACrB,QAAQ,EAAE,IAAI,CAAC,OAAO;iBACvB,CAAC;YACJ,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACxB,MAAM,GAAG,CAAC;YACZ,CAAC;oBAAS,CAAC;gBACT,MAAM,CAAC,WAAW,EAAE,CAAC;YACvB,CAAC;QACH,CAAC,CAAC,CAAC;QACH,2EAA2E;QAC3E,8CAA8C;QAC9C,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,cAAc,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper for creating a ReadableStream from a Uint8Array
|
|
3
|
+
* with proper backpressure handling.
|
|
4
|
+
*
|
|
5
|
+
* @param data The input Uint8Array
|
|
6
|
+
*/
|
|
7
|
+
export declare function readableFromBytes(data: Uint8Array<ArrayBuffer>): ReadableStream<ArrayBufferView<ArrayBufferLike>>;
|
|
8
|
+
//# sourceMappingURL=readable-from-bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readable-from-bytes.d.ts","sourceRoot":"","sources":["../src/readable-from-bytes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,oDAsB9D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper for creating a ReadableStream from a Uint8Array
|
|
3
|
+
* with proper backpressure handling.
|
|
4
|
+
*
|
|
5
|
+
* @param data The input Uint8Array
|
|
6
|
+
*/
|
|
7
|
+
export function readableFromBytes(data) {
|
|
8
|
+
let offset = 0;
|
|
9
|
+
return new ReadableStream({
|
|
10
|
+
pull(controller) {
|
|
11
|
+
if (offset >= data.byteLength) {
|
|
12
|
+
controller.close();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const chunkSize = Math.min(
|
|
16
|
+
// desiredSize can't be null here - it's only null after close()
|
|
17
|
+
// It could be <=0 under some circumstances, so ensure at least 1 byte is read
|
|
18
|
+
Math.max(controller.desiredSize, 1), data.byteLength - offset);
|
|
19
|
+
const chunk = data.subarray(offset, offset + chunkSize);
|
|
20
|
+
controller.enqueue(chunk);
|
|
21
|
+
offset += chunkSize;
|
|
22
|
+
},
|
|
23
|
+
}, new ByteLengthQueuingStrategy({ highWaterMark: 16 * 1024 }));
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=readable-from-bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readable-from-bytes.js","sourceRoot":"","sources":["../src/readable-from-bytes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAA6B;IAC7D,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,OAAO,IAAI,cAAc,CACvB;QACE,IAAI,CAAC,UAAU;YACb,IAAI,MAAM,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBAC9B,UAAU,CAAC,KAAK,EAAE,CAAC;gBACnB,OAAO;YACT,CAAC;YACD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG;YACxB,gEAAgE;YAChE,8EAA8E;YAC9E,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,WAAY,EAAE,CAAC,CAAC,EACpC,IAAI,CAAC,UAAU,GAAG,MAAM,CACzB,CAAC;YACF,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;YACxD,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC1B,MAAM,IAAI,SAAS,CAAC;QACtB,CAAC;KACF,EACD,IAAI,yBAAyB,CAAC,EAAE,aAAa,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,CAC5D,CAAC;AACJ,CAAC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
import type { EntryInfo, EntryInfoInternal } from "./index.js";
|
|
1
2
|
export declare function getDosTime(date: Date): number;
|
|
2
3
|
export declare function getDosDate(date: Date): number;
|
|
3
4
|
export declare function noop(): void;
|
|
5
|
+
/**
|
|
6
|
+
* Validates EntryOptions to ensure they are within the limits of our encoding.
|
|
7
|
+
* Throws an error if any field exceeds the maximum allowed size.
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateEntryOptions({ nameBytes, commentBytes, mode, }: {
|
|
10
|
+
nameBytes: Uint8Array;
|
|
11
|
+
commentBytes: Uint8Array;
|
|
12
|
+
mode?: number;
|
|
13
|
+
}): void;
|
|
4
14
|
type DataViewValue<T extends keyof typeof OFFSETS = keyof typeof OFFSETS> = T extends "setBigUint64" ? [T, bigint, boolean] : [T, number, boolean];
|
|
5
15
|
export declare const UINT16 = "setUint16";
|
|
6
16
|
export declare const UINT32 = "setUint32";
|
|
@@ -11,5 +21,12 @@ declare const OFFSETS: {
|
|
|
11
21
|
setBigUint64: number;
|
|
12
22
|
};
|
|
13
23
|
export declare function writeDataView(view: DataView, values: DataViewValue[], offset?: number): number;
|
|
24
|
+
export declare function entryNeedsZip64({ uncompressedSize, compressedSize, startOffset, }: Pick<EntryInfoInternal, "uncompressedSize" | "compressedSize" | "startOffset">): boolean;
|
|
25
|
+
export declare function eocdNeedsZip64(options: {
|
|
26
|
+
centralDirectoryStart: bigint;
|
|
27
|
+
centralDirectorySize: bigint;
|
|
28
|
+
entriesCount: number;
|
|
29
|
+
}): boolean;
|
|
30
|
+
export declare function getPublicEntryInfo(entryInfo: EntryInfoInternal): EntryInfo;
|
|
14
31
|
export {};
|
|
15
32
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AAEpB,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAM7C;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAM7C;AAED,wBAAgB,IAAI,SAAK;AAEzB;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,SAAS,EACT,YAAY,EACZ,IAAI,GACL,EAAE;IACD,SAAS,EAAE,UAAU,CAAC;IACtB,YAAY,EAAE,UAAU,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,IAAI,CAuBP;AAED,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,OAAO,OAAO,GAAG,MAAM,OAAO,OAAO,IACtE,CAAC,SAAS,cAAc,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAEzE,eAAO,MAAM,MAAM,cAAc,CAAC;AAClC,eAAO,MAAM,MAAM,cAAc,CAAC;AAClC,eAAO,MAAM,MAAM,iBAAiB,CAAC;AAGrC,QAAA,MAAM,OAAO;;;;CAImB,CAAC;AAEjC,wBAAgB,aAAa,CAC3B,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,aAAa,EAAE,EACvB,MAAM,GAAE,MAAU,GACjB,MAAM,CAOR;AAED,wBAAgB,eAAe,CAAC,EAC9B,gBAAgB,EAChB,cAAc,EACd,WAAW,GACZ,EAAE,IAAI,CACL,iBAAiB,EACjB,kBAAkB,GAAG,gBAAgB,GAAG,aAAa,CACtD,GAAG,OAAO,CAMV;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE;IACtC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAMV;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,iBAAiB,GAAG,SAAS,CAgB1E"}
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ZIP64_LIMIT } from "./constants.js";
|
|
1
2
|
export function getDosTime(date) {
|
|
2
3
|
return ((date.getHours() << 11) |
|
|
3
4
|
(date.getMinutes() << 5) |
|
|
@@ -9,6 +10,26 @@ export function getDosDate(date) {
|
|
|
9
10
|
date.getDate());
|
|
10
11
|
}
|
|
11
12
|
export function noop() { }
|
|
13
|
+
/**
|
|
14
|
+
* Validates EntryOptions to ensure they are within the limits of our encoding.
|
|
15
|
+
* Throws an error if any field exceeds the maximum allowed size.
|
|
16
|
+
*/
|
|
17
|
+
export function validateEntryOptions({ nameBytes, commentBytes, mode, }) {
|
|
18
|
+
// Validate name
|
|
19
|
+
if (nameBytes.length > 0xffff) {
|
|
20
|
+
throw new RangeError(`File name exceeds maximum length of 65535 bytes (got ${nameBytes.length} bytes)`);
|
|
21
|
+
}
|
|
22
|
+
// Validate comment
|
|
23
|
+
if (commentBytes.length > 0xffff) {
|
|
24
|
+
throw new RangeError(`File comment exceeds maximum length of 65535 bytes (got ${commentBytes.length} bytes)`);
|
|
25
|
+
}
|
|
26
|
+
// Validate mode (Unix file mode is 16 bits, stored in upper 16 bits of external attributes)
|
|
27
|
+
if (mode !== undefined) {
|
|
28
|
+
if (!Number.isInteger(mode) || mode < 0 || mode > 0xffff) {
|
|
29
|
+
throw new RangeError(`File mode must be an integer between 0 and 65535 (got ${mode})`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
12
33
|
export const UINT16 = "setUint16";
|
|
13
34
|
export const UINT32 = "setUint32";
|
|
14
35
|
export const UINT64 = "setBigUint64";
|
|
@@ -25,4 +46,32 @@ export function writeDataView(view, values, offset = 0) {
|
|
|
25
46
|
}
|
|
26
47
|
return offset;
|
|
27
48
|
}
|
|
49
|
+
export function entryNeedsZip64({ uncompressedSize, compressedSize, startOffset, }) {
|
|
50
|
+
return (uncompressedSize >= ZIP64_LIMIT ||
|
|
51
|
+
compressedSize >= ZIP64_LIMIT ||
|
|
52
|
+
startOffset >= ZIP64_LIMIT);
|
|
53
|
+
}
|
|
54
|
+
export function eocdNeedsZip64(options) {
|
|
55
|
+
return (options.centralDirectoryStart >= ZIP64_LIMIT ||
|
|
56
|
+
options.centralDirectorySize >= ZIP64_LIMIT ||
|
|
57
|
+
options.entriesCount >= 0xffff);
|
|
58
|
+
}
|
|
59
|
+
export function getPublicEntryInfo(entryInfo) {
|
|
60
|
+
const { nameBytes, commentBytes, ...rest } = entryInfo;
|
|
61
|
+
if (rest.zip64) {
|
|
62
|
+
return {
|
|
63
|
+
...rest,
|
|
64
|
+
zip64: true,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return {
|
|
69
|
+
...rest,
|
|
70
|
+
zip64: false,
|
|
71
|
+
uncompressedSize: Number(rest.uncompressedSize),
|
|
72
|
+
compressedSize: Number(rest.compressedSize),
|
|
73
|
+
startOffset: Number(rest.startOffset),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
28
77
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU,CAAC,IAAU;IACnC,OAAO,CACL,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;QACvB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACxB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CACzB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAU;IACnC,OAAO,CACL,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,CAAC,OAAO,EAAE,CACf,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI,KAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAQ7C,MAAM,UAAU,UAAU,CAAC,IAAU;IACnC,OAAO,CACL,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;QACvB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACxB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CACzB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAU;IACnC,OAAO,CACL,CAAC,CAAC,IAAI,CAAC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generate the Central Directory File Header for the given entry info.
|
|
4
4
|
*/
|
|
5
|
-
export declare function getCDFH(entryInfo:
|
|
5
|
+
export declare function getCDFH(entryInfo: EntryInfoInternal): Uint8Array<ArrayBuffer>;
|
|
6
6
|
/**
|
|
7
7
|
* Generate the End of Central Directory record with zip64 support.
|
|
8
8
|
*/
|
|
@@ -10,5 +10,9 @@ export declare function getEOCDStandard(entriesCount: number, centralDirectoryOf
|
|
|
10
10
|
/**
|
|
11
11
|
* Generate the ZIP64 End of Central Directory record.
|
|
12
12
|
*/
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function getEOCD(options: {
|
|
14
|
+
entriesCount: number;
|
|
15
|
+
centralDirectoryStart: bigint;
|
|
16
|
+
centralDirectorySize: bigint;
|
|
17
|
+
}): Uint8Array<ArrayBuffer>;
|
|
14
18
|
//# sourceMappingURL=write-central-directory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-central-directory.d.ts","sourceRoot":"","sources":["../src/write-central-directory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"write-central-directory.d.ts","sourceRoot":"","sources":["../src/write-central-directory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AAiCpB;;GAEG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,iBAAiB,GAAG,UAAU,CAAC,WAAW,CAAC,CAoG7E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,MAAM,EACpB,sBAAsB,EAAE,MAAM,EAC9B,oBAAoB,EAAE,MAAM,GAC3B,UAAU,CAAC,WAAW,CAAC,CAwBzB;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oBAAoB,EAAE,MAAM,CAAC;CAC9B,GAAG,UAAU,CAAC,WAAW,CAAC,CAkF1B"}
|