@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.
@@ -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",
@@ -4827,7 +4833,7 @@
4827
4833
  constructor(reader, options = {}) {
4828
4834
  Object.assign(this, {
4829
4835
  reader: new GenericReader(reader),
4830
- options,
4836
+ options: options || {},
4831
4837
  readRanges: { indexes: new Set(), sortedRanges: [], pendingRanges: [] },
4832
4838
  entriesMissingZip64ExtraField: new WeakSet()
4833
4839
  });
@@ -6847,6 +6853,7 @@
6847
6853
  async function appendZipEntries(zipWriter, reader, options = {}) {
6848
6854
  const { pendingAddFileCalls, filenames, fileEntries } = zipWriter;
6849
6855
  const filter = checkFunctionOption(options.filter);
6856
+ const readerOptions = checkReaderOptionsObject(options.readerOptions);
6850
6857
  while (pendingAddFileCalls.size) {
6851
6858
  await Promise.allSettled(Array.from(pendingAddFileCalls));
6852
6859
  }
@@ -6863,15 +6870,19 @@
6863
6870
  await initStream(reader);
6864
6871
  }
6865
6872
  const { ZipReader, getEntryDataDescriptorLength } = await Promise.resolve().then(function () { return zipReader; });
6866
- const zipReader$1 = new ZipReader(reader);
6867
- const entries = await zipReader$1.getEntries();
6873
+ const zipReader$1 = new ZipReader(reader, readerOptions);
6868
6874
  const keptEntries = [];
6869
- for (const entry of entries) {
6870
- if (!filter || await filter(entry)) {
6871
- keptEntries.push(entry);
6875
+ let entries;
6876
+ try {
6877
+ entries = await zipReader$1.getEntries();
6878
+ for (const entry of entries) {
6879
+ if (!filter || await filter(entry, getExistingEntry(fileEntries, entry.filename))) {
6880
+ keptEntries.push(entry);
6881
+ }
6872
6882
  }
6883
+ } finally {
6884
+ await zipReader$1.close();
6873
6885
  }
6874
- await zipReader$1.close();
6875
6886
  await initStream(zipWriter.writer);
6876
6887
  const { directoryOffset, entriesMissingZip64ExtraField } = zipReader$1;
6877
6888
  keptEntries.forEach(entry => {
@@ -6941,7 +6952,7 @@
6941
6952
  setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
6942
6953
  }
6943
6954
  const { offset, diskNumberStart } = entryPositions.get(entry);
6944
- Object.assign(entry, {
6955
+ fileEntries.set(entry.filename, Object.assign({}, entry, {
6945
6956
  zip64Enabled: true,
6946
6957
  zip64UncompressedSize,
6947
6958
  zip64CompressedSize,
@@ -6958,8 +6969,7 @@
6958
6969
  rawCentralExtraField: EMPTY_UINT8_ARRAY,
6959
6970
  headerArray,
6960
6971
  headerView
6961
- });
6962
- fileEntries.set(entry.filename, entry);
6972
+ }));
6963
6973
  });
6964
6974
  } catch (error) {
6965
6975
  appendedFilenames.forEach(filename => filenames.delete(filename));
@@ -6973,6 +6983,11 @@
6973
6983
  }
6974
6984
  }
6975
6985
 
6986
+ function getExistingEntry(fileEntries, filename) {
6987
+ const fileEntry = fileEntries.get(filename);
6988
+ return fileEntry ? new Entry(fileEntry) : UNDEFINED_VALUE;
6989
+ }
6990
+
6976
6991
  async function prependZipEntries(zipWriter, reader) {
6977
6992
  if (zipWriter.filenames.size) {
6978
6993
  throw new Error(ERR_ZIP_NOT_EMPTY);
@@ -9117,7 +9132,7 @@
9117
9132
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9118
9133
  */
9119
9134
 
9120
- const VERSION = "2.21.0";
9135
+ const VERSION = "2.22.0";
9121
9136
 
9122
9137
  /*
9123
9138
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9646,6 +9661,7 @@
9646
9661
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
9647
9662
  exports.ERR_INVALID_PASS_THROUGH_VALUE = ERR_INVALID_PASS_THROUGH_VALUE;
9648
9663
  exports.ERR_INVALID_READER = ERR_INVALID_READER;
9664
+ exports.ERR_INVALID_READER_OPTIONS = ERR_INVALID_READER_OPTIONS;
9649
9665
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
9650
9666
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
9651
9667
  exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;