@zip.js/zip.js 2.6.37 → 2.6.40

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/index.d.ts CHANGED
@@ -142,8 +142,7 @@ interface WorkerConfiguration {
142
142
  * @param registerDataHandler The function called to handle the `data` events triggered by a third-party codec implementation.
143
143
  * @returns An instance containing classes compatible with `ZipDeflate` and `ZipInflate`.
144
144
  */
145
- // deno-lint-ignore no-explicit-any
146
- export function initShimAsyncCodec(library: EventBasedZipLibrary, constructorOptions: any | null, registerDataHandler: registerDataHandler): ZipLibrary
145
+ export function initShimAsyncCodec(library: EventBasedZipLibrary, constructorOptions: unknown | null, registerDataHandler: registerDataHandler): ZipLibrary
147
146
 
148
147
  /**
149
148
  * Represents the callback function used to register the `data` event handler.
@@ -267,7 +266,7 @@ declare class CodecStream extends TransformStream { }
267
266
  export function getMimeType(fileExtension: string): string
268
267
 
269
268
  /**
270
- * Represents an instance used to read or write any type of data.
269
+ * Represents an instance used to read or write unknown type of data.
271
270
  *
272
271
  * zip.js can handle multiple types of data thanks to a generic API. This feature is based on 2 abstract constructors: `Reader` and `Writer`.
273
272
  * The classes inheriting from `Reader` help to read data from a source of data. The classes inheriting from `Writer` help to write data into a destination.
@@ -290,7 +289,7 @@ interface ReadableReader {
290
289
  }
291
290
 
292
291
  /**
293
- * Represents a `Reader` instance used to read any type of data.
292
+ * Represents a `Reader` instance used to read unknown type of data.
294
293
  *
295
294
  * @example
296
295
  * Here is an example of custom `Reader` class used to read binary strings:
@@ -369,8 +368,7 @@ export class Uint8ArrayReader extends Reader<Uint8Array> { }
369
368
  /**
370
369
  * Represents a `Reader` instance used to read data provided as an array of `Reader` instances (i.e. split zip files).
371
370
  */
372
- // deno-lint-ignore no-explicit-any
373
- export class SplitZipReader extends Reader<Reader<any>[] | ReadableReader[] | ReadableStream[]> { }
371
+ export class SplitZipReader extends Reader<Reader<unknown>[] | ReadableReader[] | ReadableStream[]> { }
374
372
 
375
373
  /**
376
374
  * Represents a URL stored into a `string`.
@@ -455,7 +453,7 @@ interface WritableWriter {
455
453
  }
456
454
 
457
455
  /**
458
- * Represents a `Writer` instance used to write any type of data.
456
+ * Represents a `Writer` instance used to write unknown type of data.
459
457
  *
460
458
  * @example
461
459
  * Here is an example of custom `Writer` class used to write binary strings:
@@ -574,7 +572,7 @@ export class SplitZipWriter implements Initializable, WritableWriter {
574
572
  * @param writerGenerator The MIME type of the content.
575
573
  * @param maxSize The maximum size of the data written into `Writer` instances (default: 4GB).
576
574
  */
577
- constructor(writerGenerator: AsyncGenerator<Writer<any> | WritableWriter | WritableStream, boolean>, maxSize?: number)
575
+ constructor(writerGenerator: AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream, boolean>, maxSize?: number)
578
576
  }
579
577
 
580
578
  /**
@@ -621,8 +619,7 @@ export class ZipReader<Type> {
621
619
  * @param reader The `Reader` instance used to read data.
622
620
  * @param options The options.
623
621
  */
624
- // deno-lint-ignore no-explicit-any
625
- constructor(reader: Reader<Type> | ReadableReader | ReadableStream | Reader<any>[] | ReadableReader[] | ReadableStream[], options?: ZipReaderConstructorOptions)
622
+ constructor(reader: Reader<Type> | ReadableReader | ReadableStream | Reader<unknown>[] | ReadableReader[] | ReadableStream[], options?: ZipReaderConstructorOptions)
626
623
  /**
627
624
  * The global comment of the zip file.
628
625
  */
@@ -878,7 +875,7 @@ export class ZipWriter<Type> {
878
875
  * @param writer The `Writer` instance where the zip content will be written.
879
876
  * @param options The options.
880
877
  */
881
- constructor(writer: Writer<Type> | WritableWriter | WritableStream | SplitZipWriter | AsyncGenerator<Writer<any> | WritableWriter | WritableStream, boolean>, options?: ZipWriterConstructorOptions)
878
+ constructor(writer: Writer<Type> | WritableWriter | WritableStream | SplitZipWriter | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream, boolean>, options?: ZipWriterConstructorOptions)
882
879
  /**
883
880
  * `true` if the zip contains at least one entry that has been partially written.
884
881
  */
@@ -891,7 +888,7 @@ export class ZipWriter<Type> {
891
888
  * @param options The options.
892
889
  * @returns A promise resolving to an `Entry` instance.
893
890
  */
894
- add<ReaderType>(filename: string, reader?: Reader<ReaderType> | ReadableReader | ReadableStream | null, options?: ZipWriterAddDataOptions): Promise<Entry>
891
+ add<ReaderType>(filename: string, reader?: Reader<ReaderType> | ReadableReader | ReadableStream, options?: ZipWriterAddDataOptions): Promise<Entry>
895
892
  /**
896
893
  * Writes the entries directory, writes the global comment, and returns the content of the zip file
897
894
  *
@@ -899,7 +896,7 @@ export class ZipWriter<Type> {
899
896
  * @param options The options.
900
897
  * @returns The content of the zip file.
901
898
  */
902
- close(comment?: Uint8Array | null, options?: ZipWriterCloseOptions): Promise<Type>
899
+ close(comment?: Uint8Array, options?: ZipWriterCloseOptions): Promise<Type>
903
900
  }
904
901
 
905
902
  /**
@@ -1158,7 +1155,7 @@ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
1158
1155
  * @param options The options.
1159
1156
  * @returns A promise resolving to a `string`.
1160
1157
  */
1161
- getText(encoding?: string | null, options?: EntryGetDataOptions): Promise<string>
1158
+ getText(encoding?: string, options?: EntryGetDataOptions): Promise<string>
1162
1159
  /**
1163
1160
  * Retrieves the content of the entry as a `Blob` instance
1164
1161
  *
@@ -1166,7 +1163,7 @@ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
1166
1163
  * @param options The options.
1167
1164
  * @returns A promise resolving to a `Blob` instance.
1168
1165
  */
1169
- getBlob(mimeType?: string | null, options?: EntryGetDataOptions): Promise<Blob>
1166
+ getBlob(mimeType?: string, options?: EntryGetDataOptions): Promise<Blob>
1170
1167
  /**
1171
1168
  * Retrieves the content of the entry as as a Data URI `string` encoded in Base64
1172
1169
  *
@@ -1174,7 +1171,7 @@ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
1174
1171
  * @param options The options.
1175
1172
  * @returns A promise resolving to a Data URI `string` encoded in Base64.
1176
1173
  */
1177
- getData64URI(mimeType?: string | null, options?: EntryGetDataOptions): Promise<string>
1174
+ getData64URI(mimeType?: string, options?: EntryGetDataOptions): Promise<string>
1178
1175
  /**
1179
1176
  * Retrieves the content of the entry as a `Uint8Array` instance
1180
1177
  *
@@ -1189,7 +1186,7 @@ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
1189
1186
  * @param options The options.
1190
1187
  * @returns A promise resolving to the `WritableStream` instance.
1191
1188
  */
1192
- getWritable(writable?: WritableStream | null, options?: EntryGetDataOptions): Promise<WritableStream>
1189
+ getWritable(writable?: WritableStream, options?: EntryGetDataOptions): Promise<WritableStream>
1193
1190
  /**
1194
1191
  * Retrieves the content of the entry via a `Writer` instance
1195
1192
  *
@@ -1344,34 +1341,34 @@ export class ZipDirectoryEntry extends ZipEntry {
1344
1341
  */
1345
1342
  importReadable(readable: ReadableStream, options?: ZipReaderConstructorOptions): Promise<void>
1346
1343
  /**
1347
- * Returns a `Blob` instance containing a zip file of the entry and its descendants, if any
1344
+ * Returns a `Blob` instance containing a zip file of the entry and its descendants, if unknown
1348
1345
  *
1349
1346
  * @param options The options.
1350
1347
  * @returns A promise resolving to the `Blob` instance.
1351
1348
  */
1352
1349
  exportBlob(options?: ZipDirectoryEntryExportOptions): Promise<Blob>
1353
1350
  /**
1354
- * Returns a Data URI `string` encoded in Base64 containing a zip file of the entry and its descendants, if any
1351
+ * Returns a Data URI `string` encoded in Base64 containing a zip file of the entry and its descendants, if unknown
1355
1352
  *
1356
1353
  * @param options The options.
1357
1354
  * @returns A promise resolving to the Data URI `string` encoded in Base64.
1358
1355
  */
1359
1356
  exportData64URI(options?: ZipDirectoryEntryExportOptions): Promise<string>
1360
1357
  /**
1361
- * Returns a `Uint8Array` instance containing a zip file of the entry and its descendants, if any
1358
+ * Returns a `Uint8Array` instance containing a zip file of the entry and its descendants, if unknown
1362
1359
  *
1363
1360
  * @param options The options.
1364
1361
  * @returns A promise resolving to the `Uint8Array` instance.
1365
1362
  */
1366
1363
  exportUint8Array(options?: ZipDirectoryEntryExportOptions): Promise<Uint8Array>
1367
1364
  /**
1368
- * Creates a zip file via a `WritableStream` instance containing the entry and its descendants, if any
1365
+ * Creates a zip file via a `WritableStream` instance containing the entry and its descendants, if unknown
1369
1366
  *
1370
1367
  * @param writable The `WritableStream` instance.
1371
1368
  * @param options The options.
1372
1369
  * @returns A promise resolving to the `Uint8Array` instance.
1373
1370
  */
1374
- exportWritable(writable?: WritableStream | null, options?: ZipDirectoryEntryExportOptions): Promise<WritableStream>
1371
+ exportWritable(writable?: WritableStream, options?: ZipDirectoryEntryExportOptions): Promise<WritableStream>
1375
1372
  }
1376
1373
 
1377
1374
  /**
@@ -54,26 +54,24 @@ let indexWorker = 0;
54
54
  async function runWorker(stream, workerOptions) {
55
55
  const { options, config } = workerOptions;
56
56
  const { transferStreams, useWebWorkers, useCompressionStream, codecType, compressed, signed, encrypted } = options;
57
- const { workerScripts } = config;
57
+ const { workerScripts, maxWorkers, terminateWorkerTimeout } = config;
58
58
  workerOptions.transferStreams = transferStreams || transferStreams === UNDEFINED_VALUE;
59
59
  const streamCopy = !compressed && !signed && !encrypted && !workerOptions.transferStreams;
60
60
  workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
61
61
  workerOptions.scripts = workerOptions.useWebWorkers && workerScripts ? workerScripts[codecType] : [];
62
62
  options.useCompressionStream = useCompressionStream || (useCompressionStream === UNDEFINED_VALUE && config.useCompressionStream);
63
63
  let worker;
64
- if (pool.length < config.maxWorkers) {
64
+ const workerData = pool.find(workerData => !workerData.busy);
65
+ if (workerData) {
66
+ clearTerminateTimeout(workerData);
67
+ worker = new CodecWorker(workerData, stream, workerOptions, onTaskFinished);
68
+ } else if (pool.length < maxWorkers) {
65
69
  const workerData = { indexWorker };
66
70
  indexWorker++;
67
71
  pool.push(workerData);
68
72
  worker = new CodecWorker(workerData, stream, workerOptions, onTaskFinished);
69
73
  } else {
70
- const workerData = pool.find(workerData => !workerData.busy);
71
- if (workerData) {
72
- clearTerminateTimeout(workerData);
73
- worker = new CodecWorker(workerData, stream, workerOptions, onTaskFinished);
74
- } else {
75
- worker = await new Promise(resolve => pendingRequests.push({ resolve, stream, workerOptions }));
76
- }
74
+ worker = await new Promise(resolve => pendingRequests.push({ resolve, stream, workerOptions }));
77
75
  }
78
76
  return worker.run();
79
77
 
@@ -82,7 +80,6 @@ async function runWorker(stream, workerOptions) {
82
80
  const [{ resolve, stream, workerOptions }] = pendingRequests.splice(0, 1);
83
81
  resolve(new CodecWorker(workerData, stream, workerOptions, onTaskFinished));
84
82
  } else if (workerData.worker) {
85
- const { terminateWorkerTimeout } = config;
86
83
  clearTerminateTimeout(workerData);
87
84
  if (Number.isFinite(terminateWorkerTimeout) && terminateWorkerTimeout >= 0) {
88
85
  workerData.terminateTimeout = setTimeout(() => {
@@ -51,13 +51,11 @@ export {
51
51
 
52
52
  class CodecWorker {
53
53
 
54
- constructor(workerData, stream, workerOptions, onTaskFinished) {
55
- const { readable, writable } = stream;
56
- const { options, config, streamOptions, useWebWorkers, transferStreams, scripts } = workerOptions;
54
+ constructor(workerData, { readable, writable }, { options, config, streamOptions, useWebWorkers, transferStreams, scripts }, onTaskFinished) {
57
55
  const { signal } = streamOptions;
58
56
  Object.assign(workerData, {
59
57
  busy: true,
60
- readable: readable.pipeThrough(new ReadableStreamHooks(readable, streamOptions, config), { signal }),
58
+ readable: readable.pipeThrough(new ProgressWatcherStream(readable, streamOptions, config), { signal }),
61
59
  writable,
62
60
  options: Object.assign({}, options),
63
61
  scripts,
@@ -78,7 +76,7 @@ class CodecWorker {
78
76
  }
79
77
  }
80
78
 
81
- class ReadableStreamHooks extends TransformStream {
79
+ class ProgressWatcherStream extends TransformStream {
82
80
 
83
81
  constructor(readableSource, { onstart, onprogress, size, onend }, { chunkSize }) {
84
82
  let chunkOffset = 0;
@@ -161,11 +159,11 @@ async function runWebWorker(workerData, config) {
161
159
  rejectResult,
162
160
  result
163
161
  });
164
- const { readable, options } = workerData;
165
- const { writable, closed } = detectClosedStream(workerData.writable);
162
+ const { readable, options, scripts } = workerData;
163
+ const { writable, closed } = watchClosedStream(workerData.writable);
166
164
  const streamsTransferred = sendMessage({
167
165
  type: MESSAGE_START,
168
- scripts: workerData.scripts.slice(1),
166
+ scripts: scripts.slice(1),
169
167
  options,
170
168
  config,
171
169
  readable,
@@ -187,7 +185,7 @@ async function runWebWorker(workerData, config) {
187
185
  return resultValue;
188
186
  }
189
187
 
190
- function detectClosedStream(writableSource) {
188
+ function watchClosedStream(writableSource) {
191
189
  const writer = writableSource.getWriter();
192
190
  let resolveStreamClosed;
193
191
  const closed = new Promise(resolve => resolveStreamClosed = resolve);
@@ -201,7 +199,7 @@ function detectClosedStream(writableSource) {
201
199
  resolveStreamClosed();
202
200
  },
203
201
  abort(reason) {
204
- writer.abort(reason);
202
+ return writer.abort(reason);
205
203
  }
206
204
  });
207
205
  return { writable, closed };
@@ -213,6 +211,7 @@ let transferStreamsSupported = true;
213
211
  function getWebWorker(url, baseURL, workerData) {
214
212
  const workerOptions = { type: "module" };
215
213
  let scriptUrl, worker;
214
+ // deno-lint-ignore valid-typeof
216
215
  if (typeof url == FUNCTION_TYPE) {
217
216
  url = url();
218
217
  }
@@ -237,29 +236,29 @@ function getWebWorker(url, baseURL, workerData) {
237
236
 
238
237
  function sendMessage(message, { worker, writer, onTaskFinished, transferStreams }) {
239
238
  try {
240
- let { data, readable, writable } = message;
241
- const transferrables = [];
242
- if (data) {
243
- const { buffer, length } = data;
239
+ let { value, readable, writable } = message;
240
+ const transferables = [];
241
+ if (value) {
242
+ const { buffer, length } = value;
244
243
  if (length != buffer.byteLength) {
245
- data = new Uint8Array(data);
244
+ value = new Uint8Array(value);
246
245
  }
247
- message.data = data.buffer;
248
- transferrables.push(message.data);
246
+ message.value = value.buffer;
247
+ transferables.push(message.value);
249
248
  }
250
249
  if (transferStreams && transferStreamsSupported) {
251
250
  if (readable) {
252
- transferrables.push(readable);
251
+ transferables.push(readable);
253
252
  }
254
253
  if (writable) {
255
- transferrables.push(writable);
254
+ transferables.push(writable);
256
255
  }
257
256
  } else {
258
257
  message.readable = message.writable = null;
259
258
  }
260
- if (transferrables.length) {
259
+ if (transferables.length) {
261
260
  try {
262
- worker.postMessage(message, transferrables);
261
+ worker.postMessage(message, transferables);
263
262
  return true;
264
263
  } catch (_error) {
265
264
  transferStreamsSupported = false;
@@ -278,25 +277,23 @@ function sendMessage(message, { worker, writer, onTaskFinished, transferStreams
278
277
  }
279
278
  }
280
279
 
281
- async function onMessage(event, workerData) {
282
- const message = event.data;
280
+ async function onMessage({ data }, workerData) {
281
+ const { type, value, messageId, result, error } = data;
283
282
  const { reader, writer, resolveResult, rejectResult, onTaskFinished } = workerData;
284
- const { type, data, messageId, result } = message;
285
- const reponseError = message.error;
286
283
  try {
287
- if (reponseError) {
288
- const { message, stack, code, name } = reponseError;
289
- const error = new Error(message);
290
- Object.assign(error, { stack, code, name });
291
- close(error);
284
+ if (error) {
285
+ const { message, stack, code, name } = error;
286
+ const responseError = new Error(message);
287
+ Object.assign(responseError, { stack, code, name });
288
+ close(responseError);
292
289
  } else {
293
290
  if (type == MESSAGE_PULL) {
294
291
  const { value, done } = await reader.read();
295
- sendMessage({ type: MESSAGE_DATA, data: value, done, messageId }, workerData);
292
+ sendMessage({ type: MESSAGE_DATA, value, done, messageId }, workerData);
296
293
  }
297
294
  if (type == MESSAGE_DATA) {
298
295
  await writer.ready;
299
- await writer.write(new Uint8Array(data));
296
+ await writer.write(new Uint8Array(value));
300
297
  sendMessage({ type: MESSAGE_ACK_DATA, messageId }, workerData);
301
298
  }
302
299
  if (type == MESSAGE_CLOSE) {
@@ -69,14 +69,14 @@ const HmacSha1 = misc.hmacSha1;
69
69
 
70
70
  class AESDecryptionStream extends TransformStream {
71
71
 
72
- constructor(password, signed, strength) {
72
+ constructor({ password, signed, encryptionStrength }) {
73
73
  super({
74
74
  start() {
75
75
  Object.assign(this, {
76
76
  ready: new Promise(resolve => this.resolveReady = resolve),
77
77
  password,
78
78
  signed,
79
- strength: strength - 1,
79
+ strength: encryptionStrength - 1,
80
80
  pending: new Uint8Array()
81
81
  });
82
82
  },
@@ -132,7 +132,7 @@ class AESDecryptionStream extends TransformStream {
132
132
 
133
133
  class AESEncryptionStream extends TransformStream {
134
134
 
135
- constructor(password, strength) {
135
+ constructor({ password, encryptionStrength }) {
136
136
  // deno-lint-ignore prefer-const
137
137
  let stream;
138
138
  super({
@@ -140,7 +140,7 @@ class AESEncryptionStream extends TransformStream {
140
140
  Object.assign(this, {
141
141
  ready: new Promise(resolve => this.resolveReady = resolve),
142
142
  password,
143
- strength: strength - 1,
143
+ strength: encryptionStrength - 1,
144
144
  pending: new Uint8Array()
145
145
  });
146
146
  },
@@ -36,7 +36,7 @@ class StreamAdapter {
36
36
 
37
37
  constructor(Codec) {
38
38
  return class extends TransformStream {
39
- constructor(options) {
39
+ constructor(_format, options) {
40
40
  const codec = new Codec(options);
41
41
  super({
42
42
  transform(chunk, controller) {
@@ -39,7 +39,7 @@ const HEADER_LENGTH = 12;
39
39
 
40
40
  class ZipCryptoDecryptionStream extends TransformStream {
41
41
 
42
- constructor(password, passwordVerification) {
42
+ constructor({ password, passwordVerification }) {
43
43
  super({
44
44
  start() {
45
45
  Object.assign(this, {
@@ -66,7 +66,7 @@ class ZipCryptoDecryptionStream extends TransformStream {
66
66
 
67
67
  class ZipCryptoEncryptionStream extends TransformStream {
68
68
 
69
- constructor(password, passwordVerification) {
69
+ constructor({ password, passwordVerification }) {
70
70
  super({
71
71
  start() {
72
72
  Object.assign(this, {
@@ -49,7 +49,7 @@ class DeflateStream extends TransformStream {
49
49
 
50
50
  constructor(options, { chunkSize, CompressionStream, CompressionStreamNative }) {
51
51
  super({});
52
- const { compressed, encrypted, useCompressionStream, password, passwordVerification, encryptionStrength, zipCrypto, signed, level } = options;
52
+ const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level } = options;
53
53
  const stream = this;
54
54
  let crc32Stream, encryptionStream;
55
55
  let readable = filterEmptyChunks(super.readable);
@@ -62,9 +62,9 @@ class DeflateStream extends TransformStream {
62
62
  }
63
63
  if (encrypted) {
64
64
  if (zipCrypto) {
65
- readable = pipeThrough(readable, new ZipCryptoEncryptionStream(password, passwordVerification));
65
+ readable = pipeThrough(readable, new ZipCryptoEncryptionStream(options));
66
66
  } else {
67
- encryptionStream = new AESEncryptionStream(password, encryptionStrength);
67
+ encryptionStream = new AESEncryptionStream(options);
68
68
  readable = pipeThrough(readable, encryptionStream);
69
69
  }
70
70
  }
@@ -86,14 +86,14 @@ class InflateStream extends TransformStream {
86
86
 
87
87
  constructor(options, { chunkSize, DecompressionStream, DecompressionStreamNative }) {
88
88
  super({});
89
- const { zipCrypto, encrypted, password, passwordVerification, signed, signature, encryptionStrength, compressed, useCompressionStream } = options;
89
+ const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream } = options;
90
90
  let crc32Stream, decryptionStream;
91
91
  let readable = filterEmptyChunks(super.readable);
92
92
  if (encrypted) {
93
93
  if (zipCrypto) {
94
- readable = pipeThrough(readable, new ZipCryptoDecryptionStream(password, passwordVerification));
94
+ readable = pipeThrough(readable, new ZipCryptoDecryptionStream(options));
95
95
  } else {
96
- decryptionStream = new AESDecryptionStream(password, signed, encryptionStrength);
96
+ decryptionStream = new AESDecryptionStream(options);
97
97
  readable = pipeThrough(readable, decryptionStream);
98
98
  }
99
99
  }
@@ -47,10 +47,11 @@ function createCodecClass(constructor, constructorOptions, registerDataHandler)
47
47
  const codecAdapter = this;
48
48
  const onData = data => {
49
49
  if (codecAdapter.pendingData) {
50
+ const previousPendingData = codecAdapter.pendingData;
51
+ codecAdapter.pendingData = new Uint8Array(previousPendingData.length + data.length);
50
52
  const { pendingData } = codecAdapter;
51
- codecAdapter.pendingData = new Uint8Array(pendingData.length + data.length);
52
- pendingData.set(pendingData, 0);
53
- pendingData.set(data, pendingData.length);
53
+ pendingData.set(previousPendingData, 0);
54
+ pendingData.set(data, previousPendingData.length);
54
55
  } else {
55
56
  codecAdapter.pendingData = new Uint8Array(data);
56
57
  }
@@ -45,17 +45,16 @@ const pendingDataMessages = new Map();
45
45
 
46
46
  let messageId = 0;
47
47
 
48
- addEventListener(MESSAGE_EVENT_TYPE, event => {
49
- const message = event.data;
50
- const { type, messageId, data, done } = message;
48
+ addEventListener(MESSAGE_EVENT_TYPE, ({ data }) => {
49
+ const { type, messageId, value, done } = data;
51
50
  try {
52
51
  if (type == MESSAGE_START) {
53
- init(message);
52
+ init(data);
54
53
  }
55
54
  if (type == MESSAGE_DATA) {
56
55
  const resolve = pendingPullMessages.get(messageId);
57
56
  pendingPullMessages.delete(messageId);
58
- resolve({ value: new Uint8Array(data), done });
57
+ resolve({ value: new Uint8Array(value), done });
59
58
  }
60
59
  if (type == MESSAGE_ACK_DATA) {
61
60
  const resolve = pendingDataMessages.get(messageId);
@@ -98,11 +97,11 @@ async function init(message) {
98
97
  }
99
98
  }, strategy);
100
99
  const writable = message.writable || new WritableStream({
101
- async write(data) {
100
+ async write(value) {
102
101
  let resolveAckData;
103
102
  const ackData = new Promise(resolve => resolveAckData = resolve);
104
103
  pendingDataMessages.set(messageId, resolveAckData);
105
- sendMessage({ type: MESSAGE_DATA, data, messageId });
104
+ sendMessage({ type: MESSAGE_DATA, value, messageId });
106
105
  messageId = (messageId + 1) % Number.MAX_SAFE_INTEGER;
107
106
  await ackData;
108
107
  }
@@ -131,13 +130,13 @@ async function init(message) {
131
130
  }
132
131
 
133
132
  function sendMessage(message) {
134
- if (message.data) {
135
- let { data } = message;
136
- if (data && data.length) {
133
+ let { value } = message;
134
+ if (value) {
135
+ if (value.length) {
137
136
  try {
138
- data = new Uint8Array(data);
139
- message.data = data.buffer;
140
- postMessage(message, [message.data]);
137
+ value = new Uint8Array(value);
138
+ message.value = value.buffer;
139
+ postMessage(message, [message.value]);
141
140
  } catch (_error) {
142
141
  postMessage(message);
143
142
  }
@@ -354,7 +354,6 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
354
354
  const {
355
355
  keepOrder,
356
356
  dataDescriptor,
357
- zipCrypto,
358
357
  signal
359
358
  } = options;
360
359
  const previousFileEntry = Array.from(files.values()).pop();
@@ -409,20 +408,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
409
408
  await requestLockWriter();
410
409
  writingBufferedEntryData = true;
411
410
  if (!dataDescriptor) {
412
- const arrayBuffer = await sliceAsArrayBuffer(blob, 0, 26);
413
- const arrayBufferView = new DataView(arrayBuffer);
414
- if (!fileEntry.encrypted || zipCrypto) {
415
- setUint32(arrayBufferView, 14, fileEntry.signature);
416
- }
417
- if (fileEntry.zip64) {
418
- setUint32(arrayBufferView, 18, MAX_32_BITS);
419
- setUint32(arrayBufferView, 22, MAX_32_BITS);
420
- } else {
421
- setUint32(arrayBufferView, 18, fileEntry.compressedSize);
422
- setUint32(arrayBufferView, 22, fileEntry.uncompressedSize);
423
- }
424
- await writeData(writable, new Uint8Array(arrayBuffer));
425
- blob = blob.slice(arrayBuffer.byteLength);
411
+ blob = await setMissingInfo(fileEntry, blob, writable, options);
426
412
  }
427
413
  fileEntry.diskNumberStart = writer.diskNumber;
428
414
  diskOffset = writer.diskOffset;
@@ -432,10 +418,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
432
418
  }
433
419
  fileEntry.offset = zipWriter.offset - diskOffset;
434
420
  if (fileEntry.zip64) {
435
- const { rawExtraFieldZip64, offset, diskNumberStart } = fileEntry;
436
- const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
437
- setBigUint64(rawExtraFieldZip64View, 20, BigInt(offset));
438
- setUint32(rawExtraFieldZip64View, 28, diskNumberStart);
421
+ setZip64Info(fileEntry);
439
422
  } else if (fileEntry.offset >= MAX_32_BITS) {
440
423
  throw new Error(ERR_UNSUPPORTED_FORMAT);
441
424
  }
@@ -811,6 +794,30 @@ function setEntryInfo(entryInfo, options) {
811
794
  }
812
795
  }
813
796
 
797
+ async function setMissingInfo(fileEntry, entryData, writable, { zipCrypto }) {
798
+ const arrayBuffer = await sliceAsArrayBuffer(entryData, 0, 26);
799
+ const arrayBufferView = new DataView(arrayBuffer);
800
+ if (!fileEntry.encrypted || zipCrypto) {
801
+ setUint32(arrayBufferView, 14, fileEntry.signature);
802
+ }
803
+ if (fileEntry.zip64) {
804
+ setUint32(arrayBufferView, 18, MAX_32_BITS);
805
+ setUint32(arrayBufferView, 22, MAX_32_BITS);
806
+ } else {
807
+ setUint32(arrayBufferView, 18, fileEntry.compressedSize);
808
+ setUint32(arrayBufferView, 22, fileEntry.uncompressedSize);
809
+ }
810
+ await writeData(writable, new Uint8Array(arrayBuffer));
811
+ return entryData.slice(arrayBuffer.byteLength);
812
+ }
813
+
814
+ function setZip64Info(fileEntry) {
815
+ const { rawExtraFieldZip64, offset, diskNumberStart } = fileEntry;
816
+ const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
817
+ setBigUint64(rawExtraFieldZip64View, 20, BigInt(offset));
818
+ setUint32(rawExtraFieldZip64View, 28, diskNumberStart);
819
+ }
820
+
814
821
  async function closeFile(zipWriter, comment, options) {
815
822
  const { files, writer } = zipWriter;
816
823
  let offset = 0;