@zip.js/zip.js 2.5.11 → 2.5.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/cli-deno/mc-zip.js +157 -0
  2. package/dist/z-worker-fflate.js +1 -1
  3. package/dist/z-worker-pako.js +1 -1
  4. package/dist/z-worker.js +1 -1
  5. package/dist/zip-fs-full.js +268 -250
  6. package/dist/zip-fs-full.min.js +1 -1
  7. package/dist/zip-fs.js +252 -234
  8. package/dist/zip-fs.min.js +1 -1
  9. package/dist/zip-full.js +266 -248
  10. package/dist/zip-full.min.js +1 -1
  11. package/dist/zip-no-worker-deflate.min.js +1 -1
  12. package/dist/zip-no-worker-inflate.min.js +1 -1
  13. package/dist/zip-no-worker.min.js +1 -1
  14. package/dist/zip.js +250 -232
  15. package/dist/zip.min.js +1 -1
  16. package/index.d.ts +10 -4
  17. package/lib/core/codec-pool-worker.js +66 -44
  18. package/lib/core/codec-pool.js +19 -14
  19. package/lib/core/configuration.js +40 -28
  20. package/lib/core/io.js +42 -59
  21. package/lib/core/streams/aes-crypto-stream.js +5 -5
  22. package/lib/core/streams/codecs/deflate.js +8 -8
  23. package/lib/core/streams/codecs/inflate.js +8 -8
  24. package/lib/core/streams/codecs/sjcl.js +6 -6
  25. package/lib/core/streams/zip-entry-stream.js +3 -4
  26. package/lib/core/util/decode-text.js +1 -8
  27. package/lib/core/util/stream-codec-shim.js +3 -3
  28. package/lib/core/z-worker-core.js +17 -17
  29. package/lib/core/zip-fs-core.js +2 -2
  30. package/lib/core/zip-reader.js +27 -20
  31. package/lib/core/zip-writer.js +42 -45
  32. package/lib/z-worker-inline.js +1 -1
  33. package/package.json +1 -1
  34. package/rollup-fflate.config.dev.js +1 -1
  35. package/rollup-fflate.config.js +2 -2
  36. package/rollup.config.dev.js +1 -1
  37. package/rollup.config.js +3 -3
  38. package/tests/all/test-abort-signal-read.js +4 -2
@@ -2055,7 +2055,7 @@ const ZipInflate = (() => {
2055
2055
  }
2056
2056
 
2057
2057
  ZStream.prototype = {
2058
- inflateInit: function (bits) {
2058
+ inflateInit(bits) {
2059
2059
  const that = this;
2060
2060
  that.istate = new Inflate();
2061
2061
  if (!bits)
@@ -2063,14 +2063,14 @@ const ZipInflate = (() => {
2063
2063
  return that.istate.inflateInit(that, bits);
2064
2064
  },
2065
2065
 
2066
- inflate: function (f) {
2066
+ inflate(f) {
2067
2067
  const that = this;
2068
2068
  if (!that.istate)
2069
2069
  return Z_STREAM_ERROR;
2070
2070
  return that.istate.inflate(that, f);
2071
2071
  },
2072
2072
 
2073
- inflateEnd: function () {
2073
+ inflateEnd() {
2074
2074
  const that = this;
2075
2075
  if (!that.istate)
2076
2076
  return Z_STREAM_ERROR;
@@ -2079,23 +2079,23 @@ const ZipInflate = (() => {
2079
2079
  return ret;
2080
2080
  },
2081
2081
 
2082
- inflateSync: function () {
2082
+ inflateSync() {
2083
2083
  const that = this;
2084
2084
  if (!that.istate)
2085
2085
  return Z_STREAM_ERROR;
2086
2086
  return that.istate.inflateSync(that);
2087
2087
  },
2088
- inflateSetDictionary: function (dictionary, dictLength) {
2088
+ inflateSetDictionary(dictionary, dictLength) {
2089
2089
  const that = this;
2090
2090
  if (!that.istate)
2091
2091
  return Z_STREAM_ERROR;
2092
2092
  return that.istate.inflateSetDictionary(that, dictionary, dictLength);
2093
2093
  },
2094
- read_byte: function (start) {
2094
+ read_byte(start) {
2095
2095
  const that = this;
2096
2096
  return that.next_in[start];
2097
2097
  },
2098
- read_buf: function (start, size) {
2098
+ read_buf(start, size) {
2099
2099
  const that = this;
2100
2100
  return that.next_in.subarray(start, start + size);
2101
2101
  }
@@ -2155,7 +2155,7 @@ const ZipInflate = (() => {
2155
2155
  bufferIndex += chunk.length;
2156
2156
  });
2157
2157
  } else {
2158
- array = buffers[0] || new Uint8Array(0);
2158
+ array = buffers[0] || new Uint8Array();
2159
2159
  }
2160
2160
  return array;
2161
2161
  };
@@ -232,7 +232,7 @@ hash.sha1.prototype = {
232
232
  * Reset the hash state.
233
233
  * @return this
234
234
  */
235
- reset: function () {
235
+ reset() {
236
236
  const sha1 = this;
237
237
  sha1._h = this._init.slice(0);
238
238
  sha1._buffer = [];
@@ -245,7 +245,7 @@ hash.sha1.prototype = {
245
245
  * @param {bitArray|String} data the data to hash.
246
246
  * @return this
247
247
  */
248
- update: function (data) {
248
+ update(data) {
249
249
  const sha1 = this;
250
250
  if (typeof data === "string") {
251
251
  data = codec.utf8String.toBits(data);
@@ -271,7 +271,7 @@ hash.sha1.prototype = {
271
271
  * Complete hashing and output the hash value.
272
272
  * @return {bitArray} The hash value, an array of 5 big-endian words. TODO
273
273
  */
274
- finalize: function () {
274
+ finalize() {
275
275
  const sha1 = this;
276
276
  let b = sha1._buffer;
277
277
  const h = sha1._h;
@@ -311,7 +311,7 @@ hash.sha1.prototype = {
311
311
  * The SHA-1 logical functions f(0), f(1), ..., f(79).
312
312
  * @private
313
313
  */
314
- _f: function (t, b, c, d) {
314
+ _f(t, b, c, d) {
315
315
  if (t <= 19) {
316
316
  return (b & c) | (~b & d);
317
317
  } else if (t <= 39) {
@@ -327,7 +327,7 @@ hash.sha1.prototype = {
327
327
  * Circular left-shift operator.
328
328
  * @private
329
329
  */
330
- _S: function (n, x) {
330
+ _S(n, x) {
331
331
  return (x << n) | (x >>> 32 - n);
332
332
  },
333
333
 
@@ -336,7 +336,7 @@ hash.sha1.prototype = {
336
336
  * @param {Uint32Array|bitArray} words one block of words.
337
337
  * @private
338
338
  */
339
- _block: function (words) {
339
+ _block(words) {
340
340
  const sha1 = this;
341
341
  const h = sha1._h;
342
342
  // When words is passed to _block, it has 16 elements. SHA1 _block
@@ -66,8 +66,7 @@ class DeflateStream extends TransformStream {
66
66
  readable = pipeCodecStream(codecConstructor, readable, chunkSize);
67
67
  } else {
68
68
  try {
69
- const compressionStream = new CompressionStream(COMPRESSION_FORMAT);
70
- readable = readable.pipeThrough(compressionStream);
69
+ readable = readable.pipeThrough(new CompressionStream(COMPRESSION_FORMAT));
71
70
  } catch (_error) {
72
71
  DEFLATE_RAW_SUPPORTED = false;
73
72
  readable = pipeCodecStream(codecConstructor, readable, chunkSize);
@@ -153,8 +152,8 @@ export {
153
152
  ERR_INVALID_SIGNATURE
154
153
  };
155
154
 
156
- function pipeCodecStream(codecConstructor, stream, chunkSize) {
157
- return stream.pipeThrough(new CodecStream(codecConstructor, { chunkSize }));
155
+ function pipeCodecStream(codecConstructor, readable, chunkSize) {
156
+ return readable.pipeThrough(new CodecStream(codecConstructor, { chunkSize }));
158
157
  }
159
158
 
160
159
  function filterEmptyChunks(readable) {
@@ -26,7 +26,7 @@
26
26
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
- /* global TextDecoder, FileReader, Blob */
29
+ /* global TextDecoder */
30
30
 
31
31
  import decodeCP437 from "./cp437-decode.js";
32
32
 
@@ -35,13 +35,6 @@ export default decodeText;
35
35
  function decodeText(value, encoding) {
36
36
  if (encoding && encoding.trim().toLowerCase() == "cp437") {
37
37
  return decodeCP437(value);
38
- } else if (typeof TextDecoder == "undefined") {
39
- const fileReader = new FileReader();
40
- return new Promise((resolve, reject) => {
41
- fileReader.onload = event => resolve(event.target.result);
42
- fileReader.onerror = () => reject(fileReader.error);
43
- fileReader.readAsText(new Blob([value]));
44
- });
45
38
  } else {
46
39
  return new TextDecoder(encoding).decode(value);
47
40
  }
@@ -41,7 +41,7 @@ function createCodecClass(constructor, constructorOptions, registerDataHandler)
41
41
  const codecAdapter = this;
42
42
  const onData = data => {
43
43
  if (codecAdapter.pendingData) {
44
- const pendingData = codecAdapter.pendingData;
44
+ const { pendingData } = codecAdapter;
45
45
  codecAdapter.pendingData = new Uint8Array(pendingData.length + data.length);
46
46
  codecAdapter.pendingData.set(pendingData, 0);
47
47
  codecAdapter.pendingData.set(data, pendingData.length);
@@ -61,7 +61,7 @@ function createCodecClass(constructor, constructorOptions, registerDataHandler)
61
61
  return getResponse(this);
62
62
  }
63
63
  flush() {
64
- this.codec.push(new Uint8Array(0), true);
64
+ this.codec.push(new Uint8Array(), true);
65
65
  return getResponse(this);
66
66
  }
67
67
  };
@@ -72,7 +72,7 @@ function createCodecClass(constructor, constructorOptions, registerDataHandler)
72
72
  codec.pendingData = null;
73
73
  return output;
74
74
  } else {
75
- return new Uint8Array(0);
75
+ return new Uint8Array();
76
76
  }
77
77
  }
78
78
  }
@@ -46,15 +46,15 @@ let messageId = 0;
46
46
 
47
47
  addEventListener(MESSAGE_EVENT_TYPE, async event => {
48
48
  const message = event.data;
49
- const type = message.type;
49
+ const { type, messageId, data, done } = message;
50
50
  try {
51
51
  if (type == MESSAGE_START) {
52
52
  init(message);
53
53
  }
54
54
  if (type == MESSAGE_DATA) {
55
- const { resolve } = pendingMessages.get(message.messageId);
56
- pendingMessages.delete(message.messageId);
57
- resolve({ value: new Uint8Array(message.data), done: message.done });
55
+ const { resolve } = pendingMessages.get(messageId);
56
+ pendingMessages.delete(messageId);
57
+ resolve({ value: new Uint8Array(data), done });
58
58
  }
59
59
  if (type == MESSAGE_ABORT) {
60
60
  codec.abort();
@@ -66,45 +66,45 @@ addEventListener(MESSAGE_EVENT_TYPE, async event => {
66
66
 
67
67
  async function init(message) {
68
68
  try {
69
- if (message.scripts && message.scripts.length) {
70
- importScripts.apply(undefined, message.scripts);
69
+ const { options, scripts, config } = message;
70
+ const { codecType } = options;
71
+ if (scripts && scripts.length) {
72
+ importScripts.apply(undefined, scripts);
71
73
  }
72
- const options = message.options;
73
74
  if (self.initCodec) {
74
75
  self.initCodec();
75
76
  }
76
77
  let codecConstructor;
77
- if (options.codecType.startsWith(CODEC_DEFLATE)) {
78
+ if (codecType.startsWith(CODEC_DEFLATE)) {
78
79
  codecConstructor = self.Deflate;
79
- } else if (options.codecType.startsWith(CODEC_INFLATE)) {
80
+ } else if (codecType.startsWith(CODEC_INFLATE)) {
80
81
  codecConstructor = self.Inflate;
81
82
  }
83
+ const strategy = { highWaterMark: 1, size: () => config.chunkSize };
82
84
  const readable = new ReadableStream({
83
85
  async pull(controller) {
84
86
  let result = new Promise((resolve, reject) => pendingMessages.set(messageId, { resolve, reject }));
85
87
  sendMessage({ type: MESSAGE_PULL, messageId });
86
- messageId++;
88
+ messageId = (messageId + 1) % Number.MAX_SAFE_INTEGER;
87
89
  const { value, done } = await result;
88
- // debugger;
89
90
  controller.enqueue(value);
90
91
  if (done) {
91
92
  controller.close();
92
93
  }
93
94
  }
94
- }, {
95
- highWaterMark: 1
96
- });
95
+ }, strategy);
97
96
  const writable = new WritableStream({
98
97
  write(data) {
99
98
  sendMessage({ type: MESSAGE_DATA, data });
100
99
  }
101
- });
102
- codec = createCodec(codecConstructor, readable, writable, options, message.config);
100
+ }, strategy);
101
+ codec = createCodec(codecConstructor, readable, writable, options, config);
103
102
  const result = await codec.run();
104
103
  sendMessage({ type: MESSAGE_CLOSE, result });
105
104
 
106
105
  } catch (error) {
107
- postMessage({ error: { message: error.message, stack: error.stack } });
106
+ const { message, stack } = error;
107
+ postMessage({ error: { message, stack } });
108
108
  }
109
109
  }
110
110
 
@@ -503,11 +503,11 @@ async function exportZip(zipWriter, entry, totalSize, options) {
503
503
  await zipWriter.add(name, child.reader, Object.assign({
504
504
  directory: child.directory
505
505
  }, Object.assign({}, options, {
506
- onprogress: indexProgress => {
506
+ onprogress: async indexProgress => {
507
507
  if (options.onprogress) {
508
508
  entryOffsets.set(name, indexProgress);
509
509
  try {
510
- options.onprogress(Array.from(entryOffsets.values()).reduce((previousValue, currentValue) => previousValue + currentValue), totalSize);
510
+ await options.onprogress(Array.from(entryOffsets.values()).reduce((previousValue, currentValue) => previousValue + currentValue), totalSize);
511
511
  } catch (_error) {
512
512
  // ignored
513
513
  }
@@ -61,7 +61,7 @@ import {
61
61
  getChunkSize
62
62
  } from "./configuration.js";
63
63
  import {
64
- runCodec,
64
+ runWorker,
65
65
  CODEC_INFLATE,
66
66
  ERR_INVALID_SIGNATURE,
67
67
  ERR_INVALID_PASSWORD
@@ -96,7 +96,7 @@ class ZipReader {
96
96
 
97
97
  async* getEntriesGenerator(options = {}) {
98
98
  const zipReader = this;
99
- const reader = zipReader.reader;
99
+ const { reader, config } = zipReader;
100
100
  if (!reader.initialized) {
101
101
  await reader.init();
102
102
  }
@@ -156,7 +156,7 @@ class ZipReader {
156
156
  throw new Error(ERR_BAD_FORMAT);
157
157
  }
158
158
  for (let indexFile = 0; indexFile < filesLength; indexFile++) {
159
- const fileEntry = new ZipEntry(reader, zipReader.config, zipReader.options);
159
+ const fileEntry = new ZipEntry(reader, config, zipReader.options);
160
160
  if (getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
161
161
  throw new Error(ERR_CENTRAL_DIRECTORY_NOT_FOUND);
162
162
  }
@@ -201,7 +201,7 @@ class ZipReader {
201
201
  offset = endOffset;
202
202
  if (options.onprogress) {
203
203
  try {
204
- options.onprogress(indexFile + 1, filesLength, new Entry(fileEntry));
204
+ await options.onprogress(indexFile + 1, filesLength, new Entry(fileEntry));
205
205
  } catch (_error) {
206
206
  // ignored
207
207
  }
@@ -301,25 +301,32 @@ class ZipEntry {
301
301
  }
302
302
  const dataOffset = offset + 30 + localDirectory.filenameLength + localDirectory.extraFieldLength;
303
303
  const size = () => compressedSize;
304
- const readable = reader.getStream({ offset: dataOffset, size, chunkSize: getChunkSize(config) });
305
- const writable = writer.getStream();
304
+ const readable = reader.getReadable({ offset: dataOffset, size, chunkSize: getChunkSize(config) });
305
+ const { writable } = writer;
306
306
  const signal = getOptionValue(zipEntry, options, "signal");
307
307
  if (!writer.initialized) {
308
308
  await writer.init();
309
309
  }
310
- await runCodec(config.Inflate, readable, writable, {
311
- codecType: CODEC_INFLATE,
312
- password,
313
- zipCrypto,
314
- encryptionStrength: extraFieldAES && extraFieldAES.strength,
315
- signed: getOptionValue(zipEntry, options, "checkSignature"),
316
- passwordVerification: zipCrypto && (bitFlag.dataDescriptor ? ((rawLastModDate >>> 8) & 0xFF) : ((signature >>> 24) & 0xFF)),
317
- signature,
318
- compressed: compressionMethod != 0,
319
- encrypted,
320
- useWebWorkers: getOptionValue(zipEntry, options, "useWebWorkers"),
321
- useCompressionStream: getOptionValue(zipEntry, options, "useCompressionStream")
322
- }, config, { signal, onprogress: options.onprogress, size });
310
+ const { onstart, onprogress, onend } = options;
311
+ const workerOptions = {
312
+ options: {
313
+ codecType: CODEC_INFLATE,
314
+ password,
315
+ zipCrypto,
316
+ encryptionStrength: extraFieldAES && extraFieldAES.strength,
317
+ signed: getOptionValue(zipEntry, options, "checkSignature"),
318
+ passwordVerification: zipCrypto && (bitFlag.dataDescriptor ? ((rawLastModDate >>> 8) & 0xFF) : ((signature >>> 24) & 0xFF)),
319
+ signature,
320
+ compressed: compressionMethod != 0,
321
+ encrypted,
322
+ useWebWorkers: getOptionValue(zipEntry, options, "useWebWorkers"),
323
+ useCompressionStream: getOptionValue(zipEntry, options, "useCompressionStream")
324
+ },
325
+ config,
326
+ streamOptions: { signal, size, onstart, onprogress, onend },
327
+ codecConstructor: config.Inflate
328
+ };
329
+ await runWorker({ readable, writable }, workerOptions);
323
330
  return writer.getData();
324
331
  }
325
332
  }
@@ -344,7 +351,7 @@ function readCommonHeader(directory, dataView, offset) {
344
351
  }
345
352
 
346
353
  async function readCommonFooter(fileEntry, directory, dataView, offset) {
347
- const rawExtraField = directory.rawExtraField;
354
+ const { rawExtraField } = directory;
348
355
  const extraField = directory.extraField = new Map();
349
356
  const rawExtraFieldView = getDataView(new Uint8Array(rawExtraField));
350
357
  let offsetExtraField = 0;
@@ -26,7 +26,7 @@
26
26
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
- /* global BigInt, FileReader */
29
+ /* global BigInt */
30
30
 
31
31
  import {
32
32
  MAX_32_BITS,
@@ -65,7 +65,7 @@ import {
65
65
  } from "./configuration.js";
66
66
  import {
67
67
  CODEC_DEFLATE,
68
- runCodec
68
+ runWorker
69
69
  } from "./codec-pool.js";
70
70
  import encodeText from "./util/encode-text.js";
71
71
  import { BlobWriter } from "./io.js";
@@ -125,7 +125,7 @@ class ZipWriter {
125
125
  }
126
126
  }
127
127
 
128
- async close(comment = new Uint8Array(0), options = {}) {
128
+ async close(comment = new Uint8Array(), options = {}) {
129
129
  while (this.pendingAddFileCalls.size) {
130
130
  await Promise.all(Array.from(this.pendingAddFileCalls));
131
131
  }
@@ -183,8 +183,8 @@ async function addFile(zipWriter, name, reader, options) {
183
183
  if (password !== undefined && encryptionStrength !== undefined && (encryptionStrength < 1 || encryptionStrength > 3)) {
184
184
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
185
185
  }
186
- let rawExtraField = new Uint8Array(0);
187
- const extraField = options.extraField;
186
+ let rawExtraField = new Uint8Array();
187
+ const { extraField } = options;
188
188
  if (extraField) {
189
189
  let extraFieldSize = 0;
190
190
  let offset = 0;
@@ -295,11 +295,10 @@ async function getFileEntry(zipWriter, name, reader, options) {
295
295
  try {
296
296
  let lockPreviousFileEntry;
297
297
  let fileWriter;
298
- let lockCurrentFileEntry;
299
298
  if (options.keepOrder) {
300
299
  lockPreviousFileEntry = previousFileEntry && previousFileEntry.lock;
301
300
  }
302
- fileEntry.lock = lockCurrentFileEntry = new Promise(resolve => resolveLockCurrentFileEntry = resolve);
301
+ fileEntry.lock = new Promise(resolve => resolveLockCurrentFileEntry = resolve);
303
302
  if (options.bufferedWrite || zipWriter.lockWrite || !options.dataDescriptor) {
304
303
  fileWriter = new BlobWriter();
305
304
  fileWriter.init();
@@ -311,8 +310,7 @@ async function getFileEntry(zipWriter, name, reader, options) {
311
310
  }
312
311
  fileWriter = writer;
313
312
  }
314
- fileEntry = await createFileEntry(reader, fileWriter.getStream(), zipWriter.config, options);
315
- fileEntry.lock = lockCurrentFileEntry;
313
+ fileEntry = await createFileEntry(reader, fileWriter.writable, zipWriter.config, options);
316
314
  files.set(name, fileEntry);
317
315
  fileEntry.filename = name;
318
316
  if (bufferedWrite) {
@@ -327,7 +325,7 @@ async function getFileEntry(zipWriter, name, reader, options) {
327
325
  }
328
326
  } while (pendingFileEntry && pendingFileEntry.lock);
329
327
  fileEntry.writingBufferedData = true;
330
- const writable = writer.getStream();
328
+ const { writable } = writer;
331
329
  if (!options.dataDescriptor) {
332
330
  const headerLength = 26;
333
331
  const arrayBuffer = await sliceAsArrayBuffer(blob, 0, headerLength);
@@ -391,7 +389,9 @@ async function createFileEntry(reader, writable, config, options) {
391
389
  rawComment,
392
390
  rawExtraField,
393
391
  useWebWorkers,
392
+ onstart,
394
393
  onprogress,
394
+ onend,
395
395
  signal,
396
396
  encryptionStrength,
397
397
  extendedTimestamp,
@@ -410,7 +410,7 @@ async function createFileEntry(reader, writable, config, options) {
410
410
  arraySet(rawExtraFieldAES, EXTRAFIELD_DATA_AES, 2);
411
411
  setUint8(extraFieldAESView, 8, encryptionStrength);
412
412
  } else {
413
- rawExtraFieldAES = new Uint8Array(0);
413
+ rawExtraFieldAES = new Uint8Array();
414
414
  }
415
415
  let rawExtraFieldNTFS;
416
416
  let rawExtraFieldExtendedTimestamp;
@@ -440,10 +440,10 @@ async function createFileEntry(reader, writable, config, options) {
440
440
  setBigUint64(extraFieldNTFSView, 20, getTimeNTFS(lastAccessDate) || lastModTimeNTFS);
441
441
  setBigUint64(extraFieldNTFSView, 28, getTimeNTFS(creationDate) || lastModTimeNTFS);
442
442
  } catch (_error) {
443
- rawExtraFieldNTFS = new Uint8Array(0);
443
+ rawExtraFieldNTFS = new Uint8Array();
444
444
  }
445
445
  } else {
446
- rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array(0);
446
+ rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array();
447
447
  }
448
448
  const fileEntry = {
449
449
  version: version || VERSION_DEFLATE,
@@ -454,7 +454,7 @@ async function createFileEntry(reader, writable, config, options) {
454
454
  rawFilename,
455
455
  commentUTF8: true,
456
456
  rawComment,
457
- rawExtraFieldZip64: zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array(0),
457
+ rawExtraFieldZip64: zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array(),
458
458
  rawExtraFieldExtendedTimestamp,
459
459
  rawExtraFieldNTFS,
460
460
  rawExtraFieldAES,
@@ -524,27 +524,33 @@ async function createFileEntry(reader, writable, config, options) {
524
524
  await writeUint8Array(writable, localHeaderArray);
525
525
  fileEntry.dataWritten = true;
526
526
  const size = () => reader.size;
527
- const readable = reader.getStream({ offset: 0, size, chunkSize: getChunkSize(config) });
528
- result = await runCodec(config.Deflate, readable, writable, {
529
- codecType: CODEC_DEFLATE,
530
- level,
531
- password,
532
- encryptionStrength,
533
- zipCrypto: encrypted && zipCrypto,
534
- passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
535
- signed: true,
536
- compressed,
537
- encrypted,
538
- useWebWorkers,
539
- useCompressionStream
540
- }, config, { signal, onprogress, size });
527
+ const readable = reader.getReadable({ offset: 0, size, chunkSize: getChunkSize(config) });
528
+ const workerOptions = {
529
+ options: {
530
+ codecType: CODEC_DEFLATE,
531
+ level,
532
+ password,
533
+ encryptionStrength,
534
+ zipCrypto: encrypted && zipCrypto,
535
+ passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
536
+ signed: true,
537
+ compressed,
538
+ encrypted,
539
+ useWebWorkers,
540
+ useCompressionStream
541
+ },
542
+ config,
543
+ streamOptions: { signal, size, onstart, onprogress, onend },
544
+ codecConstructor: config.Deflate
545
+ };
546
+ result = await runWorker({ readable, writable }, workerOptions);
541
547
  uncompressedSize = fileEntry.uncompressedSize = reader.size;
542
548
  compressedSize = result.length;
543
549
  } else {
544
550
  await writeUint8Array(writable, localHeaderArray);
545
551
  fileEntry.dataWritten = true;
546
552
  }
547
- let dataDescriptorArray = new Uint8Array(0);
553
+ let dataDescriptorArray = new Uint8Array();
548
554
  let dataDescriptorView, dataDescriptorOffset = 0;
549
555
  if (dataDescriptor) {
550
556
  dataDescriptorArray = new Uint8Array(zip64 ? (dataDescriptorSignature ? 24 : 20) : (dataDescriptorSignature ? 16 : 12));
@@ -555,7 +561,7 @@ async function createFileEntry(reader, writable, config, options) {
555
561
  }
556
562
  }
557
563
  if (reader) {
558
- const signature = result.signature;
564
+ const { signature } = result;
559
565
  if ((!encrypted || zipCrypto) && signature !== undefined) {
560
566
  setUint32(headerView, 10, signature);
561
567
  fileEntry.signature = signature;
@@ -651,7 +657,7 @@ async function closeFile(zipWriter, comment, options) {
651
657
  setUint8(extraFieldExtendedTimestampView, 4, 0x1);
652
658
  setUint32(extraFieldExtendedTimestampView, 5, Math.floor(fileEntry.lastModDate.getTime() / 1000));
653
659
  } else {
654
- rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array(0);
660
+ rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array();
655
661
  }
656
662
  const extraFieldLength = rawExtraFieldZip64.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length + rawExtraField.length;
657
663
  setUint32(directoryView, offset, CENTRAL_FILE_HEADER_SIGNATURE);
@@ -680,7 +686,7 @@ async function closeFile(zipWriter, comment, options) {
680
686
  offset += 46 + rawFilename.length + extraFieldLength + rawComment.length;
681
687
  if (options.onprogress) {
682
688
  try {
683
- options.onprogress(indexFileEntry + 1, files.size, new Entry(fileEntry));
689
+ await options.onprogress(indexFileEntry + 1, files.size, new Entry(fileEntry));
684
690
  } catch (_error) {
685
691
  // ignored
686
692
  }
@@ -708,7 +714,7 @@ async function closeFile(zipWriter, comment, options) {
708
714
  setUint16(directoryView, offset + 10, filesLength);
709
715
  setUint32(directoryView, offset + 12, directoryDataLength);
710
716
  setUint32(directoryView, offset + 16, directoryOffset);
711
- const writable = zipWriter.writer.getStream();
717
+ const { writable } = zipWriter.writer;
712
718
  await writeUint8Array(writable, directoryArray);
713
719
  if (comment && comment.length) {
714
720
  await writeUint8Array(writable, comment);
@@ -716,19 +722,10 @@ async function closeFile(zipWriter, comment, options) {
716
722
  }
717
723
 
718
724
  function sliceAsArrayBuffer(blob, start, end) {
719
- if (blob.arrayBuffer) {
720
- if (start || end) {
721
- return blob.slice(start, end).arrayBuffer();
722
- } else {
723
- return blob.arrayBuffer();
724
- }
725
+ if (start || end) {
726
+ return blob.slice(start, end).arrayBuffer();
725
727
  } else {
726
- const fileReader = new FileReader();
727
- return new Promise((resolve, reject) => {
728
- fileReader.onload = event => resolve(event.target.result);
729
- fileReader.onerror = () => reject(fileReader.error);
730
- fileReader.readAsArrayBuffer(start || end ? blob.slice(start, end) : blob);
731
- });
728
+ return blob.arrayBuffer();
732
729
  }
733
730
  }
734
731