@zip.js/zip.js 2.7.34 → 2.7.36

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.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  zip.js is a JavaScript open-source library (BSD-3-Clause license) for
4
4
  compressing and decompressing zip files. It has been designed to handle large amounts
5
5
  of data. It supports notably multi-core compression, native compression with
6
- compression streams, files larger than 4GB with Zip64, split zip files and data
6
+ compression streams, archives larger than 4GB with Zip64, split zip files and data
7
7
  encryption.
8
8
 
9
9
  # Demo
package/deno.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@zip-js/zip-js",
3
+ "version": "2.7.35",
4
+ "exports": "./index.js"
5
+ }
@@ -8923,8 +8923,8 @@
8923
8923
 
8924
8924
  constructor(writerGenerator, maxSize = 4294967295) {
8925
8925
  super();
8926
- const zipWriter = this;
8927
- Object.assign(zipWriter, {
8926
+ const writer = this;
8927
+ Object.assign(writer, {
8928
8928
  diskNumber: 0,
8929
8929
  diskOffset: 0,
8930
8930
  size: 0,
@@ -8934,7 +8934,7 @@
8934
8934
  let diskSourceWriter, diskWritable, diskWriter;
8935
8935
  const writable = new WritableStream({
8936
8936
  async write(chunk) {
8937
- const { availableSize } = zipWriter;
8937
+ const { availableSize } = writer;
8938
8938
  if (!diskWriter) {
8939
8939
  const { value, done } = await writerGenerator.next();
8940
8940
  if (done && !value) {
@@ -8943,9 +8943,9 @@
8943
8943
  diskSourceWriter = value;
8944
8944
  diskSourceWriter.size = 0;
8945
8945
  if (diskSourceWriter.maxSize) {
8946
- zipWriter.maxSize = diskSourceWriter.maxSize;
8946
+ writer.maxSize = diskSourceWriter.maxSize;
8947
8947
  }
8948
- zipWriter.availableSize = zipWriter.maxSize;
8948
+ writer.availableSize = writer.maxSize;
8949
8949
  await initStream(diskSourceWriter);
8950
8950
  diskWritable = value.writable;
8951
8951
  diskWriter = diskWritable.getWriter();
@@ -8954,8 +8954,8 @@
8954
8954
  } else if (chunk.length >= availableSize) {
8955
8955
  await writeChunk(chunk.slice(0, availableSize));
8956
8956
  await closeDisk();
8957
- zipWriter.diskOffset += diskSourceWriter.size;
8958
- zipWriter.diskNumber++;
8957
+ writer.diskOffset += diskSourceWriter.size;
8958
+ writer.diskNumber++;
8959
8959
  diskWriter = null;
8960
8960
  await this.write(chunk.slice(availableSize));
8961
8961
  } else {
@@ -8967,7 +8967,7 @@
8967
8967
  await closeDisk();
8968
8968
  }
8969
8969
  });
8970
- Object.defineProperty(zipWriter, PROPERTY_NAME_WRITABLE, {
8970
+ Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
8971
8971
  get() {
8972
8972
  return writable;
8973
8973
  }
@@ -8979,8 +8979,8 @@
8979
8979
  await diskWriter.ready;
8980
8980
  await diskWriter.write(chunk);
8981
8981
  diskSourceWriter.size += chunkLength;
8982
- zipWriter.size += chunkLength;
8983
- zipWriter.availableSize -= chunkLength;
8982
+ writer.size += chunkLength;
8983
+ writer.availableSize -= chunkLength;
8984
8984
  }
8985
8985
  }
8986
8986
 
@@ -9000,6 +9000,8 @@
9000
9000
  async function initStream(stream, initSize) {
9001
9001
  if (stream.init && !stream.initialized) {
9002
9002
  await stream.init(initSize);
9003
+ } else {
9004
+ return Promise.resolve();
9003
9005
  }
9004
9006
  }
9005
9007
 
@@ -9201,8 +9203,8 @@
9201
9203
  1. Redistributions of source code must retain the above copyright notice,
9202
9204
  this list of conditions and the following disclaimer.
9203
9205
 
9204
- 2. Redistributions in binary form must reproduce the above copyright
9205
- notice, this list of conditions and the following disclaimer in
9206
+ 2. Redistributions in binary form must reproduce the above copyright
9207
+ notice, this list of conditions and the following disclaimer in
9206
9208
  the documentation and/or other materials provided with the distribution.
9207
9209
 
9208
9210
  3. The names of the authors may not be used to endorse or promote products
@@ -9331,7 +9333,7 @@
9331
9333
  }
9332
9334
  if (directoryDataOffset >= reader.size) {
9333
9335
  prependedDataLength = reader.size - directoryDataOffset - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
9334
- directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
9336
+ directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
9335
9337
  }
9336
9338
  if (expectedLastDiskNumber != lastDiskNumber) {
9337
9339
  throw new Error(ERR_SPLIT_ZIP_FILE);
@@ -9448,6 +9450,34 @@
9448
9450
  }
9449
9451
  }
9450
9452
 
9453
+ class ZipReaderStream {
9454
+
9455
+ constructor(options = {}) {
9456
+ const { readable, writable } = new TransformStream();
9457
+ const gen = new ZipReader(readable, options).getEntriesGenerator();
9458
+ this.readable = new ReadableStream({
9459
+ async pull(controller) {
9460
+ const { done, value } = await gen.next();
9461
+ if (done)
9462
+ return controller.close();
9463
+ const chunk = {
9464
+ ...value,
9465
+ readable: (function () {
9466
+ const { readable, writable } = new TransformStream();
9467
+ if (value.getData) {
9468
+ value.getData(writable);
9469
+ return readable;
9470
+ }
9471
+ })()
9472
+ };
9473
+ delete chunk.getData;
9474
+ controller.enqueue(chunk);
9475
+ }
9476
+ });
9477
+ this.writable = writable;
9478
+ }
9479
+ }
9480
+
9451
9481
  class ZipEntry$1 {
9452
9482
 
9453
9483
  constructor(reader, config, options) {
@@ -9837,8 +9867,8 @@
9837
9867
  1. Redistributions of source code must retain the above copyright notice,
9838
9868
  this list of conditions and the following disclaimer.
9839
9869
 
9840
- 2. Redistributions in binary form must reproduce the above copyright
9841
- notice, this list of conditions and the following disclaimer in
9870
+ 2. Redistributions in binary form must reproduce the above copyright
9871
+ notice, this list of conditions and the following disclaimer in
9842
9872
  the documentation and/or other materials provided with the distribution.
9843
9873
 
9844
9874
  3. The names of the authors may not be used to endorse or promote products
@@ -9875,9 +9905,12 @@
9875
9905
 
9876
9906
  constructor(writer, options = {}) {
9877
9907
  writer = initWriter(writer);
9908
+ const addSplitZipSignature =
9909
+ writer.availableSize !== UNDEFINED_VALUE && writer.availableSize > 0 && writer.availableSize !== Infinity &&
9910
+ writer.maxSize !== UNDEFINED_VALUE && writer.maxSize > 0 && writer.maxSize !== Infinity;
9878
9911
  Object.assign(this, {
9879
9912
  writer,
9880
- addSplitZipSignature: writer instanceof SplitDataWriter,
9913
+ addSplitZipSignature,
9881
9914
  options,
9882
9915
  config: getConfiguration(),
9883
9916
  files: new Map(),
@@ -9940,6 +9973,33 @@
9940
9973
  }
9941
9974
  }
9942
9975
 
9976
+ class ZipWriterStream {
9977
+
9978
+ constructor(options = {}) {
9979
+ const { readable, writable } = new TransformStream();
9980
+ this.readable = readable;
9981
+ this.zipWriter = new ZipWriter(writable, options);
9982
+ }
9983
+
9984
+ transform(path) {
9985
+ const { readable, writable } = new TransformStream({
9986
+ flush: () => { this.zipWriter.close(); }
9987
+ });
9988
+ this.zipWriter.add(path, readable);
9989
+ return { readable: this.readable, writable };
9990
+ }
9991
+
9992
+ writable(path) {
9993
+ const { readable, writable } = new TransformStream();
9994
+ this.zipWriter.add(path, readable);
9995
+ return writable;
9996
+ }
9997
+
9998
+ close(comment = undefined, options = {}) {
9999
+ return this.zipWriter.close(comment, options);
10000
+ }
10001
+ }
10002
+
9943
10003
  async function addFile(zipWriter, name, reader, options) {
9944
10004
  name = name.trim();
9945
10005
  if (options.directory && (!name.endsWith(DIRECTORY_SIGNATURE))) {
@@ -10110,6 +10170,7 @@
10110
10170
  let writingBufferedEntryData;
10111
10171
  let writingEntryData;
10112
10172
  let fileWriter;
10173
+ let blobPromise;
10113
10174
  files.set(name, fileEntry);
10114
10175
  try {
10115
10176
  let lockPreviousFileEntry;
@@ -10118,7 +10179,8 @@
10118
10179
  requestLockCurrentFileEntry();
10119
10180
  }
10120
10181
  if ((options.bufferedWrite || zipWriter.writerLocked || (zipWriter.bufferedWrites && keepOrder) || !dataDescriptor) && !usdz) {
10121
- fileWriter = new BlobWriter();
10182
+ fileWriter = new TransformStream();
10183
+ blobPromise = new Response(fileWriter.readable).blob();
10122
10184
  fileWriter.writable.size = 0;
10123
10185
  bufferedWrite = true;
10124
10186
  zipWriter.bufferedWrites++;
@@ -10154,7 +10216,7 @@
10154
10216
  fileEntry.filename = name;
10155
10217
  if (bufferedWrite) {
10156
10218
  await fileWriter.writable.getWriter().close();
10157
- let blob = await fileWriter.getData();
10219
+ let blob = await blobPromise;
10158
10220
  await lockPreviousFileEntry;
10159
10221
  await requestLockWriter();
10160
10222
  writingBufferedEntryData = true;
@@ -11745,8 +11807,8 @@
11745
11807
  1. Redistributions of source code must retain the above copyright notice,
11746
11808
  this list of conditions and the following disclaimer.
11747
11809
 
11748
- 2. Redistributions in binary form must reproduce the above copyright
11749
- notice, this list of conditions and the following disclaimer in
11810
+ 2. Redistributions in binary form must reproduce the above copyright
11811
+ notice, this list of conditions and the following disclaimer in
11750
11812
  the documentation and/or other materials provided with the distribution.
11751
11813
 
11752
11814
  3. The names of the authors may not be used to endorse or promote products
@@ -11818,7 +11880,9 @@
11818
11880
  exports.Uint8ArrayWriter = Uint8ArrayWriter;
11819
11881
  exports.Writer = Writer;
11820
11882
  exports.ZipReader = ZipReader;
11883
+ exports.ZipReaderStream = ZipReaderStream;
11821
11884
  exports.ZipWriter = ZipWriter;
11885
+ exports.ZipWriterStream = ZipWriterStream;
11822
11886
  exports.configure = configure;
11823
11887
  exports.fs = fs;
11824
11888
  exports.getMimeType = getMimeType;