@zip.js/zip.js 2.11.2 → 2.11.4

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.js CHANGED
@@ -4,7 +4,7 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.zip = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- const { Array, Object, String, Number, BigInt, Math, Date, Map, Set, Response, URL, Error, Uint8Array, Uint16Array, Uint32Array, DataView, Blob, Promise, TextEncoder, TextDecoder, document, crypto, btoa, TransformStream, ReadableStream, WritableStream, CompressionStream, DecompressionStream, navigator, Worker, Symbol, setTimeout, clearTimeout, structuredClone } = typeof globalThis !== 'undefined' ? globalThis : this || self;
7
+ const { Array, Object, String, Number, BigInt, Math, Date, Map, Set, Response, URL, Error, Uint8Array, Uint16Array, Uint32Array, DataView, Blob, Promise, TextEncoder, TextDecoder, document, crypto, btoa, TransformStream, ReadableStream, WritableStream, CompressionStream, DecompressionStream, navigator, Worker, Symbol, setTimeout, clearTimeout, structuredClone } = typeof globalThis !== 'undefined' ? globalThis : self;
8
8
 
9
9
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
10
10
  /*
@@ -217,6 +217,8 @@
217
217
  const ERR_INVALID_FUNCTION_OPTION = "Invalid option (must be a function)";
218
218
  const ERR_INVALID_SIGNAL = "Invalid signal (must be an AbortSignal instance)";
219
219
  const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
220
+ const ERR_ABORTED = "The operation was aborted";
221
+ const ABORT_ERROR_NAME = "AbortError";
220
222
 
221
223
  function checkFunctionOption(value) {
222
224
  if (value && typeof value != FUNCTION_TYPE) {
@@ -232,6 +234,12 @@
232
234
  return signal || UNDEFINED_VALUE;
233
235
  }
234
236
 
237
+ function throwIfAborted(signal) {
238
+ if (signal && signal.aborted) {
239
+ throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME) : signal.reason;
240
+ }
241
+ }
242
+
235
243
  function checkPasswordOption(password, rawPassword) {
236
244
  if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
237
245
  throw new Error(ERR_INVALID_PASSWORD_TYPE);
@@ -3760,11 +3768,13 @@
3760
3768
  const reader = this;
3761
3769
  const { sourceBlob, size } = reader;
3762
3770
  const { offset = 0, size: readSize = size - offset } = options || {};
3763
- if (!offset && readSize >= size) {
3764
- return toCompatibleReadable(sourceBlob.stream());
3765
- }
3766
- if (blobSliceReliable) {
3767
- return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
3771
+ if (typeof sourceBlob.stream == FUNCTION_TYPE) {
3772
+ if (!offset && readSize >= size) {
3773
+ return toCompatibleReadable(sourceBlob.stream());
3774
+ }
3775
+ if (blobSliceReliable) {
3776
+ return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
3777
+ }
3768
3778
  }
3769
3779
  return super.createReadable(options);
3770
3780
  }
@@ -5180,27 +5190,28 @@
5180
5190
  const { done, value } = await gen.next();
5181
5191
  if (done)
5182
5192
  return controller.close();
5183
- const chunk = {
5184
- ...value,
5185
- readable: (function () {
5186
- const { readable, writable } = new TransformStream();
5187
- if (value.getData) {
5188
- getData();
5189
- return readable;
5190
- }
5193
+ const entryReadable = (function () {
5194
+ const { readable, writable } = new TransformStream();
5195
+ if (value.getData) {
5196
+ getData();
5197
+ return readable;
5198
+ }
5191
5199
 
5192
- async function getData() {
5200
+ async function getData() {
5201
+ try {
5202
+ await value.getData(writable);
5203
+ } catch (error) {
5193
5204
  try {
5194
- await value.getData(writable);
5195
- } catch (error) {
5196
- try {
5197
- await writable.abort(error);
5198
- } catch {
5199
- // ignored
5200
- }
5205
+ await writable.abort(error);
5206
+ } catch {
5207
+ // ignored
5201
5208
  }
5202
5209
  }
5203
- })()
5210
+ }
5211
+ })();
5212
+ const chunk = {
5213
+ ...value,
5214
+ readable: entryReadable
5204
5215
  };
5205
5216
  delete chunk.getData;
5206
5217
  controller.enqueue(chunk);
@@ -5346,6 +5357,7 @@
5346
5357
  const size = compressedSize;
5347
5358
  const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
5348
5359
  const signal = checkSignalOption(getOptionValue$1(zipEntry, options, OPTION_SIGNAL));
5360
+ throwIfAborted(signal);
5349
5361
  const checkPasswordOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
5350
5362
  let checkOverlappingEntry = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
5351
5363
  const checkOverlappingEntryOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY_ONLY);
@@ -6252,6 +6264,7 @@
6252
6264
  const ERR_INVALID_VERSION = "Version exceeds 65535";
6253
6265
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
6254
6266
  const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
6267
+ const ERR_UNSUPPORTED_SPLIT_USDZ = "Split zip files are not supported in USDZ files";
6255
6268
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
6256
6269
  const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
6257
6270
  const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
@@ -6266,6 +6279,7 @@
6266
6279
  const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
6267
6280
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
6268
6281
  const ERR_UNDEFINED_READER = "Undefined reader";
6282
+ const ERR_INVALID_READER = "Invalid reader (must be a Reader instance, a ReadableStream instance, or an object with a 'readable' property)";
6269
6283
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
6270
6284
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
6271
6285
  const ERR_INVALID_GID = "Invalid gid (must be integer 0..2^32-1)";
@@ -6297,6 +6311,9 @@
6297
6311
  const addSplitZipSignature =
6298
6312
  availableSize > 0 && availableSize !== INFINITY_VALUE &&
6299
6313
  maxSize > 0 && maxSize !== INFINITY_VALUE;
6314
+ if (addSplitZipSignature && options[OPTION_USDZ]) {
6315
+ throw new Error(ERR_UNSUPPORTED_SPLIT_USDZ);
6316
+ }
6300
6317
  Object.assign(this, {
6301
6318
  writer,
6302
6319
  addSplitZipSignature,
@@ -6412,6 +6429,7 @@
6412
6429
  }
6413
6430
  const { offset, diskNumberStart } = entryPositions.get(entry);
6414
6431
  Object.assign(entry, {
6432
+ zip64Enabled: true,
6415
6433
  zip64UncompressedSize,
6416
6434
  zip64CompressedSize,
6417
6435
  offset,
@@ -6870,6 +6888,7 @@
6870
6888
  const createTempStream = getFunctionOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
6871
6889
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, true);
6872
6890
  const signal = checkSignalOption(getOptionValue(zipWriter, options, OPTION_SIGNAL));
6891
+ throwIfAborted(signal);
6873
6892
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
6874
6893
  const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
6875
6894
  const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
@@ -6987,6 +7006,9 @@
6987
7006
  if (reader) {
6988
7007
  reader = new GenericReader(reader);
6989
7008
  await initStream(reader);
7009
+ if (!reader.readable && !reader.readUint8Array) {
7010
+ throw new Error(ERR_INVALID_READER);
7011
+ }
6990
7012
  ({ size: contentSize } = reader);
6991
7013
  }
6992
7014
  return Object.assign({ reader }, resolveEntrySizes(zipWriter, Boolean(reader), contentSize, metadata, options));
@@ -6997,6 +7019,7 @@
6997
7019
  let { dataDescriptor, zip64, level, compressionMethod } = metadata;
6998
7020
  let maximumCompressedSize = 0;
6999
7021
  let uncompressedSize = 0;
7022
+ let unknownSize = false;
7000
7023
  if (passThrough && hasContent) {
7001
7024
  uncompressedSize = options[PROPERTY_NAME_UNCOMPRESSED_SIZE];
7002
7025
  if (uncompressedSize === UNDEFINED_VALUE) {
@@ -7022,8 +7045,8 @@
7022
7045
  if (contentSize === UNDEFINED_VALUE) {
7023
7046
  dataDescriptor = true;
7024
7047
  if (zip64 || zip64 === UNDEFINED_VALUE) {
7025
- zip64 = true;
7026
- uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
7048
+ zip64 = unknownSize = true;
7049
+ maximumCompressedSize = MAX_32_BITS + 1;
7027
7050
  }
7028
7051
  } else {
7029
7052
  options.uncompressedSize = uncompressedSize = contentSize;
@@ -7038,7 +7061,7 @@
7038
7061
  if (emptyEntry && !zipCrypto && getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR) === UNDEFINED_VALUE) {
7039
7062
  dataDescriptor = false;
7040
7063
  }
7041
- const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
7064
+ const zip64UncompressedSize = zip64Enabled || unknownSize || uncompressedSize >= MAX_32_BITS;
7042
7065
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
7043
7066
  if (zip64UncompressedSize || zip64CompressedSize) {
7044
7067
  if (zip64 === false) {
@@ -7054,6 +7077,8 @@
7054
7077
  dataDescriptor,
7055
7078
  emptyEntry,
7056
7079
  zip64,
7080
+ zip64Enabled,
7081
+ unknownSize,
7057
7082
  zip64UncompressedSize,
7058
7083
  zip64CompressedSize,
7059
7084
  uncompressedSize,
@@ -7252,6 +7277,7 @@
7252
7277
  rawPassword,
7253
7278
  level,
7254
7279
  zip64,
7280
+ zip64Enabled,
7255
7281
  zip64UncompressedSize,
7256
7282
  zip64CompressedSize,
7257
7283
  zipCrypto,
@@ -7292,6 +7318,7 @@
7292
7318
  lockFileEntry,
7293
7319
  versionMadeBy,
7294
7320
  zip64,
7321
+ zip64Enabled,
7295
7322
  directory: Boolean(directory),
7296
7323
  executable: Boolean(executable),
7297
7324
  filenameUTF8: true,
@@ -7435,13 +7462,14 @@
7435
7462
  zip64UncompressedSize,
7436
7463
  zip64CompressedSize,
7437
7464
  uncompressedSize,
7465
+ unknownSize,
7438
7466
  crc32
7439
7467
  } = options;
7440
7468
  let { version, compressionMethod } = options;
7441
7469
  const compressed = !directory && isCompressed(compressionMethod, level);
7442
7470
  let rawLocalExtraFieldZip64;
7443
7471
  const uncompressedFile = passThrough || !compressed;
7444
- const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
7472
+ const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || (uncompressedFile && !unknownSize)));
7445
7473
  const writeLocalExtraFieldZip64 = zip64ExtraFieldComplete || (zip64 && dataDescriptor && (zip64UncompressedSize || zip64CompressedSize));
7446
7474
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
7447
7475
  const length = 4 + 16;
@@ -7575,6 +7603,10 @@
7575
7603
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
7576
7604
  }
7577
7605
  const dosLastModDate = new Date(Math.ceil(Math.floor(lastModDate.getTime() / 1000) / 2) * 2000);
7606
+ const clampedLastModDate = dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate;
7607
+ const storedLastModDate = getLength(rawExtraFieldExtendedTimestamp) ?
7608
+ new Date(getTimeUnix(lastModDate) * 1000) :
7609
+ getLength(rawExtraFieldNTFS) ? lastModDate : clampedLastModDate;
7578
7610
  const {
7579
7611
  headerArray,
7580
7612
  headerView,
@@ -7584,7 +7616,7 @@
7584
7616
  bitFlag: getBitFlag(level, useUnicodeFileNames, dataDescriptor, encrypted, compressionMethod),
7585
7617
  compressionMethod,
7586
7618
  uncompressedSize,
7587
- lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
7619
+ lastModDate: clampedLastModDate,
7588
7620
  rawLastModDate: rawLastModDateOption,
7589
7621
  rawFilename,
7590
7622
  zip64CompressedSize,
@@ -7619,7 +7651,7 @@
7619
7651
  localHeaderView,
7620
7652
  headerArray,
7621
7653
  headerView,
7622
- lastModDate,
7654
+ lastModDate: storedLastModDate,
7623
7655
  rawLastModDate,
7624
7656
  encrypted,
7625
7657
  compressed,
@@ -7791,14 +7823,15 @@
7791
7823
 
7792
7824
 
7793
7825
  async function closeFile(zipWriter, comment, options) {
7794
- const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7826
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(zipWriter.fileEntries);
7795
7827
  const { directoryStart, directoryEnd, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7796
7828
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7797
- await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength });
7829
+ await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength, zip64Entries });
7798
7830
  }
7799
7831
 
7800
7832
  function createDirectoryRecords(files) {
7801
7833
  let directoryDataLength = 0;
7834
+ let zip64Entries = false;
7802
7835
  for (const [, fileEntry] of files) {
7803
7836
  const {
7804
7837
  rawFilename,
@@ -7811,11 +7844,20 @@
7811
7844
  extendedTimestamp,
7812
7845
  extraFieldExtendedTimestampFlag,
7813
7846
  lastModDate,
7814
- zip64UncompressedSize,
7815
- zip64CompressedSize,
7847
+ zip64Enabled,
7816
7848
  uncompressedSize,
7817
7849
  compressedSize
7818
7850
  } = fileEntry;
7851
+ let { zip64UncompressedSize, zip64CompressedSize } = fileEntry;
7852
+ if (!zip64Enabled) {
7853
+ if (zip64UncompressedSize && uncompressedSize < MAX_32_BITS) {
7854
+ zip64UncompressedSize = fileEntry.zip64UncompressedSize = false;
7855
+ }
7856
+ if (zip64CompressedSize && compressedSize < MAX_32_BITS) {
7857
+ zip64CompressedSize = fileEntry.zip64CompressedSize = false;
7858
+ }
7859
+ }
7860
+ zip64Entries = zip64Entries || zip64UncompressedSize || zip64CompressedSize;
7819
7861
  const zip64Offset = fileEntry.offset >= MAX_32_BITS;
7820
7862
  const zip64DiskNumberStart = fileEntry.diskNumberStart >= MAX_16_BITS;
7821
7863
  let rawExtraFieldZip64;
@@ -7869,7 +7911,7 @@
7869
7911
  }
7870
7912
  directoryDataLength += CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
7871
7913
  }
7872
- return directoryDataLength;
7914
+ return { directoryDataLength, zip64Entries };
7873
7915
  }
7874
7916
 
7875
7917
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
@@ -7989,7 +8031,7 @@
7989
8031
 
7990
8032
  async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7991
8033
  const { writer } = zipWriter;
7992
- const { directoryStart, directoryEnd, signatureLength } = cdInfo;
8034
+ const { directoryStart, directoryEnd, signatureLength, zip64Entries } = cdInfo;
7993
8035
  let { directoryDataLength } = cdInfo;
7994
8036
  let fileEntriesLength = zipWriter.fileEntries.size;
7995
8037
  let diskNumber = directoryStart.diskNumber;
@@ -8009,6 +8051,8 @@
8009
8051
  } else {
8010
8052
  zip64 = true;
8011
8053
  }
8054
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
8055
+ zip64 = true;
8012
8056
  }
8013
8057
  const endOfdirectoryRecord = createRecordWriter(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8014
8058
  if (exceedsAvailableSize(writer, getLength(endOfdirectoryRecord.array) + commentLength)) {
@@ -8512,7 +8556,7 @@
8512
8556
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8513
8557
  */
8514
8558
 
8515
- const VERSION = "2.11.2";
8559
+ const VERSION = "2.11.4";
8516
8560
 
8517
8561
  /*
8518
8562
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9444,6 +9488,7 @@
9444
9488
  exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
9445
9489
  exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
9446
9490
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
9491
+ exports.ERR_INVALID_READER = ERR_INVALID_READER;
9447
9492
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
9448
9493
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
9449
9494
  exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;
@@ -9470,6 +9515,7 @@
9470
9515
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
9471
9516
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
9472
9517
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
9518
+ exports.ERR_UNSUPPORTED_SPLIT_USDZ = ERR_UNSUPPORTED_SPLIT_USDZ;
9473
9519
  exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
9474
9520
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
9475
9521
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;