@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
@@ -44,7 +44,9 @@ export {
44
44
  getWorker
45
45
  };
46
46
 
47
- function getWorker(workerData, codecConstructor, readable, writable, options, config, streamOptions, onTaskFinished, webWorker, scripts) {
47
+ function getWorker(workerData, stream, workerOptions, onTaskFinished) {
48
+ const { readable, writable } = stream;
49
+ const { options, config, streamOptions, webWorker, scripts, codecConstructor } = workerOptions;
48
50
  Object.assign(workerData, {
49
51
  busy: true,
50
52
  codecConstructor,
@@ -63,36 +65,47 @@ function getWorker(workerData, codecConstructor, readable, writable, options, co
63
65
  onTaskFinished(workerData);
64
66
  }
65
67
  });
66
- const { signal, onprogress, size } = streamOptions;
67
- if (signal || onprogress) {
68
+ const { signal, size, onstart, onprogress, onend } = streamOptions;
69
+ if (signal || onstart || onprogress || onend) {
68
70
  let chunkOffset = 0;
69
71
  const transformer = {};
72
+ if (onstart) {
73
+ transformer.start = () => callHandler(onstart, size());
74
+ }
70
75
  if (onprogress) {
71
- transformer.transform = (chunk, controller) => {
76
+ transformer.transform = async (chunk, controller) => {
72
77
  chunkOffset += chunk.length;
73
- try {
74
- onprogress(chunkOffset, size());
75
- } catch (_error) {
76
- // ignored
77
- }
78
+ await callHandler(onprogress, chunkOffset, size());
78
79
  controller.enqueue(chunk);
79
80
  };
80
81
  }
81
- workerData.readable = readable.pipeThrough(new TransformStream(transformer), { signal });
82
+ if (onend) {
83
+ transformer.flush = () => callHandler(onend);
84
+ }
85
+ workerData.readable = readable.pipeThrough(new TransformStream(transformer, { highWaterMark: 1, size: () => config.chunkSize }), { signal });
82
86
  }
83
87
  return webWorker ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
84
88
  }
85
89
 
90
+ async function callHandler(handler, ...parameters) {
91
+ try {
92
+ await handler(...parameters);
93
+ } catch (_error) {
94
+ // ignored
95
+ }
96
+ }
97
+
86
98
  function createWorkerInterface(workerData, config) {
87
99
  const interfaceCodec = createCodec(workerData.codecConstructor, workerData.readable, workerData.writable, workerData.options, config);
100
+ const { onTaskFinished } = workerData;
88
101
  const codec = {
89
102
  abort() {
90
103
  interfaceCodec.abort();
91
- workerData.onTaskFinished();
104
+ onTaskFinished();
92
105
  },
93
- run() {
94
- const result = interfaceCodec.run();
95
- workerData.onTaskFinished();
106
+ async run() {
107
+ const result = await interfaceCodec.run();
108
+ onTaskFinished();
96
109
  return result;
97
110
  }
98
111
  };
@@ -101,11 +114,14 @@ function createWorkerInterface(workerData, config) {
101
114
 
102
115
  function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
103
116
  const workerOptions = { type: "module" };
104
- workerData.reader = workerData.readable.getReader();
105
- workerData.writer = workerData.writable.getWriter();
106
- workerData.result = new Promise((resolve, reject) => {
107
- workerData.resolveResult = resolve;
108
- workerData.rejectResult = reject;
117
+ const { readable, writable } = workerData;
118
+ Object.assign(workerData, {
119
+ reader: readable.getReader(),
120
+ writer: writable.getWriter(),
121
+ result: new Promise((resolve, reject) => {
122
+ workerData.resolveResult = resolve;
123
+ workerData.rejectResult = reject;
124
+ })
109
125
  });
110
126
  if (!workerData.interface) {
111
127
  if (!classicWorkersSupported) {
@@ -126,7 +142,7 @@ function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
126
142
  workerData.onTaskFinished();
127
143
  },
128
144
  run() {
129
- const options = workerData.options;
145
+ const { options } = workerData;
130
146
  const scripts = workerData.scripts.slice(1);
131
147
  sendMessage({ type: MESSAGE_START, scripts, options, config: { chunkSize } });
132
148
  return workerData.result;
@@ -150,12 +166,13 @@ function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
150
166
  }
151
167
 
152
168
  function sendMessage(message) {
153
- const worker = workerData.worker;
169
+ const { worker, writer, onTaskFinished } = workerData;
154
170
  try {
155
171
  let { data } = message;
156
172
  if (data) {
157
173
  try {
158
- if (data.length != data.buffer.byteLength) {
174
+ const { buffer, length } = data;
175
+ if (length != buffer.byteLength) {
159
176
  data = new Uint8Array(data);
160
177
  }
161
178
  message.data = data.buffer;
@@ -167,43 +184,48 @@ function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
167
184
  worker.postMessage(message);
168
185
  }
169
186
  } catch (error) {
170
- workerData.writer.releaseLock();
171
- workerData.onTaskFinished();
187
+ writer.releaseLock();
188
+ onTaskFinished();
172
189
  throw error;
173
190
  }
174
191
  }
175
192
 
176
193
  async function onMessage(event) {
177
194
  const message = event.data;
195
+ const { reader, writer, resolveResult, rejectResult, onTaskFinished } = workerData;
196
+ const { type, data, messageId, result } = message;
178
197
  const reponseError = message.error;
179
198
  try {
180
199
  if (reponseError) {
181
- const error = new Error(reponseError.message);
182
- error.stack = reponseError.stack;
183
- workerData.rejectResult(error);
184
- workerData.writer.releaseLock();
185
- workerData.onTaskFinished();
200
+ const { message, stack } = reponseError;
201
+ const error = new Error(message);
202
+ error.stack = stack;
203
+ close(error);
186
204
  } else {
187
- if (message.type == MESSAGE_PULL) {
188
- const { value, done } = await workerData.reader.read();
189
- sendMessage({ type: MESSAGE_DATA, data: value, done, messageId: message.messageId });
205
+ if (type == MESSAGE_PULL) {
206
+ const { value, done } = await reader.read();
207
+ sendMessage({ type: MESSAGE_DATA, data: value, done, messageId });
190
208
  }
191
- if (message.type == MESSAGE_DATA) {
192
- let { data } = message;
193
- data = new Uint8Array(data);
194
- await workerData.writer.ready;
195
- await workerData.writer.write(data);
209
+ if (type == MESSAGE_DATA) {
210
+ await writer.ready;
211
+ await writer.write(new Uint8Array(data));
196
212
  }
197
- if (message.type == MESSAGE_CLOSE) {
198
- workerData.resolveResult(message.result);
199
- workerData.writer.releaseLock();
200
- workerData.onTaskFinished();
213
+ if (type == MESSAGE_CLOSE) {
214
+ close(null, result);
201
215
  }
202
216
  }
203
217
  } catch (error) {
204
- workerData.rejectResult(error);
205
- workerData.writer.releaseLock();
206
- workerData.onTaskFinished();
218
+ close(error);
219
+ }
220
+
221
+ function close(error, result) {
222
+ if (error) {
223
+ rejectResult(error);
224
+ } else {
225
+ resolveResult(result);
226
+ }
227
+ writer.releaseLock();
228
+ onTaskFinished();
207
229
  }
208
230
  }
209
231
  }
@@ -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,27 @@ 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] : [];
59
- options.useCompressionStream = options.useCompressionStream === undefined ? config.useCompressionStream : options.useCompressionStream;
58
+ const { useWebWorkers, useCompressionStream, codecType } = options;
59
+ const { workerScripts } = config;
60
+ workerOptions.webWorker = !streamCopy && (useWebWorkers || (useWebWorkers === undefined && config.useWebWorkers));
61
+ workerOptions.scripts = workerOptions.webWorker && workerScripts ? workerScripts[codecType] : [];
62
+ options.useCompressionStream = useCompressionStream === undefined ? config.useCompressionStream : useCompressionStream;
60
63
  let codec;
61
64
  if (pool.length < config.maxWorkers) {
62
65
  const workerData = { indexWorker };
63
66
  indexWorker++;
64
67
  pool.push(workerData);
65
- codec = getWorker(workerData, codecConstructor, readable, writable, options, config, streamOptions, onTaskFinished, webWorker, scripts);
68
+ codec = getWorker(workerData, stream, workerOptions, onTaskFinished);
66
69
  } else {
67
70
  const workerData = pool.find(workerData => !workerData.busy);
68
71
  if (workerData) {
69
72
  clearTerminateTimeout(workerData);
70
- codec = getWorker(workerData, codecConstructor, readable, writable, options, config, streamOptions, onTaskFinished, webWorker, scripts);
73
+ codec = getWorker(workerData, stream, workerOptions, onTaskFinished);
71
74
  } else {
72
- codec = await new Promise(resolve => pendingRequests.push({ resolve, codecConstructor, readable, writable, options, webWorker, scripts }));
75
+ codec = await new Promise(resolve => pendingRequests.push({ resolve, stream, workerOptions }));
73
76
  }
74
77
  }
75
78
  const { signal } = streamOptions;
@@ -86,15 +89,16 @@ async function runCodec(codecConstructor, readable, writable, options, config, s
86
89
 
87
90
  function onTaskFinished(workerData) {
88
91
  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));
92
+ const [{ resolve, stream, workerOptions }] = pendingRequests.splice(0, 1);
93
+ resolve(getWorker(workerData, stream, workerOptions, onTaskFinished));
91
94
  } else if (workerData.worker) {
95
+ const { terminateWorkerTimeout } = config;
92
96
  clearTerminateTimeout(workerData);
93
- if (Number.isFinite(config.terminateWorkerTimeout) && config.terminateWorkerTimeout >= 0) {
97
+ if (Number.isFinite(terminateWorkerTimeout) && terminateWorkerTimeout >= 0) {
94
98
  workerData.terminateTimeout = setTimeout(() => {
95
99
  pool = pool.filter(data => data != workerData);
96
100
  workerData.terminate();
97
- }, config.terminateWorkerTimeout);
101
+ }, terminateWorkerTimeout);
98
102
  }
99
103
  } else {
100
104
  pool = pool.filter(data => data != workerData);
@@ -103,8 +107,9 @@ async function runCodec(codecConstructor, readable, writable, options, config, s
103
107
  }
104
108
 
105
109
  function clearTerminateTimeout(workerData) {
106
- if (workerData.terminateTimeout) {
107
- clearTimeout(workerData.terminateTimeout);
110
+ const { terminateTimeout } = workerData;
111
+ if (terminateTimeout) {
112
+ clearTimeout(terminateTimeout);
108
113
  workerData.terminateTimeout = null;
109
114
  }
110
115
  }
@@ -29,6 +29,7 @@
29
29
  /* global navigator */
30
30
 
31
31
  const MINIMUM_CHUNK_SIZE = 64;
32
+ const UNDEFINED_TYPE = undefined;
32
33
  const DEFAULT_CONFIGURATION = {
33
34
  chunkSize: 512 * 1024,
34
35
  maxWorkers: (typeof navigator != "undefined" && navigator.hardwareConcurrency) || 2,
@@ -54,48 +55,59 @@ function getChunkSize(config) {
54
55
  }
55
56
 
56
57
  function configure(configuration) {
57
- if (configuration.baseURL !== undefined) {
58
- config.baseURL = configuration.baseURL;
58
+ const {
59
+ baseURL,
60
+ chunkSize,
61
+ maxWorkers,
62
+ terminateWorkerTimeout,
63
+ useCompressionStream,
64
+ useWebWorkers,
65
+ Deflate,
66
+ Inflate,
67
+ workerScripts
68
+ } = configuration;
69
+ if (baseURL !== UNDEFINED_TYPE) {
70
+ config.baseURL = baseURL;
59
71
  }
60
- if (configuration.chunkSize !== undefined) {
61
- config.chunkSize = configuration.chunkSize;
72
+ if (chunkSize !== UNDEFINED_TYPE) {
73
+ config.chunkSize = chunkSize;
62
74
  }
63
- if (configuration.maxWorkers !== undefined) {
64
- config.maxWorkers = configuration.maxWorkers;
75
+ if (maxWorkers !== UNDEFINED_TYPE) {
76
+ config.maxWorkers = maxWorkers;
65
77
  }
66
- if (configuration.terminateWorkerTimeout !== undefined) {
67
- config.terminateWorkerTimeout = configuration.terminateWorkerTimeout;
78
+ if (terminateWorkerTimeout !== UNDEFINED_TYPE) {
79
+ config.terminateWorkerTimeout = terminateWorkerTimeout;
68
80
  }
69
- if (configuration.useCompressionStream !== undefined) {
70
- config.useCompressionStream = configuration.useCompressionStream;
81
+ if (useCompressionStream !== UNDEFINED_TYPE) {
82
+ config.useCompressionStream = useCompressionStream;
71
83
  }
72
- if (configuration.useWebWorkers !== undefined) {
73
- config.useWebWorkers = configuration.useWebWorkers;
84
+ if (useWebWorkers !== UNDEFINED_TYPE) {
85
+ config.useWebWorkers = useWebWorkers;
74
86
  }
75
- if (configuration.Deflate !== undefined) {
76
- config.Deflate = configuration.Deflate;
87
+ if (Deflate !== UNDEFINED_TYPE) {
88
+ config.Deflate = Deflate;
77
89
  }
78
- if (configuration.Inflate !== undefined) {
79
- config.Inflate = configuration.Inflate;
90
+ if (Inflate !== UNDEFINED_TYPE) {
91
+ config.Inflate = Inflate;
80
92
  }
81
- if (configuration.workerScripts !== undefined) {
82
- if (configuration.workerScripts.deflate) {
83
- if (!Array.isArray(configuration.workerScripts.deflate)) {
84
- throw new Error("workerScripts.deflate must be an array");
85
- }
93
+ if (workerScripts !== UNDEFINED_TYPE) {
94
+ const { deflate, inflate } = workerScripts;
95
+ if (deflate || inflate) {
86
96
  if (!config.workerScripts) {
87
97
  config.workerScripts = {};
88
98
  }
89
- config.workerScripts.deflate = configuration.workerScripts.deflate;
90
99
  }
91
- if (configuration.workerScripts.inflate) {
92
- if (!Array.isArray(configuration.workerScripts.inflate)) {
93
- throw new Error("workerScripts.inflate must be an array");
100
+ if (deflate) {
101
+ if (!Array.isArray(deflate)) {
102
+ throw new Error("workerScripts.deflate must be an array");
94
103
  }
95
- if (!config.workerScripts) {
96
- config.workerScripts = {};
104
+ config.workerScripts.deflate = deflate;
105
+ }
106
+ if (inflate) {
107
+ if (!Array.isArray(inflate)) {
108
+ throw new Error("workerScripts.inflate must be an array");
97
109
  }
98
- config.workerScripts.inflate = configuration.workerScripts.inflate;
110
+ config.workerScripts.inflate = inflate;
99
111
  }
100
112
  }
101
113
  }
package/lib/core/io.js CHANGED
@@ -26,7 +26,7 @@
26
26
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
- /* global Blob, FileReader, atob, btoa, XMLHttpRequest, document, fetch, ReadableStream, WritableStream, TransformStream */
29
+ /* global Blob, atob, btoa, XMLHttpRequest, document, fetch, ReadableStream, WritableStream, TransformStream */
30
30
 
31
31
  const ERR_HTTP_STATUS = "HTTP error ";
32
32
  const ERR_HTTP_RANGE = "HTTP Range not supported";
@@ -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) {
@@ -127,16 +127,7 @@ class TextWriter extends Writer {
127
127
 
128
128
  getData() {
129
129
  const writer = this;
130
- if (writer.blob.text) {
131
- return writer.blob.text();
132
- } else {
133
- const reader = new FileReader();
134
- return new Promise((resolve, reject) => {
135
- reader.onload = event => resolve(event.target.result);
136
- reader.onerror = () => reject(reader.error);
137
- reader.readAsText(writer.blob, writer.encoding);
138
- });
139
- }
130
+ return writer.blob.text();
140
131
  }
141
132
  }
142
133
 
@@ -210,16 +201,7 @@ class BlobReader extends Reader {
210
201
 
211
202
  async readUint8Array(offset, length) {
212
203
  const reader = this;
213
- if (reader.blob.arrayBuffer) {
214
- return new Uint8Array(await reader.blob.slice(offset, offset + length).arrayBuffer());
215
- } else {
216
- const reader = new FileReader();
217
- return new Promise((resolve, reject) => {
218
- reader.onload = event => resolve(new Uint8Array(event.target.result));
219
- reader.onerror = () => reject(reader.error);
220
- reader.readAsArrayBuffer(reader.blob.slice(offset, offset + length));
221
- });
222
- }
204
+ return new Uint8Array(await reader.blob.slice(offset, offset + length).arrayBuffer());
223
205
  }
224
206
  }
225
207
 
@@ -227,9 +209,10 @@ class BlobWriter extends Writer {
227
209
 
228
210
  constructor(contentType) {
229
211
  super();
230
- this.contentType = contentType;
231
- this.arrayBuffersMaxlength = 8;
232
- initArrayBuffers(this);
212
+ const writer = this;
213
+ writer.contentType = contentType;
214
+ writer.arrayBuffersMaxlength = 8;
215
+ initArrayBuffers(writer);
233
216
  }
234
217
 
235
218
  writeUint8Array(array) {
@@ -266,9 +249,12 @@ function flushArrayBuffers(blobWriter) {
266
249
 
267
250
  class ReadableStreamReader {
268
251
 
269
- constructor(readableStream) {
252
+ constructor(readable) {
270
253
  const reader = this;
271
- reader.readableStream = readableStream.pipeThrough(new TransformStream({
254
+ if (!readable) {
255
+ readable = new ReadableStream({});
256
+ }
257
+ reader.readable = readable.pipeThrough(new TransformStream({
272
258
  transform(chunk, controller) {
273
259
  if (chunk) {
274
260
  reader.size += chunk.length;
@@ -283,33 +269,33 @@ class ReadableStreamReader {
283
269
  this.initialized = true;
284
270
  }
285
271
 
286
- getStream() {
287
- return this.readableStream;
272
+ getReadable() {
273
+ return this.readable;
288
274
  }
289
275
  }
290
276
 
291
277
  class WritableStreamWriter extends Writer {
292
278
 
293
- constructor(writable) {
279
+ constructor(writable, { preventClose } = {}) {
294
280
  super();
295
- const writer = this;
296
- writer.writable = writable;
297
- }
298
-
299
- async writeUint8Array(array) {
300
- await this.writer.ready;
301
- const writer = this.writable.getWriter();
302
- await writer.write(array);
303
- writer.releaseLock();
304
- }
305
-
306
- getStream() {
307
- return this.writable;
281
+ this.preventClose = preventClose;
282
+ if (!writable) {
283
+ writable = new WritableStream({});
284
+ }
285
+ Object.defineProperty(this, "writable", {
286
+ get() {
287
+ return writable;
288
+ }
289
+ });
308
290
  }
309
291
 
310
292
  async getData() {
311
- await this.writable.getWriter().close();
312
- return this.writable;
293
+ const writer = this;
294
+ const { writable } = writer;
295
+ if (!writer.preventClose) {
296
+ await writable.getWriter().close();
297
+ }
298
+ return writable;
313
299
  }
314
300
  }
315
301
 
@@ -322,11 +308,11 @@ class FetchReader extends Reader {
322
308
  reader.preventHeadRequest = options.preventHeadRequest;
323
309
  reader.useRangeHeader = options.useRangeHeader;
324
310
  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;
311
+ reader.options = options = Object.assign({}, options);
312
+ delete options.preventHeadRequest;
313
+ delete options.useRangeHeader;
314
+ delete options.forceRangeRequests;
315
+ delete options.useXHR;
330
316
  }
331
317
 
332
318
  async init() {
@@ -494,12 +480,9 @@ class HttpReader extends Reader {
494
480
 
495
481
  constructor(url, options = {}) {
496
482
  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
- }
483
+ const reader = this;
484
+ reader.url = url;
485
+ reader.reader = options.useXHR ? new XHRReader(url, options) : new FetchReader(url, options);
503
486
  }
504
487
 
505
488
  set size(value) {
@@ -546,7 +529,7 @@ class Uint8ArrayWriter extends Writer {
546
529
 
547
530
  constructor() {
548
531
  super();
549
- this.array = new Uint8Array(0);
532
+ this.array = new Uint8Array();
550
533
  }
551
534
 
552
535
  writeUint8Array(array) {
@@ -590,4 +573,4 @@ export {
590
573
  WritableStreamWriter,
591
574
  ERR_HTTP_RANGE,
592
575
  ERR_NOT_SEEKABLE_READER
593
- };
576
+ };
@@ -74,7 +74,7 @@ class AESDecryptionStream extends TransformStream {
74
74
  password,
75
75
  signed,
76
76
  strength: strength - 1,
77
- pending: new Uint8Array(0)
77
+ pending: new Uint8Array()
78
78
  });
79
79
  },
80
80
  async transform(chunk, controller) {
@@ -100,7 +100,7 @@ class AESDecryptionStream extends TransformStream {
100
100
  const pending = aesCrypto.pending;
101
101
  const chunkToDecrypt = subarray(pending, 0, pending.length - SIGNATURE_LENGTH);
102
102
  const originalSignature = subarray(pending, pending.length - SIGNATURE_LENGTH);
103
- let decryptedChunkArray = new Uint8Array(0);
103
+ let decryptedChunkArray = new Uint8Array();
104
104
  if (chunkToDecrypt.length) {
105
105
  const encryptedChunk = toBits(codecBytes, chunkToDecrypt);
106
106
  aesCrypto.hmac.update(encryptedChunk);
@@ -133,12 +133,12 @@ class AESEncryptionStream extends TransformStream {
133
133
  ready: new Promise(resolve => this.resolveReady = resolve),
134
134
  password,
135
135
  strength: strength - 1,
136
- pending: new Uint8Array(0)
136
+ pending: new Uint8Array()
137
137
  });
138
138
  },
139
139
  async transform(chunk, controller) {
140
140
  const aesCrypto = this;
141
- let preamble = new Uint8Array(0);
141
+ let preamble = new Uint8Array();
142
142
  if (aesCrypto.password) {
143
143
  const password = aesCrypto.password;
144
144
  aesCrypto.password = null;
@@ -156,7 +156,7 @@ class AESEncryptionStream extends TransformStream {
156
156
  async flush(controller) {
157
157
  const aesCrypto = this;
158
158
  await aesCrypto.ready;
159
- let encryptedChunkArray = new Uint8Array(0);
159
+ let encryptedChunkArray = new Uint8Array();
160
160
  if (aesCrypto.pending.length) {
161
161
  const encryptedChunk = aesCrypto.ctr.update(toBits(codecBytes, aesCrypto.pending));
162
162
  aesCrypto.hmac.update(encryptedChunk);
@@ -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
 
@@ -2029,7 +2029,7 @@ const ZipDeflate = (() => {
2029
2029
  bufferIndex += chunk.length;
2030
2030
  });
2031
2031
  } else {
2032
- array = buffers[0] || new Uint8Array(0);
2032
+ array = buffers[0] || new Uint8Array();
2033
2033
  }
2034
2034
  return array;
2035
2035
  };