@zip.js/zip.js 2.6.18 → 2.6.21

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 (140) hide show
  1. package/.eslintrc.json +0 -0
  2. package/README.md +0 -0
  3. package/cli-deno/mc-zip.js +0 -0
  4. package/dist/README.md +0 -0
  5. package/dist/z-worker-fflate.js +1 -1
  6. package/dist/z-worker-pako.js +1 -1
  7. package/dist/z-worker.js +1 -1
  8. package/dist/zip-fs-full.js +264 -153
  9. package/dist/zip-fs-full.min.js +1 -1
  10. package/dist/zip-fs.js +264 -153
  11. package/dist/zip-fs.min.js +1 -1
  12. package/dist/zip-full.js +259 -153
  13. package/dist/zip-full.min.js +1 -1
  14. package/dist/zip-no-worker-deflate.min.js +1 -1
  15. package/dist/zip-no-worker-inflate.min.js +1 -1
  16. package/dist/zip-no-worker.min.js +1 -1
  17. package/dist/zip.js +259 -153
  18. package/dist/zip.min.js +1 -1
  19. package/index-fflate.js +0 -0
  20. package/index.d.ts +11 -18
  21. package/index.js +0 -0
  22. package/lib/core/codec-interface.js +14 -1
  23. package/lib/core/codec-pool-worker.js +3 -0
  24. package/lib/core/codec-pool.js +0 -0
  25. package/lib/core/configuration.js +0 -0
  26. package/lib/core/constants.js +0 -0
  27. package/lib/core/io.js +11 -19
  28. package/lib/core/streams/aes-crypto-stream.js +0 -0
  29. package/lib/core/streams/codec-stream.js +0 -0
  30. package/lib/core/streams/codecs/crc32.js +0 -0
  31. package/lib/core/streams/codecs/deflate.js +0 -0
  32. package/lib/core/streams/codecs/inflate.js +0 -0
  33. package/lib/core/streams/codecs/sjcl.js +0 -0
  34. package/lib/core/streams/common-crypto.js +0 -0
  35. package/lib/core/streams/crc32-stream.js +0 -0
  36. package/lib/core/streams/zip-crypto-stream.js +0 -0
  37. package/lib/core/streams/zip-entry-stream.js +1 -9
  38. package/lib/core/util/cp437-decode.js +0 -0
  39. package/lib/core/util/decode-text.js +0 -0
  40. package/lib/core/util/default-mime-type.js +0 -0
  41. package/lib/core/util/encode-text.js +0 -0
  42. package/lib/core/util/mime-type.js +0 -0
  43. package/lib/core/util/stream-codec-shim.js +0 -0
  44. package/lib/core/z-worker-core.js +18 -7
  45. package/lib/core/zip-entry.js +0 -0
  46. package/lib/core/zip-fs-core.js +5 -0
  47. package/lib/core/zip-reader.js +1 -0
  48. package/lib/core/zip-writer.js +231 -123
  49. package/lib/z-worker-bootstrap-fflate.js +0 -0
  50. package/lib/z-worker-bootstrap-pako.js +0 -0
  51. package/lib/z-worker-fflate.js +0 -0
  52. package/lib/z-worker-inline-template-base64.js +0 -0
  53. package/lib/z-worker-inline-template.js +0 -0
  54. package/lib/z-worker-inline.js +1 -1
  55. package/lib/z-worker.js +0 -0
  56. package/lib/zip-fflate-shim.js +0 -0
  57. package/lib/zip-fs.js +0 -0
  58. package/lib/zip-full-fflate.js +0 -0
  59. package/lib/zip-full.js +0 -0
  60. package/lib/zip-no-worker-deflate.js +0 -0
  61. package/lib/zip-no-worker-fflate-deflate.js +0 -0
  62. package/lib/zip-no-worker-fflate-inflate.js +0 -0
  63. package/lib/zip-no-worker-fflate.js +0 -0
  64. package/lib/zip-no-worker-inflate.js +0 -0
  65. package/lib/zip-no-worker.js +0 -0
  66. package/lib/zip.js +0 -0
  67. package/package.json +1 -1
  68. package/rollup-fflate.config.dev.js +0 -0
  69. package/rollup-fflate.config.js +0 -0
  70. package/rollup.config.dev.js +0 -0
  71. package/rollup.config.js +0 -0
  72. package/tests/all/loader.html +0 -0
  73. package/tests/all/test-abort-signal-read.js +0 -0
  74. package/tests/all/test-abort-signal-write.js +0 -0
  75. package/tests/all/test-array.js +0 -0
  76. package/tests/all/test-base64.js +0 -0
  77. package/tests/all/test-blob.js +0 -0
  78. package/tests/all/test-codecs-interoperability.js +0 -0
  79. package/tests/all/test-crc.js +0 -0
  80. package/tests/all/test-crypto.js +0 -0
  81. package/tests/all/test-custom-io.js +0 -1
  82. package/tests/all/test-data-descriptor-signature.js +0 -0
  83. package/tests/all/test-data-descriptor.js +0 -0
  84. package/tests/all/test-duplicated-filename.js +0 -0
  85. package/tests/all/test-empty.js +0 -0
  86. package/tests/all/test-extended-timestamp.js +0 -0
  87. package/tests/all/test-extra-field.js +0 -0
  88. package/tests/all/test-fflate-no-worker.js +0 -0
  89. package/tests/all/test-fflate.js +0 -0
  90. package/tests/all/test-fs-base64.js +0 -0
  91. package/tests/all/test-fs-export-options.js +0 -0
  92. package/tests/all/test-fs-http-import.js +0 -0
  93. package/tests/all/test-fs-http-reader.js +0 -0
  94. package/tests/all/test-fs-replace.js +0 -0
  95. package/tests/all/test-fs-streams.js +0 -0
  96. package/tests/all/test-fs-text.js +0 -0
  97. package/tests/all/test-fs-unzip-store.js +0 -0
  98. package/tests/all/test-fs.js +0 -0
  99. package/tests/all/test-http-crypto.js +0 -0
  100. package/tests/all/test-http-range.js +0 -0
  101. package/tests/all/test-http-zip64.js +0 -0
  102. package/tests/all/test-invalid-crc.js +0 -0
  103. package/tests/all/test-multiple-writers.js +0 -0
  104. package/tests/all/test-no-worker.js +0 -0
  105. package/tests/all/test-pako-no-worker.js +0 -0
  106. package/tests/all/test-pako.js +0 -0
  107. package/tests/all/test-parallel-reads.js +0 -0
  108. package/tests/all/test-parallel-writes-auto-buffered.js +0 -0
  109. package/tests/all/test-parallel-writes-ordered.js +0 -0
  110. package/tests/all/test-parallel-writes.js +0 -0
  111. package/tests/all/test-readable-stream.js +0 -0
  112. package/tests/all/test-readable-zip-stream.js +0 -0
  113. package/tests/all/test-safe-closing.js +0 -0
  114. package/tests/all/test-store.js +0 -0
  115. package/tests/all/test-sw-worker.js +0 -0
  116. package/tests/all/test-sw.js +0 -0
  117. package/tests/all/test-worker-timeout.js +0 -0
  118. package/tests/all/test-wrapped.js +2 -2
  119. package/tests/all/test-writable-stream.js +0 -0
  120. package/tests/all/test-zip64-auto.js +3 -2
  121. package/tests/all/test-zip64-crypto.js +0 -0
  122. package/tests/all/test-zip64.js +0 -0
  123. package/tests/all/test-zipcrypto.js +0 -0
  124. package/tests/data/lorem-encrypted.zip +0 -0
  125. package/tests/data/lorem-invalid-crc.zip +0 -0
  126. package/tests/data/lorem-store.zip +0 -0
  127. package/tests/data/lorem-zip64.zip +0 -0
  128. package/tests/data/lorem.txt +0 -0
  129. package/tests/data/lorem.zip +0 -0
  130. package/tests/deno-runner.js +0 -0
  131. package/tests/index.html +0 -0
  132. package/tests/node-runner.js +0 -0
  133. package/tests/tests-data.js +0 -0
  134. package/tests/vendor/fflate-es2019.min.js +0 -0
  135. package/tests/vendor/fflate.min.js +0 -0
  136. package/tests/vendor/pako.min.js +0 -0
  137. package/tests/vendor/pako_deflate.min.js +0 -0
  138. package/tests/vendor/pako_inflate.min.js +0 -0
  139. package/tests/web-runner.js +0 -0
  140. package/tsconfig.json +0 -0
@@ -27,6 +27,7 @@
27
27
  */
28
28
 
29
29
  // deno-lint-ignore-file no-this-alias
30
+ /* global TransformStream */
30
31
 
31
32
  import {
32
33
  InflateStream,
@@ -41,6 +42,7 @@ const MESSAGE_EVENT_TYPE = "message";
41
42
  const MESSAGE_START = "start";
42
43
  const MESSAGE_PULL = "pull";
43
44
  const MESSAGE_DATA = "data";
45
+ const MESSAGE_ACK_DATA = "ack";
44
46
  const MESSAGE_CLOSE = "close";
45
47
 
46
48
  export {
@@ -53,6 +55,7 @@ export {
53
55
  MESSAGE_START,
54
56
  MESSAGE_PULL,
55
57
  MESSAGE_DATA,
58
+ MESSAGE_ACK_DATA,
56
59
  MESSAGE_CLOSE
57
60
  };
58
61
 
@@ -68,7 +71,17 @@ class Codec {
68
71
 
69
72
  async function run(StreamConstructor) {
70
73
  const stream = new StreamConstructor(codecConstructor, options, config);
71
- await readable.pipeThrough(stream).pipeTo(writable, { preventClose: true, preventAbort: true });
74
+ await readable
75
+ .pipeThrough(stream)
76
+ .pipeThrough(new TransformStream({
77
+ transform(chunk, controller) {
78
+ if (chunk && chunk.length) {
79
+ writable.size += chunk.length;
80
+ controller.enqueue(chunk);
81
+ }
82
+ }
83
+ }))
84
+ .pipeTo(writable, { preventClose: true, preventAbort: true });
72
85
  const { size, signature } = stream;
73
86
  return { size, signature };
74
87
  }
@@ -34,6 +34,7 @@ import {
34
34
  MESSAGE_START,
35
35
  MESSAGE_PULL,
36
36
  MESSAGE_DATA,
37
+ MESSAGE_ACK_DATA,
37
38
  MESSAGE_CLOSE
38
39
  } from "./codec-interface.js";
39
40
 
@@ -208,7 +209,9 @@ function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
208
209
  }
209
210
  if (type == MESSAGE_DATA) {
210
211
  await writer.ready;
212
+ workerData.writable.size += data.byteLength;
211
213
  await writer.write(new Uint8Array(data));
214
+ sendMessage({ type: MESSAGE_ACK_DATA, messageId });
212
215
  }
213
216
  if (type == MESSAGE_CLOSE) {
214
217
  close(null, result);
File without changes
File without changes
File without changes
package/lib/core/io.js CHANGED
@@ -78,7 +78,7 @@ class Reader extends Stream {
78
78
  }
79
79
  }
80
80
 
81
- class WriterStream extends Stream {
81
+ class Writer extends Stream {
82
82
 
83
83
  constructor() {
84
84
  super();
@@ -88,18 +88,15 @@ class WriterStream extends Stream {
88
88
  return writer.writeUint8Array(chunk);
89
89
  }
90
90
  });
91
- Object.defineProperty(this, "writable", {
91
+ Object.defineProperty(writer, "writable", {
92
92
  get() {
93
93
  return writable;
94
94
  }
95
95
  });
96
96
  }
97
- }
98
97
 
99
- class Writer extends WriterStream {
100
-
101
- writeUint8Array(array) {
102
- this.size += array.length;
98
+ writeUint8Array() {
99
+ // abstract
103
100
  }
104
101
  }
105
102
 
@@ -131,7 +128,6 @@ class TextWriter extends Writer {
131
128
  }
132
129
 
133
130
  writeUint8Array(array) {
134
- super.writeUint8Array(array);
135
131
  this.blob = new Blob([this.blob, array.buffer], { type: CONTENT_TYPE_TEXT_PLAIN });
136
132
  }
137
133
 
@@ -186,7 +182,6 @@ class Data64URIWriter extends Writer {
186
182
  }
187
183
 
188
184
  writeUint8Array(array) {
189
- super.writeUint8Array(array);
190
185
  const writer = this;
191
186
  let indexArray = 0;
192
187
  let dataString = writer.pending;
@@ -230,12 +225,7 @@ class BlobWriter extends Stream {
230
225
  super();
231
226
  const writer = this;
232
227
  writer.contentType = contentType;
233
- writer.transformStream = new TransformStream({
234
- transform(chunk, controller) {
235
- writer.size += chunk.length;
236
- controller.enqueue(chunk);
237
- }
238
- });
228
+ writer.transformStream = new TransformStream();
239
229
  Object.defineProperty(this, "writable", {
240
230
  get() {
241
231
  return writer.transformStream.writable;
@@ -488,18 +478,20 @@ class Uint8ArrayWriter extends Writer {
488
478
 
489
479
  init(initSize = 0) {
490
480
  super.init();
491
- this.array = new Uint8Array(initSize);
481
+ const writer = this;
482
+ writer.offset = 0;
483
+ writer.array = new Uint8Array(initSize);
492
484
  }
493
485
 
494
486
  writeUint8Array(array) {
495
487
  const writer = this;
496
- if (writer.size + array.length > writer.array.length) {
488
+ if (writer.offset + array.length > writer.array.length) {
497
489
  const previousArray = writer.array;
498
490
  writer.array = new Uint8Array(previousArray.length + array.length);
499
491
  writer.array.set(previousArray);
500
492
  }
501
- writer.array.set(array, writer.size);
502
- super.writeUint8Array(array);
493
+ writer.array.set(array, writer.offset);
494
+ writer.offset += array.length;
503
495
  }
504
496
 
505
497
  getData() {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -167,15 +167,7 @@ function filterEmptyChunks(readable) {
167
167
  }
168
168
 
169
169
  function setReadable(stream, readable, flush) {
170
- stream.size = 0;
171
- readable = readable.pipeThrough(new TransformStream({
172
- transform(chunk, controller) {
173
- if (chunk && chunk.length) {
174
- stream.size += chunk.length;
175
- controller.enqueue(chunk);
176
- }
177
- }, flush
178
- }));
170
+ readable = readable.pipeThrough(new TransformStream({ flush }));
179
171
  Object.defineProperty(stream, "readable", {
180
172
  get() {
181
173
  return readable;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -36,10 +36,12 @@ import {
36
36
  MESSAGE_START,
37
37
  MESSAGE_PULL,
38
38
  MESSAGE_DATA,
39
+ MESSAGE_ACK_DATA,
39
40
  MESSAGE_CLOSE
40
41
  } from "./codec-interface.js";
41
42
 
42
- const pendingMessages = new Map();
43
+ const pendingPullMessages = new Map();
44
+ const pendingDataMessages = new Map();
43
45
  let codec;
44
46
  let messageId = 0;
45
47
 
@@ -51,10 +53,15 @@ addEventListener(MESSAGE_EVENT_TYPE, async event => {
51
53
  init(message);
52
54
  }
53
55
  if (type == MESSAGE_DATA) {
54
- const { resolve } = pendingMessages.get(messageId);
55
- pendingMessages.delete(messageId);
56
+ const resolve = pendingPullMessages.get(messageId);
57
+ pendingPullMessages.delete(messageId);
56
58
  resolve({ value: new Uint8Array(data), done });
57
59
  }
60
+ if (type == MESSAGE_ACK_DATA) {
61
+ const resolve = pendingDataMessages.get(messageId);
62
+ pendingDataMessages.delete(messageId);
63
+ resolve();
64
+ }
58
65
  } catch (error) {
59
66
  postMessage({ error: { message: error.message, stack: error.stack } });
60
67
  }
@@ -79,7 +86,7 @@ async function init(message) {
79
86
  const strategy = { highWaterMark: 1, size: () => config.chunkSize };
80
87
  const readable = new ReadableStream({
81
88
  async pull(controller) {
82
- let result = new Promise((resolve, reject) => pendingMessages.set(messageId, { resolve, reject }));
89
+ let result = new Promise(resolve => pendingPullMessages.set(messageId, resolve));
83
90
  sendMessage({ type: MESSAGE_PULL, messageId });
84
91
  messageId = (messageId + 1) % Number.MAX_SAFE_INTEGER;
85
92
  const { value, done } = await result;
@@ -90,14 +97,18 @@ async function init(message) {
90
97
  }
91
98
  }, strategy);
92
99
  const writable = new WritableStream({
93
- write(data) {
94
- sendMessage({ type: MESSAGE_DATA, data });
100
+ async write(data) {
101
+ let resolveAckData;
102
+ const ackData = new Promise(resolve => resolveAckData = resolve);
103
+ pendingDataMessages.set(messageId, resolveAckData);
104
+ sendMessage({ type: MESSAGE_DATA, data, messageId });
105
+ messageId = (messageId + 1) % Number.MAX_SAFE_INTEGER;
106
+ await ackData;
95
107
  }
96
108
  }, strategy);
97
109
  codec = new Codec(codecConstructor, readable, writable, options, config);
98
110
  const result = await codec.run();
99
111
  sendMessage({ type: MESSAGE_CLOSE, result });
100
-
101
112
  } catch (error) {
102
113
  const { message, stack } = error;
103
114
  postMessage({ error: { message, stack } });
File without changes
@@ -437,6 +437,11 @@ class FS {
437
437
  await this.root.importData64URI(dataURI, options);
438
438
  }
439
439
 
440
+ async importUint8Array(array, options) {
441
+ resetFS(this);
442
+ await this.root.importUint8Array(array, options);
443
+ }
444
+
440
445
  async importHttpContent(url, options) {
441
446
  resetFS(this);
442
447
  await this.root.importHttpContent(url, options);
@@ -322,6 +322,7 @@ class ZipEntry {
322
322
  readable.offset = dataOffset;
323
323
  readable.size = size;
324
324
  const { writable } = writer;
325
+ writable.size = 0;
325
326
  const signal = getOptionValue(zipEntry, options, "signal");
326
327
  await initStream(writer, uncompressedSize);
327
328
  const { onstart, onprogress, onend } = options;