@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/index-native.cjs CHANGED
@@ -219,6 +219,7 @@ const ERR_INVALID_FUNCTION_OPTION = "Invalid option (must be a function)";
219
219
  const ERR_INVALID_SIGNAL = "Invalid signal (must be an AbortSignal instance)";
220
220
  const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
221
221
  const ERR_INVALID_PASS_THROUGH_VALUE = "Invalid passThrough option (must be a boolean or 'compressed')";
222
+ const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
222
223
  const ERR_ABORTED = "The operation was aborted";
223
224
  const ABORT_ERROR_NAME$1 = "AbortError";
224
225
 
@@ -229,6 +230,13 @@ function checkFunctionOption(value) {
229
230
  return value;
230
231
  }
231
232
 
233
+ function checkReaderOptionsObject(readerOptions) {
234
+ if (readerOptions && (typeof readerOptions != OBJECT_TYPE || Array.isArray(readerOptions))) {
235
+ throw new Error(ERR_INVALID_READER_OPTIONS);
236
+ }
237
+ return readerOptions;
238
+ }
239
+
232
240
  function checkSignalOption(signal) {
233
241
  if (signal && (typeof signal.addEventListener != FUNCTION_TYPE || typeof signal.aborted != BOOLEAN_TYPE)) {
234
242
  throw new Error(ERR_INVALID_SIGNAL);
@@ -324,7 +332,6 @@ const DEFAULT_CONFIGURATION = {
324
332
  workerStartupTimeout: 5000,
325
333
  useWebWorkers: true,
326
334
  useCompressionStream: true,
327
- transferStreams: true,
328
335
  CompressionStream: typeof CompressionStream != UNDEFINED_TYPE && CompressionStream,
329
336
  DecompressionStream: typeof DecompressionStream != UNDEFINED_TYPE && DecompressionStream
330
337
  };
@@ -338,8 +345,7 @@ const URI_PROPERTY_NAMES = [
338
345
  ];
339
346
  const BOOLEAN_PROPERTY_NAMES = [
340
347
  "useCompressionStream",
341
- "useWebWorkers",
342
- "transferStreams"
348
+ "useWebWorkers"
343
349
  ];
344
350
  const NUMBER_PROPERTY_NAMES = [
345
351
  "chunkSize",
@@ -4841,7 +4847,7 @@ class ZipReader {
4841
4847
  constructor(reader, options = {}) {
4842
4848
  Object.assign(this, {
4843
4849
  reader: new GenericReader(reader),
4844
- options,
4850
+ options: options || {},
4845
4851
  readRanges: { indexes: new Set(), sortedRanges: [], pendingRanges: [] },
4846
4852
  entriesMissingZip64ExtraField: new WeakSet()
4847
4853
  });
@@ -6861,6 +6867,7 @@ function watchPromiseError(zipWriter, promise) {
6861
6867
  async function appendZipEntries(zipWriter, reader, options = {}) {
6862
6868
  const { pendingAddFileCalls, filenames, fileEntries } = zipWriter;
6863
6869
  const filter = checkFunctionOption(options.filter);
6870
+ const readerOptions = checkReaderOptionsObject(options.readerOptions);
6864
6871
  while (pendingAddFileCalls.size) {
6865
6872
  await Promise.allSettled(Array.from(pendingAddFileCalls));
6866
6873
  }
@@ -6877,15 +6884,19 @@ async function appendZipEntries(zipWriter, reader, options = {}) {
6877
6884
  await initStream(reader);
6878
6885
  }
6879
6886
  const { ZipReader, getEntryDataDescriptorLength } = await Promise.resolve().then(function () { return zipReader; });
6880
- const zipReader$1 = new ZipReader(reader);
6881
- const entries = await zipReader$1.getEntries();
6887
+ const zipReader$1 = new ZipReader(reader, readerOptions);
6882
6888
  const keptEntries = [];
6883
- for (const entry of entries) {
6884
- if (!filter || await filter(entry)) {
6885
- keptEntries.push(entry);
6889
+ let entries;
6890
+ try {
6891
+ entries = await zipReader$1.getEntries();
6892
+ for (const entry of entries) {
6893
+ if (!filter || await filter(entry, getExistingEntry(fileEntries, entry.filename))) {
6894
+ keptEntries.push(entry);
6895
+ }
6886
6896
  }
6897
+ } finally {
6898
+ await zipReader$1.close();
6887
6899
  }
6888
- await zipReader$1.close();
6889
6900
  await initStream(zipWriter.writer);
6890
6901
  const { directoryOffset, entriesMissingZip64ExtraField } = zipReader$1;
6891
6902
  keptEntries.forEach(entry => {
@@ -6955,7 +6966,7 @@ async function appendZipEntries(zipWriter, reader, options = {}) {
6955
6966
  setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
6956
6967
  }
6957
6968
  const { offset, diskNumberStart } = entryPositions.get(entry);
6958
- Object.assign(entry, {
6969
+ fileEntries.set(entry.filename, Object.assign({}, entry, {
6959
6970
  zip64Enabled: true,
6960
6971
  zip64UncompressedSize,
6961
6972
  zip64CompressedSize,
@@ -6972,8 +6983,7 @@ async function appendZipEntries(zipWriter, reader, options = {}) {
6972
6983
  rawCentralExtraField: EMPTY_UINT8_ARRAY,
6973
6984
  headerArray,
6974
6985
  headerView
6975
- });
6976
- fileEntries.set(entry.filename, entry);
6986
+ }));
6977
6987
  });
6978
6988
  } catch (error) {
6979
6989
  appendedFilenames.forEach(filename => filenames.delete(filename));
@@ -6987,6 +6997,11 @@ async function appendZipEntries(zipWriter, reader, options = {}) {
6987
6997
  }
6988
6998
  }
6989
6999
 
7000
+ function getExistingEntry(fileEntries, filename) {
7001
+ const fileEntry = fileEntries.get(filename);
7002
+ return fileEntry ? new Entry(fileEntry) : UNDEFINED_VALUE;
7003
+ }
7004
+
6990
7005
  async function prependZipEntries(zipWriter, reader) {
6991
7006
  if (zipWriter.filenames.size) {
6992
7007
  throw new Error(ERR_ZIP_NOT_EMPTY);
@@ -9229,7 +9244,7 @@ function formatSupported(StreamClass, format) {
9229
9244
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9230
9245
  */
9231
9246
 
9232
- const VERSION = "2.21.0";
9247
+ const VERSION = "2.22.0";
9233
9248
 
9234
9249
  /*
9235
9250
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9758,7 +9773,6 @@ const DUPLICATES_KEEP_FIRST = "keep-first";
9758
9773
  const DUPLICATES_KEEP_LAST = "keep-last";
9759
9774
  const DUPLICATES_VALUES = new Set([DUPLICATES_THROW, DUPLICATES_KEEP_FIRST, DUPLICATES_KEEP_LAST]);
9760
9775
  const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
9761
- const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
9762
9776
  const ERR_UNSUPPORTED_PASS_THROUGH_VALUE = "The 'compressed' passThrough option is only supported by Entry#getData() and ZipWriter#add()";
9763
9777
  const ERR_INVALID_PASSWORDS = "Invalid passwords option (must be an array of strings)";
9764
9778
  const ERR_INVALID_REQUEST_PASSWORD = "Invalid requestPassword option (must be a function returning a string or undefined)";
@@ -10684,9 +10698,7 @@ function getDeterminedSize(child, passThrough) {
10684
10698
  }
10685
10699
 
10686
10700
  function checkReaderOptions(readerOptions) {
10687
- if (readerOptions && (typeof readerOptions != OBJECT_TYPE || Array.isArray(readerOptions))) {
10688
- throw new Error(ERR_INVALID_READER_OPTIONS);
10689
- }
10701
+ checkReaderOptionsObject(readerOptions);
10690
10702
  if (readerOptions) {
10691
10703
  checkPassThroughValue(readerOptions.passThrough);
10692
10704
  checkPasswordCandidatesOptions(readerOptions);