@zip.js/zip.js 2.5.10 → 2.5.13

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.
@@ -41,7 +41,7 @@ let pool = [];
41
41
  const pendingRequests = [];
42
42
 
43
43
  export {
44
- runCodec,
44
+ runWorker,
45
45
  terminateWorkers,
46
46
  CODEC_DEFLATE,
47
47
  CODEC_INFLATE,
@@ -52,24 +52,26 @@ export {
52
52
 
53
53
  let indexWorker = 0;
54
54
 
55
- async function runCodec(codecConstructor, readable, writable, options, config, streamOptions) {
55
+ async function runWorker(stream, workerOptions) {
56
+ const { options, config, streamOptions } = workerOptions;
56
57
  const streamCopy = !options.compressed && !options.signed && !options.encrypted;
57
- const webWorker = !streamCopy && (options.useWebWorkers || (options.useWebWorkers === undefined && config.useWebWorkers));
58
- const scripts = webWorker && config.workerScripts ? config.workerScripts[options.codecType] : [];
58
+ workerOptions.webWorker = !streamCopy && (options.useWebWorkers || (options.useWebWorkers === undefined && config.useWebWorkers));
59
+ workerOptions.scripts = workerOptions.webWorker && config.workerScripts ? config.workerScripts[options.codecType] : [];
59
60
  options.useCompressionStream = options.useCompressionStream === undefined ? config.useCompressionStream : options.useCompressionStream;
60
61
  let codec;
62
+
61
63
  if (pool.length < config.maxWorkers) {
62
64
  const workerData = { indexWorker };
63
65
  indexWorker++;
64
66
  pool.push(workerData);
65
- codec = getWorker(workerData, codecConstructor, readable, writable, options, config, streamOptions, onTaskFinished, webWorker, scripts);
67
+ codec = getWorker(workerData, stream, workerOptions, onTaskFinished);
66
68
  } else {
67
69
  const workerData = pool.find(workerData => !workerData.busy);
68
70
  if (workerData) {
69
71
  clearTerminateTimeout(workerData);
70
- codec = getWorker(workerData, codecConstructor, readable, writable, options, config, streamOptions, onTaskFinished, webWorker, scripts);
72
+ codec = getWorker(workerData, stream, workerOptions, onTaskFinished);
71
73
  } else {
72
- codec = await new Promise(resolve => pendingRequests.push({ resolve, codecConstructor, readable, writable, options, webWorker, scripts }));
74
+ codec = await new Promise(resolve => pendingRequests.push({ resolve, stream, workerOptions }));
73
75
  }
74
76
  }
75
77
  const { signal } = streamOptions;
@@ -86,8 +88,8 @@ async function runCodec(codecConstructor, readable, writable, options, config, s
86
88
 
87
89
  function onTaskFinished(workerData) {
88
90
  if (pendingRequests.length) {
89
- const [{ resolve, codecConstructor, readable, writable, options, webWorker, scripts }] = pendingRequests.splice(0, 1);
90
- resolve(getWorker(workerData, codecConstructor, readable, writable, options, config, streamOptions, onTaskFinished, webWorker, scripts));
91
+ const [{ resolve, stream, workerOptions }] = pendingRequests.splice(0, 1);
92
+ resolve(getWorker(workerData, stream, workerOptions, onTaskFinished));
91
93
  } else if (workerData.worker) {
92
94
  clearTerminateTimeout(workerData);
93
95
  if (Number.isFinite(config.terminateWorkerTimeout) && config.terminateWorkerTimeout >= 0) {
package/lib/core/io.js CHANGED
@@ -55,7 +55,7 @@ class Stream {
55
55
 
56
56
  class Reader extends Stream {
57
57
 
58
- getStream({ offset, size, chunkSize } = { offset: 0, chunkSize: DEFAULT_CHUNK_SIZE }) {
58
+ getReadable({ offset, size, chunkSize } = { offset: 0, chunkSize: DEFAULT_CHUNK_SIZE }) {
59
59
  const reader = this;
60
60
  return new ReadableStream({
61
61
  start() {
@@ -76,7 +76,7 @@ class Reader extends Stream {
76
76
 
77
77
  class WriterStream extends Stream {
78
78
 
79
- getStream() {
79
+ get writable() {
80
80
  const writer = this;
81
81
  return new WritableStream({
82
82
  write(chunk) {
@@ -227,9 +227,10 @@ class BlobWriter extends Writer {
227
227
 
228
228
  constructor(contentType) {
229
229
  super();
230
- this.contentType = contentType;
231
- this.arrayBuffersMaxlength = 8;
232
- initArrayBuffers(this);
230
+ const writer = this;
231
+ writer.contentType = contentType;
232
+ writer.arrayBuffersMaxlength = 8;
233
+ initArrayBuffers(writer);
233
234
  }
234
235
 
235
236
  writeUint8Array(array) {
@@ -283,7 +284,7 @@ class ReadableStreamReader {
283
284
  this.initialized = true;
284
285
  }
285
286
 
286
- getStream() {
287
+ getReadable() {
287
288
  return this.readableStream;
288
289
  }
289
290
  }
@@ -292,8 +293,11 @@ class WritableStreamWriter extends Writer {
292
293
 
293
294
  constructor(writable) {
294
295
  super();
295
- const writer = this;
296
- writer.writable = writable;
296
+ Object.defineProperty(this, "writable", {
297
+ get() {
298
+ return writable;
299
+ }
300
+ });
297
301
  }
298
302
 
299
303
  async writeUint8Array(array) {
@@ -303,10 +307,6 @@ class WritableStreamWriter extends Writer {
303
307
  writer.releaseLock();
304
308
  }
305
309
 
306
- getStream() {
307
- return this.writable;
308
- }
309
-
310
310
  async getData() {
311
311
  await this.writable.getWriter().close();
312
312
  return this.writable;
@@ -322,11 +322,11 @@ class FetchReader extends Reader {
322
322
  reader.preventHeadRequest = options.preventHeadRequest;
323
323
  reader.useRangeHeader = options.useRangeHeader;
324
324
  reader.forceRangeRequests = options.forceRangeRequests;
325
- reader.options = Object.assign({}, options);
326
- delete reader.options.preventHeadRequest;
327
- delete reader.options.useRangeHeader;
328
- delete reader.options.forceRangeRequests;
329
- delete reader.options.useXHR;
325
+ reader.options = options = Object.assign({}, options);
326
+ delete options.preventHeadRequest;
327
+ delete options.useRangeHeader;
328
+ delete options.forceRangeRequests;
329
+ delete options.useXHR;
330
330
  }
331
331
 
332
332
  async init() {
@@ -494,12 +494,9 @@ class HttpReader extends Reader {
494
494
 
495
495
  constructor(url, options = {}) {
496
496
  super();
497
- this.url = url;
498
- if (options.useXHR) {
499
- this.reader = new XHRReader(url, options);
500
- } else {
501
- this.reader = new FetchReader(url, options);
502
- }
497
+ const reader = this;
498
+ reader.url = url;
499
+ reader.reader = options.useXHR ? new XHRReader(url, options) : new FetchReader(url, options);
503
500
  }
504
501
 
505
502
  set size(value) {
@@ -590,4 +587,4 @@ export {
590
587
  WritableStreamWriter,
591
588
  ERR_HTTP_RANGE,
592
589
  ERR_NOT_SEEKABLE_READER
593
- };
590
+ };
@@ -1891,7 +1891,7 @@ const ZipDeflate = (() => {
1891
1891
  }
1892
1892
 
1893
1893
  ZStream.prototype = {
1894
- deflateInit: function (level, bits) {
1894
+ deflateInit(level, bits) {
1895
1895
  const that = this;
1896
1896
  that.dstate = new Deflate();
1897
1897
  if (!bits)
@@ -1899,7 +1899,7 @@ const ZipDeflate = (() => {
1899
1899
  return that.dstate.deflateInit(that, level, bits);
1900
1900
  },
1901
1901
 
1902
- deflate: function (flush) {
1902
+ deflate(flush) {
1903
1903
  const that = this;
1904
1904
  if (!that.dstate) {
1905
1905
  return Z_STREAM_ERROR;
@@ -1907,7 +1907,7 @@ const ZipDeflate = (() => {
1907
1907
  return that.dstate.deflate(that, flush);
1908
1908
  },
1909
1909
 
1910
- deflateEnd: function () {
1910
+ deflateEnd() {
1911
1911
  const that = this;
1912
1912
  if (!that.dstate)
1913
1913
  return Z_STREAM_ERROR;
@@ -1916,14 +1916,14 @@ const ZipDeflate = (() => {
1916
1916
  return ret;
1917
1917
  },
1918
1918
 
1919
- deflateParams: function (level, strategy) {
1919
+ deflateParams(level, strategy) {
1920
1920
  const that = this;
1921
1921
  if (!that.dstate)
1922
1922
  return Z_STREAM_ERROR;
1923
1923
  return that.dstate.deflateParams(that, level, strategy);
1924
1924
  },
1925
1925
 
1926
- deflateSetDictionary: function (dictionary, dictLength) {
1926
+ deflateSetDictionary(dictionary, dictLength) {
1927
1927
  const that = this;
1928
1928
  if (!that.dstate)
1929
1929
  return Z_STREAM_ERROR;
@@ -1935,7 +1935,7 @@ const ZipDeflate = (() => {
1935
1935
  // this function so some applications may wish to modify it to avoid
1936
1936
  // allocating a large strm->next_in buffer and copying from it.
1937
1937
  // (See also flush_pending()).
1938
- read_buf: function (buf, start, size) {
1938
+ read_buf(buf, start, size) {
1939
1939
  const that = this;
1940
1940
  let len = that.avail_in;
1941
1941
  if (len > size)
@@ -1953,7 +1953,7 @@ const ZipDeflate = (() => {
1953
1953
  // through this function so some applications may wish to modify it
1954
1954
  // to avoid allocating a large strm->next_out buffer and copying into it.
1955
1955
  // (See also read_buf()).
1956
- flush_pending: function () {
1956
+ flush_pending() {
1957
1957
  const that = this;
1958
1958
  let len = that.dstate.pending;
1959
1959
 
@@ -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
  }
@@ -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) {
@@ -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);
@@ -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();
@@ -79,26 +79,24 @@ async function init(message) {
79
79
  } else if (options.codecType.startsWith(CODEC_INFLATE)) {
80
80
  codecConstructor = self.Inflate;
81
81
  }
82
+ const strategy = { highWaterMark: 1, size: () => message.config.chunkSize };
82
83
  const readable = new ReadableStream({
83
84
  async pull(controller) {
84
85
  let result = new Promise((resolve, reject) => pendingMessages.set(messageId, { resolve, reject }));
85
86
  sendMessage({ type: MESSAGE_PULL, messageId });
86
- messageId++;
87
+ messageId = (messageId + 1) % Number.MAX_SAFE_INTEGER;
87
88
  const { value, done } = await result;
88
- // debugger;
89
89
  controller.enqueue(value);
90
90
  if (done) {
91
91
  controller.close();
92
92
  }
93
93
  }
94
- }, {
95
- highWaterMark: 1
96
- });
94
+ }, strategy);
97
95
  const writable = new WritableStream({
98
96
  write(data) {
99
97
  sendMessage({ type: MESSAGE_DATA, data });
100
98
  }
101
- });
99
+ }, strategy);
102
100
  codec = createCodec(codecConstructor, readable, writable, options, message.config);
103
101
  const result = await codec.run();
104
102
  sendMessage({ type: MESSAGE_CLOSE, result });
@@ -110,10 +108,13 @@ async function init(message) {
110
108
 
111
109
  function sendMessage(message) {
112
110
  if (message.data) {
113
- const data = message.data;
111
+ let { data } = message;
114
112
  if (data && data.length) {
115
113
  try {
116
- message.data = new Uint8Array(data).buffer;
114
+ if (data.length != data.buffer.byteLength) {
115
+ data = new Uint8Array(data);
116
+ }
117
+ message.data = data.buffer;
117
118
  postMessage(message, [message.data]);
118
119
  } catch (_error) {
119
120
  postMessage(message);
@@ -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;
@@ -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";
@@ -184,7 +184,7 @@ async function addFile(zipWriter, name, reader, options) {
184
184
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
185
185
  }
186
186
  let rawExtraField = new Uint8Array(0);
187
- const extraField = options.extraField;
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,
@@ -524,20 +524,26 @@ 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 {
@@ -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;
@@ -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);