@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-fs.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$1 = "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",
@@ -4855,7 +4861,7 @@
4855
4861
  constructor(reader, options = {}) {
4856
4862
  Object.assign(this, {
4857
4863
  reader: new GenericReader(reader),
4858
- options,
4864
+ options: options || {},
4859
4865
  readRanges: { indexes: new Set(), sortedRanges: [], pendingRanges: [] },
4860
4866
  entriesMissingZip64ExtraField: new WeakSet()
4861
4867
  });
@@ -6875,6 +6881,7 @@
6875
6881
  async function appendZipEntries(zipWriter, reader, options = {}) {
6876
6882
  const { pendingAddFileCalls, filenames, fileEntries } = zipWriter;
6877
6883
  const filter = checkFunctionOption(options.filter);
6884
+ const readerOptions = checkReaderOptionsObject(options.readerOptions);
6878
6885
  while (pendingAddFileCalls.size) {
6879
6886
  await Promise.allSettled(Array.from(pendingAddFileCalls));
6880
6887
  }
@@ -6891,15 +6898,19 @@
6891
6898
  await initStream(reader);
6892
6899
  }
6893
6900
  const { ZipReader, getEntryDataDescriptorLength } = await Promise.resolve().then(function () { return zipReader; });
6894
- const zipReader$1 = new ZipReader(reader);
6895
- const entries = await zipReader$1.getEntries();
6901
+ const zipReader$1 = new ZipReader(reader, readerOptions);
6896
6902
  const keptEntries = [];
6897
- for (const entry of entries) {
6898
- if (!filter || await filter(entry)) {
6899
- keptEntries.push(entry);
6903
+ let entries;
6904
+ try {
6905
+ entries = await zipReader$1.getEntries();
6906
+ for (const entry of entries) {
6907
+ if (!filter || await filter(entry, getExistingEntry(fileEntries, entry.filename))) {
6908
+ keptEntries.push(entry);
6909
+ }
6900
6910
  }
6911
+ } finally {
6912
+ await zipReader$1.close();
6901
6913
  }
6902
- await zipReader$1.close();
6903
6914
  await initStream(zipWriter.writer);
6904
6915
  const { directoryOffset, entriesMissingZip64ExtraField } = zipReader$1;
6905
6916
  keptEntries.forEach(entry => {
@@ -6969,7 +6980,7 @@
6969
6980
  setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
6970
6981
  }
6971
6982
  const { offset, diskNumberStart } = entryPositions.get(entry);
6972
- Object.assign(entry, {
6983
+ fileEntries.set(entry.filename, Object.assign({}, entry, {
6973
6984
  zip64Enabled: true,
6974
6985
  zip64UncompressedSize,
6975
6986
  zip64CompressedSize,
@@ -6986,8 +6997,7 @@
6986
6997
  rawCentralExtraField: EMPTY_UINT8_ARRAY,
6987
6998
  headerArray,
6988
6999
  headerView
6989
- });
6990
- fileEntries.set(entry.filename, entry);
7000
+ }));
6991
7001
  });
6992
7002
  } catch (error) {
6993
7003
  appendedFilenames.forEach(filename => filenames.delete(filename));
@@ -7001,6 +7011,11 @@
7001
7011
  }
7002
7012
  }
7003
7013
 
7014
+ function getExistingEntry(fileEntries, filename) {
7015
+ const fileEntry = fileEntries.get(filename);
7016
+ return fileEntry ? new Entry(fileEntry) : UNDEFINED_VALUE;
7017
+ }
7018
+
7004
7019
  async function prependZipEntries(zipWriter, reader) {
7005
7020
  if (zipWriter.filenames.size) {
7006
7021
  throw new Error(ERR_ZIP_NOT_EMPTY);
@@ -9243,7 +9258,7 @@
9243
9258
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9244
9259
  */
9245
9260
 
9246
- const VERSION = "2.21.0";
9261
+ const VERSION = "2.22.0";
9247
9262
 
9248
9263
  /*
9249
9264
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -10318,7 +10333,6 @@
10318
10333
  const DUPLICATES_KEEP_LAST = "keep-last";
10319
10334
  const DUPLICATES_VALUES = new Set([DUPLICATES_THROW, DUPLICATES_KEEP_FIRST, DUPLICATES_KEEP_LAST]);
10320
10335
  const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
10321
- const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
10322
10336
  const ERR_UNSUPPORTED_PASS_THROUGH_VALUE = "The 'compressed' passThrough option is only supported by Entry#getData() and ZipWriter#add()";
10323
10337
  const ERR_INVALID_PASSWORDS = "Invalid passwords option (must be an array of strings)";
10324
10338
  const ERR_INVALID_REQUEST_PASSWORD = "Invalid requestPassword option (must be a function returning a string or undefined)";
@@ -11244,9 +11258,7 @@
11244
11258
  }
11245
11259
 
11246
11260
  function checkReaderOptions(readerOptions) {
11247
- if (readerOptions && (typeof readerOptions != OBJECT_TYPE || Array.isArray(readerOptions))) {
11248
- throw new Error(ERR_INVALID_READER_OPTIONS);
11249
- }
11261
+ checkReaderOptionsObject(readerOptions);
11250
11262
  if (readerOptions) {
11251
11263
  checkPassThroughValue(readerOptions.passThrough);
11252
11264
  checkPasswordCandidatesOptions(readerOptions);