@zip.js/zip.js 2.21.0 → 2.22.0

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/dist/zip-core.js CHANGED
@@ -225,6 +225,7 @@
225
225
  const ERR_INVALID_SIGNAL = "Invalid signal (must be an AbortSignal instance)";
226
226
  const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
227
227
  const ERR_INVALID_PASS_THROUGH_VALUE = "Invalid passThrough option (must be a boolean or 'compressed')";
228
+ const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
228
229
  const ERR_ABORTED = "The operation was aborted";
229
230
  const ABORT_ERROR_NAME = "AbortError";
230
231
 
@@ -235,6 +236,13 @@
235
236
  return value;
236
237
  }
237
238
 
239
+ function checkReaderOptionsObject(readerOptions) {
240
+ if (readerOptions && (typeof readerOptions != OBJECT_TYPE || Array.isArray(readerOptions))) {
241
+ throw new Error(ERR_INVALID_READER_OPTIONS);
242
+ }
243
+ return readerOptions;
244
+ }
245
+
238
246
  function checkSignalOption(signal) {
239
247
  if (signal && (typeof signal.addEventListener != FUNCTION_TYPE || typeof signal.aborted != BOOLEAN_TYPE)) {
240
248
  throw new Error(ERR_INVALID_SIGNAL);
@@ -330,7 +338,6 @@
330
338
  workerStartupTimeout: 5000,
331
339
  useWebWorkers: true,
332
340
  useCompressionStream: true,
333
- transferStreams: true,
334
341
  CompressionStream: typeof CompressionStream != UNDEFINED_TYPE && CompressionStream,
335
342
  DecompressionStream: typeof DecompressionStream != UNDEFINED_TYPE && DecompressionStream
336
343
  };
@@ -344,8 +351,7 @@
344
351
  ];
345
352
  const BOOLEAN_PROPERTY_NAMES = [
346
353
  "useCompressionStream",
347
- "useWebWorkers",
348
- "transferStreams"
354
+ "useWebWorkers"
349
355
  ];
350
356
  const NUMBER_PROPERTY_NAMES = [
351
357
  "chunkSize",
@@ -4825,7 +4831,7 @@
4825
4831
  constructor(reader, options = {}) {
4826
4832
  Object.assign(this, {
4827
4833
  reader: new GenericReader(reader),
4828
- options,
4834
+ options: options || {},
4829
4835
  readRanges: { indexes: new Set(), sortedRanges: [], pendingRanges: [] },
4830
4836
  entriesMissingZip64ExtraField: new WeakSet()
4831
4837
  });
@@ -6845,6 +6851,7 @@
6845
6851
  async function appendZipEntries(zipWriter, reader, options = {}) {
6846
6852
  const { pendingAddFileCalls, filenames, fileEntries } = zipWriter;
6847
6853
  const filter = checkFunctionOption(options.filter);
6854
+ const readerOptions = checkReaderOptionsObject(options.readerOptions);
6848
6855
  while (pendingAddFileCalls.size) {
6849
6856
  await Promise.allSettled(Array.from(pendingAddFileCalls));
6850
6857
  }
@@ -6861,15 +6868,19 @@
6861
6868
  await initStream(reader);
6862
6869
  }
6863
6870
  const { ZipReader, getEntryDataDescriptorLength } = await Promise.resolve().then(function () { return zipReader; });
6864
- const zipReader$1 = new ZipReader(reader);
6865
- const entries = await zipReader$1.getEntries();
6871
+ const zipReader$1 = new ZipReader(reader, readerOptions);
6866
6872
  const keptEntries = [];
6867
- for (const entry of entries) {
6868
- if (!filter || await filter(entry)) {
6869
- keptEntries.push(entry);
6873
+ let entries;
6874
+ try {
6875
+ entries = await zipReader$1.getEntries();
6876
+ for (const entry of entries) {
6877
+ if (!filter || await filter(entry, getExistingEntry(fileEntries, entry.filename))) {
6878
+ keptEntries.push(entry);
6879
+ }
6870
6880
  }
6881
+ } finally {
6882
+ await zipReader$1.close();
6871
6883
  }
6872
- await zipReader$1.close();
6873
6884
  await initStream(zipWriter.writer);
6874
6885
  const { directoryOffset, entriesMissingZip64ExtraField } = zipReader$1;
6875
6886
  keptEntries.forEach(entry => {
@@ -6939,7 +6950,7 @@
6939
6950
  setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
6940
6951
  }
6941
6952
  const { offset, diskNumberStart } = entryPositions.get(entry);
6942
- Object.assign(entry, {
6953
+ fileEntries.set(entry.filename, Object.assign({}, entry, {
6943
6954
  zip64Enabled: true,
6944
6955
  zip64UncompressedSize,
6945
6956
  zip64CompressedSize,
@@ -6956,8 +6967,7 @@
6956
6967
  rawCentralExtraField: EMPTY_UINT8_ARRAY,
6957
6968
  headerArray,
6958
6969
  headerView
6959
- });
6960
- fileEntries.set(entry.filename, entry);
6970
+ }));
6961
6971
  });
6962
6972
  } catch (error) {
6963
6973
  appendedFilenames.forEach(filename => filenames.delete(filename));
@@ -6971,6 +6981,11 @@
6971
6981
  }
6972
6982
  }
6973
6983
 
6984
+ function getExistingEntry(fileEntries, filename) {
6985
+ const fileEntry = fileEntries.get(filename);
6986
+ return fileEntry ? new Entry(fileEntry) : UNDEFINED_VALUE;
6987
+ }
6988
+
6974
6989
  async function prependZipEntries(zipWriter, reader) {
6975
6990
  if (zipWriter.filenames.size) {
6976
6991
  throw new Error(ERR_ZIP_NOT_EMPTY);
@@ -9115,7 +9130,7 @@
9115
9130
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9116
9131
  */
9117
9132
 
9118
- const VERSION = "2.21.0";
9133
+ const VERSION = "2.22.0";
9119
9134
 
9120
9135
  /*
9121
9136
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9613,6 +9628,7 @@
9613
9628
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
9614
9629
  exports.ERR_INVALID_PASS_THROUGH_VALUE = ERR_INVALID_PASS_THROUGH_VALUE;
9615
9630
  exports.ERR_INVALID_READER = ERR_INVALID_READER;
9631
+ exports.ERR_INVALID_READER_OPTIONS = ERR_INVALID_READER_OPTIONS;
9616
9632
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
9617
9633
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
9618
9634
  exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;