@zip.js/zip.js 2.8.18 → 2.8.20

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.
@@ -243,23 +243,8 @@ async function runWebWorker(workerData, config) {
243
243
  }
244
244
 
245
245
  function watchClosedStream(writableSource) {
246
- let resolveStreamClosed;
247
- const closed = new Promise(resolve => resolveStreamClosed = resolve);
248
- const writable = new WritableStream({
249
- async write(chunk) {
250
- const writer = writableSource.getWriter();
251
- await writer.ready;
252
- await writer.write(chunk);
253
- writer.releaseLock();
254
- },
255
- close() {
256
- resolveStreamClosed();
257
- },
258
- abort(reason) {
259
- const writer = writableSource.getWriter();
260
- return writer.abort(reason);
261
- }
262
- });
246
+ const { writable, readable } = new TransformStream();
247
+ const closed = readable.pipeTo(writableSource, { preventClose: true });
263
248
  return { writable, closed };
264
249
  }
265
250
 
@@ -96,6 +96,7 @@ const MAX_DATE = new Date(2107, 11, 31);
96
96
  const MIN_DATE = new Date(1980, 0, 1);
97
97
 
98
98
  const UNDEFINED_VALUE = undefined;
99
+ const INFINITY_VALUE = Infinity;
99
100
  const UNDEFINED_TYPE = "undefined";
100
101
  const FUNCTION_TYPE = "function";
101
102
  const OBJECT_TYPE = "object";
@@ -162,6 +163,7 @@ export {
162
163
  MIN_DATE,
163
164
  MAX_DATE,
164
165
  UNDEFINED_VALUE,
166
+ INFINITY_VALUE,
165
167
  UNDEFINED_TYPE,
166
168
  FUNCTION_TYPE,
167
169
  OBJECT_TYPE
package/lib/core/io.js CHANGED
@@ -31,6 +31,7 @@
31
31
 
32
32
  import {
33
33
  UNDEFINED_VALUE,
34
+ INFINITY_VALUE,
34
35
  FUNCTION_TYPE,
35
36
  END_OF_CENTRAL_DIR_LENGTH
36
37
  } from "./constants.js";
@@ -745,8 +746,8 @@ class GenericWriter {
745
746
  Object.assign(writer, {
746
747
  diskNumber: 0,
747
748
  diskOffset: 0,
748
- availableSize: Infinity,
749
- maxSize: Infinity
749
+ availableSize: INFINITY_VALUE,
750
+ maxSize: INFINITY_VALUE
750
751
  });
751
752
  }
752
753
  return writer;
@@ -87,6 +87,7 @@ import {
87
87
  MIN_DATE,
88
88
  MAX_DATE,
89
89
  UNDEFINED_VALUE,
90
+ INFINITY_VALUE,
90
91
  OBJECT_TYPE
91
92
  } from "./constants.js";
92
93
  import {
@@ -139,12 +140,14 @@ import {
139
140
  OPTION_SIGNAL,
140
141
  OPTION_USE_WEB_WORKERS,
141
142
  OPTION_USE_COMPRESSION_STREAM,
143
+ OPTION_TRANSFER_STREAMS,
142
144
  OPTION_PREVENT_CLOSE,
143
145
  OPTION_ENCRYPTION_STRENGTH,
144
146
  OPTION_EXTENDED_TIMESTAMP,
145
147
  OPTION_KEEP_ORDER,
146
148
  OPTION_LEVEL,
147
149
  OPTION_BUFFERED_WRITE,
150
+ OPTION_CREATE_TEMP_STREAM,
148
151
  OPTION_DATA_DESCRIPTOR_SIGNATURE,
149
152
  OPTION_USE_UNICODE_FILE_NAMES,
150
153
  OPTION_DATA_DESCRIPTOR,
@@ -188,8 +191,8 @@ class ZipWriter {
188
191
  constructor(writer, options = {}) {
189
192
  writer = new GenericWriter(writer);
190
193
  const addSplitZipSignature =
191
- writer.availableSize !== UNDEFINED_VALUE && writer.availableSize > 0 && writer.availableSize !== Infinity &&
192
- writer.maxSize !== UNDEFINED_VALUE && writer.maxSize > 0 && writer.maxSize !== Infinity;
194
+ writer.availableSize !== UNDEFINED_VALUE && writer.availableSize > 0 && writer.availableSize !== INFINITY_VALUE &&
195
+ writer.maxSize !== UNDEFINED_VALUE && writer.maxSize > 0 && writer.maxSize !== INFINITY_VALUE;
193
196
  Object.assign(this, {
194
197
  writer,
195
198
  addSplitZipSignature,
@@ -523,7 +526,9 @@ async function addFile(zipWriter, name, reader, options) {
523
526
  const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
524
527
  const keepOrder = getOptionValue(zipWriter, options, OPTION_KEEP_ORDER, true);
525
528
  const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
529
+ const transferStreams = getOptionValue(zipWriter, options, OPTION_TRANSFER_STREAMS, true);
526
530
  const bufferedWrite = getOptionValue(zipWriter, options, OPTION_BUFFERED_WRITE);
531
+ const createTempStream = getOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
527
532
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, false);
528
533
  const signal = getOptionValue(zipWriter, options, OPTION_SIGNAL);
529
534
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
@@ -629,10 +634,12 @@ async function addFile(zipWriter, name, reader, options) {
629
634
  rawPassword,
630
635
  level,
631
636
  useWebWorkers,
637
+ transferStreams,
632
638
  encryptionStrength,
633
639
  extendedTimestamp,
634
640
  zipCrypto,
635
641
  bufferedWrite,
642
+ createTempStream,
636
643
  keepOrder,
637
644
  useUnicodeFileNames,
638
645
  dataDescriptor,
@@ -709,7 +716,11 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
709
716
  requestLockCurrentFileEntry();
710
717
  }
711
718
  if ((options.bufferedWrite || zipWriter.writerLocked || (zipWriter.bufferedWrites && keepOrder) || !dataDescriptor) && !usdz) {
712
- fileWriter = new TransformStream(undefined, undefined, { highWaterMark: Infinity });
719
+ if (options.createTempStream) {
720
+ fileWriter = await options.createTempStream();
721
+ } else {
722
+ fileWriter = new TransformStream(UNDEFINED_VALUE, UNDEFINED_VALUE, { highWaterMark: INFINITY_VALUE });
723
+ }
713
724
  fileWriter.size = 0;
714
725
  bufferedWrite = true;
715
726
  zipWriter.bufferedWrites++;
@@ -874,6 +885,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
874
885
  rawComment,
875
886
  rawExtraField,
876
887
  useWebWorkers,
888
+ transferStreams,
877
889
  onstart,
878
890
  onprogress,
879
891
  onend,
@@ -954,7 +966,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
954
966
  encrypted: encrypted && !passThrough,
955
967
  useWebWorkers,
956
968
  useCompressionStream,
957
- transferStreams: false
969
+ transferStreams
958
970
  },
959
971
  config,
960
972
  streamOptions: { signal, size, onstart, onprogress, onend }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A JavaScript library to zip and unzip files in the browser, Deno and Node.js",
4
4
  "author": "Gildas Lormeau",
5
5
  "license": "BSD-3-Clause",
6
- "version": "2.8.18",
6
+ "version": "2.8.20",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",
@@ -161,8 +161,5 @@
161
161
  "rollup": "^4.57.1",
162
162
  "typedoc": "^0.28.16",
163
163
  "typedoc-plugin-markdown": "^4.10.0"
164
- },
165
- "dependencies": {
166
- "web-worker": "^1.5.0"
167
164
  }
168
165
  }