@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.
@@ -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);
@@ -3756,11 +3764,13 @@
3756
3764
  const reader = this;
3757
3765
  const { sourceBlob, size } = reader;
3758
3766
  const { offset = 0, size: readSize = size - offset } = options || {};
3759
- if (!offset && readSize >= size) {
3760
- return toCompatibleReadable(sourceBlob.stream());
3761
- }
3762
- if (blobSliceReliable) {
3763
- return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
3767
+ if (typeof sourceBlob.stream == FUNCTION_TYPE) {
3768
+ if (!offset && readSize >= size) {
3769
+ return toCompatibleReadable(sourceBlob.stream());
3770
+ }
3771
+ if (blobSliceReliable) {
3772
+ return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
3773
+ }
3764
3774
  }
3765
3775
  return super.createReadable(options);
3766
3776
  }
@@ -5176,27 +5186,28 @@
5176
5186
  const { done, value } = await gen.next();
5177
5187
  if (done)
5178
5188
  return controller.close();
5179
- const chunk = {
5180
- ...value,
5181
- readable: (function () {
5182
- const { readable, writable } = new TransformStream();
5183
- if (value.getData) {
5184
- getData();
5185
- return readable;
5186
- }
5189
+ const entryReadable = (function () {
5190
+ const { readable, writable } = new TransformStream();
5191
+ if (value.getData) {
5192
+ getData();
5193
+ return readable;
5194
+ }
5187
5195
 
5188
- async function getData() {
5196
+ async function getData() {
5197
+ try {
5198
+ await value.getData(writable);
5199
+ } catch (error) {
5189
5200
  try {
5190
- await value.getData(writable);
5191
- } catch (error) {
5192
- try {
5193
- await writable.abort(error);
5194
- } catch {
5195
- // ignored
5196
- }
5201
+ await writable.abort(error);
5202
+ } catch {
5203
+ // ignored
5197
5204
  }
5198
5205
  }
5199
- })()
5206
+ }
5207
+ })();
5208
+ const chunk = {
5209
+ ...value,
5210
+ readable: entryReadable
5200
5211
  };
5201
5212
  delete chunk.getData;
5202
5213
  controller.enqueue(chunk);
@@ -5342,6 +5353,7 @@
5342
5353
  const size = compressedSize;
5343
5354
  const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
5344
5355
  const signal = checkSignalOption(getOptionValue$1(zipEntry, options, OPTION_SIGNAL));
5356
+ throwIfAborted(signal);
5345
5357
  const checkPasswordOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
5346
5358
  let checkOverlappingEntry = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
5347
5359
  const checkOverlappingEntryOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY_ONLY);
@@ -6248,6 +6260,7 @@
6248
6260
  const ERR_INVALID_VERSION = "Version exceeds 65535";
6249
6261
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
6250
6262
  const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
6263
+ const ERR_UNSUPPORTED_SPLIT_USDZ = "Split zip files are not supported in USDZ files";
6251
6264
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
6252
6265
  const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
6253
6266
  const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
@@ -6262,6 +6275,7 @@
6262
6275
  const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
6263
6276
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
6264
6277
  const ERR_UNDEFINED_READER = "Undefined reader";
6278
+ const ERR_INVALID_READER = "Invalid reader (must be a Reader instance, a ReadableStream instance, or an object with a 'readable' property)";
6265
6279
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
6266
6280
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
6267
6281
  const ERR_INVALID_GID = "Invalid gid (must be integer 0..2^32-1)";
@@ -6293,6 +6307,9 @@
6293
6307
  const addSplitZipSignature =
6294
6308
  availableSize > 0 && availableSize !== INFINITY_VALUE &&
6295
6309
  maxSize > 0 && maxSize !== INFINITY_VALUE;
6310
+ if (addSplitZipSignature && options[OPTION_USDZ]) {
6311
+ throw new Error(ERR_UNSUPPORTED_SPLIT_USDZ);
6312
+ }
6296
6313
  Object.assign(this, {
6297
6314
  writer,
6298
6315
  addSplitZipSignature,
@@ -6408,6 +6425,7 @@
6408
6425
  }
6409
6426
  const { offset, diskNumberStart } = entryPositions.get(entry);
6410
6427
  Object.assign(entry, {
6428
+ zip64Enabled: true,
6411
6429
  zip64UncompressedSize,
6412
6430
  zip64CompressedSize,
6413
6431
  offset,
@@ -6866,6 +6884,7 @@
6866
6884
  const createTempStream = getFunctionOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
6867
6885
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, true);
6868
6886
  const signal = checkSignalOption(getOptionValue(zipWriter, options, OPTION_SIGNAL));
6887
+ throwIfAborted(signal);
6869
6888
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
6870
6889
  const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
6871
6890
  const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
@@ -6983,6 +7002,9 @@
6983
7002
  if (reader) {
6984
7003
  reader = new GenericReader(reader);
6985
7004
  await initStream(reader);
7005
+ if (!reader.readable && !reader.readUint8Array) {
7006
+ throw new Error(ERR_INVALID_READER);
7007
+ }
6986
7008
  ({ size: contentSize } = reader);
6987
7009
  }
6988
7010
  return Object.assign({ reader }, resolveEntrySizes(zipWriter, Boolean(reader), contentSize, metadata, options));
@@ -6993,6 +7015,7 @@
6993
7015
  let { dataDescriptor, zip64, level, compressionMethod } = metadata;
6994
7016
  let maximumCompressedSize = 0;
6995
7017
  let uncompressedSize = 0;
7018
+ let unknownSize = false;
6996
7019
  if (passThrough && hasContent) {
6997
7020
  uncompressedSize = options[PROPERTY_NAME_UNCOMPRESSED_SIZE];
6998
7021
  if (uncompressedSize === UNDEFINED_VALUE) {
@@ -7018,8 +7041,8 @@
7018
7041
  if (contentSize === UNDEFINED_VALUE) {
7019
7042
  dataDescriptor = true;
7020
7043
  if (zip64 || zip64 === UNDEFINED_VALUE) {
7021
- zip64 = true;
7022
- uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
7044
+ zip64 = unknownSize = true;
7045
+ maximumCompressedSize = MAX_32_BITS + 1;
7023
7046
  }
7024
7047
  } else {
7025
7048
  options.uncompressedSize = uncompressedSize = contentSize;
@@ -7034,7 +7057,7 @@
7034
7057
  if (emptyEntry && !zipCrypto && getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR) === UNDEFINED_VALUE) {
7035
7058
  dataDescriptor = false;
7036
7059
  }
7037
- const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
7060
+ const zip64UncompressedSize = zip64Enabled || unknownSize || uncompressedSize >= MAX_32_BITS;
7038
7061
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
7039
7062
  if (zip64UncompressedSize || zip64CompressedSize) {
7040
7063
  if (zip64 === false) {
@@ -7050,6 +7073,8 @@
7050
7073
  dataDescriptor,
7051
7074
  emptyEntry,
7052
7075
  zip64,
7076
+ zip64Enabled,
7077
+ unknownSize,
7053
7078
  zip64UncompressedSize,
7054
7079
  zip64CompressedSize,
7055
7080
  uncompressedSize,
@@ -7248,6 +7273,7 @@
7248
7273
  rawPassword,
7249
7274
  level,
7250
7275
  zip64,
7276
+ zip64Enabled,
7251
7277
  zip64UncompressedSize,
7252
7278
  zip64CompressedSize,
7253
7279
  zipCrypto,
@@ -7288,6 +7314,7 @@
7288
7314
  lockFileEntry,
7289
7315
  versionMadeBy,
7290
7316
  zip64,
7317
+ zip64Enabled,
7291
7318
  directory: Boolean(directory),
7292
7319
  executable: Boolean(executable),
7293
7320
  filenameUTF8: true,
@@ -7431,13 +7458,14 @@
7431
7458
  zip64UncompressedSize,
7432
7459
  zip64CompressedSize,
7433
7460
  uncompressedSize,
7461
+ unknownSize,
7434
7462
  crc32
7435
7463
  } = options;
7436
7464
  let { version, compressionMethod } = options;
7437
7465
  const compressed = !directory && isCompressed(compressionMethod, level);
7438
7466
  let rawLocalExtraFieldZip64;
7439
7467
  const uncompressedFile = passThrough || !compressed;
7440
- const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
7468
+ const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || (uncompressedFile && !unknownSize)));
7441
7469
  const writeLocalExtraFieldZip64 = zip64ExtraFieldComplete || (zip64 && dataDescriptor && (zip64UncompressedSize || zip64CompressedSize));
7442
7470
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
7443
7471
  const length = 4 + 16;
@@ -7571,6 +7599,10 @@
7571
7599
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
7572
7600
  }
7573
7601
  const dosLastModDate = new Date(Math.ceil(Math.floor(lastModDate.getTime() / 1000) / 2) * 2000);
7602
+ const clampedLastModDate = dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate;
7603
+ const storedLastModDate = getLength(rawExtraFieldExtendedTimestamp) ?
7604
+ new Date(getTimeUnix(lastModDate) * 1000) :
7605
+ getLength(rawExtraFieldNTFS) ? lastModDate : clampedLastModDate;
7574
7606
  const {
7575
7607
  headerArray,
7576
7608
  headerView,
@@ -7580,7 +7612,7 @@
7580
7612
  bitFlag: getBitFlag(level, useUnicodeFileNames, dataDescriptor, encrypted, compressionMethod),
7581
7613
  compressionMethod,
7582
7614
  uncompressedSize,
7583
- lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
7615
+ lastModDate: clampedLastModDate,
7584
7616
  rawLastModDate: rawLastModDateOption,
7585
7617
  rawFilename,
7586
7618
  zip64CompressedSize,
@@ -7615,7 +7647,7 @@
7615
7647
  localHeaderView,
7616
7648
  headerArray,
7617
7649
  headerView,
7618
- lastModDate,
7650
+ lastModDate: storedLastModDate,
7619
7651
  rawLastModDate,
7620
7652
  encrypted,
7621
7653
  compressed,
@@ -7787,14 +7819,15 @@
7787
7819
 
7788
7820
 
7789
7821
  async function closeFile(zipWriter, comment, options) {
7790
- const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7822
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(zipWriter.fileEntries);
7791
7823
  const { directoryStart, directoryEnd, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7792
7824
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7793
- await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength });
7825
+ await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength, zip64Entries });
7794
7826
  }
7795
7827
 
7796
7828
  function createDirectoryRecords(files) {
7797
7829
  let directoryDataLength = 0;
7830
+ let zip64Entries = false;
7798
7831
  for (const [, fileEntry] of files) {
7799
7832
  const {
7800
7833
  rawFilename,
@@ -7807,11 +7840,20 @@
7807
7840
  extendedTimestamp,
7808
7841
  extraFieldExtendedTimestampFlag,
7809
7842
  lastModDate,
7810
- zip64UncompressedSize,
7811
- zip64CompressedSize,
7843
+ zip64Enabled,
7812
7844
  uncompressedSize,
7813
7845
  compressedSize
7814
7846
  } = fileEntry;
7847
+ let { zip64UncompressedSize, zip64CompressedSize } = fileEntry;
7848
+ if (!zip64Enabled) {
7849
+ if (zip64UncompressedSize && uncompressedSize < MAX_32_BITS) {
7850
+ zip64UncompressedSize = fileEntry.zip64UncompressedSize = false;
7851
+ }
7852
+ if (zip64CompressedSize && compressedSize < MAX_32_BITS) {
7853
+ zip64CompressedSize = fileEntry.zip64CompressedSize = false;
7854
+ }
7855
+ }
7856
+ zip64Entries = zip64Entries || zip64UncompressedSize || zip64CompressedSize;
7815
7857
  const zip64Offset = fileEntry.offset >= MAX_32_BITS;
7816
7858
  const zip64DiskNumberStart = fileEntry.diskNumberStart >= MAX_16_BITS;
7817
7859
  let rawExtraFieldZip64;
@@ -7865,7 +7907,7 @@
7865
7907
  }
7866
7908
  directoryDataLength += CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
7867
7909
  }
7868
- return directoryDataLength;
7910
+ return { directoryDataLength, zip64Entries };
7869
7911
  }
7870
7912
 
7871
7913
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
@@ -7985,7 +8027,7 @@
7985
8027
 
7986
8028
  async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7987
8029
  const { writer } = zipWriter;
7988
- const { directoryStart, directoryEnd, signatureLength } = cdInfo;
8030
+ const { directoryStart, directoryEnd, signatureLength, zip64Entries } = cdInfo;
7989
8031
  let { directoryDataLength } = cdInfo;
7990
8032
  let fileEntriesLength = zipWriter.fileEntries.size;
7991
8033
  let diskNumber = directoryStart.diskNumber;
@@ -8005,6 +8047,8 @@
8005
8047
  } else {
8006
8048
  zip64 = true;
8007
8049
  }
8050
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
8051
+ zip64 = true;
8008
8052
  }
8009
8053
  const endOfdirectoryRecord = createRecordWriter(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8010
8054
  if (exceedsAvailableSize(writer, getLength(endOfdirectoryRecord.array) + commentLength)) {
@@ -8508,7 +8552,7 @@
8508
8552
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8509
8553
  */
8510
8554
 
8511
- const VERSION = "2.11.2";
8555
+ const VERSION = "2.11.4";
8512
8556
 
8513
8557
  /*
8514
8558
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9068,6 +9112,7 @@
9068
9112
  exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
9069
9113
  exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
9070
9114
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
9115
+ exports.ERR_INVALID_READER = ERR_INVALID_READER;
9071
9116
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
9072
9117
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
9073
9118
  exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;
@@ -9094,6 +9139,7 @@
9094
9139
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
9095
9140
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
9096
9141
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
9142
+ exports.ERR_UNSUPPORTED_SPLIT_USDZ = ERR_UNSUPPORTED_SPLIT_USDZ;
9097
9143
  exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
9098
9144
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
9099
9145
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;