@zip.js/zip.js 2.11.2 → 2.11.3

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
  /*
@@ -6248,6 +6248,7 @@
6248
6248
  const ERR_INVALID_VERSION = "Version exceeds 65535";
6249
6249
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
6250
6250
  const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
6251
+ const ERR_UNSUPPORTED_SPLIT_USDZ = "Split zip files are not supported in USDZ files";
6251
6252
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
6252
6253
  const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
6253
6254
  const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
@@ -6262,6 +6263,7 @@
6262
6263
  const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
6263
6264
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
6264
6265
  const ERR_UNDEFINED_READER = "Undefined reader";
6266
+ const ERR_INVALID_READER = "Invalid reader (must be a Reader instance, a ReadableStream instance, or an object with a 'readable' property)";
6265
6267
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
6266
6268
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
6267
6269
  const ERR_INVALID_GID = "Invalid gid (must be integer 0..2^32-1)";
@@ -6293,6 +6295,9 @@
6293
6295
  const addSplitZipSignature =
6294
6296
  availableSize > 0 && availableSize !== INFINITY_VALUE &&
6295
6297
  maxSize > 0 && maxSize !== INFINITY_VALUE;
6298
+ if (addSplitZipSignature && options[OPTION_USDZ]) {
6299
+ throw new Error(ERR_UNSUPPORTED_SPLIT_USDZ);
6300
+ }
6296
6301
  Object.assign(this, {
6297
6302
  writer,
6298
6303
  addSplitZipSignature,
@@ -6408,6 +6413,7 @@
6408
6413
  }
6409
6414
  const { offset, diskNumberStart } = entryPositions.get(entry);
6410
6415
  Object.assign(entry, {
6416
+ zip64Enabled: true,
6411
6417
  zip64UncompressedSize,
6412
6418
  zip64CompressedSize,
6413
6419
  offset,
@@ -6983,6 +6989,9 @@
6983
6989
  if (reader) {
6984
6990
  reader = new GenericReader(reader);
6985
6991
  await initStream(reader);
6992
+ if (!reader.readable && !reader.readUint8Array) {
6993
+ throw new Error(ERR_INVALID_READER);
6994
+ }
6986
6995
  ({ size: contentSize } = reader);
6987
6996
  }
6988
6997
  return Object.assign({ reader }, resolveEntrySizes(zipWriter, Boolean(reader), contentSize, metadata, options));
@@ -6993,6 +7002,7 @@
6993
7002
  let { dataDescriptor, zip64, level, compressionMethod } = metadata;
6994
7003
  let maximumCompressedSize = 0;
6995
7004
  let uncompressedSize = 0;
7005
+ let unknownSize = false;
6996
7006
  if (passThrough && hasContent) {
6997
7007
  uncompressedSize = options[PROPERTY_NAME_UNCOMPRESSED_SIZE];
6998
7008
  if (uncompressedSize === UNDEFINED_VALUE) {
@@ -7018,8 +7028,8 @@
7018
7028
  if (contentSize === UNDEFINED_VALUE) {
7019
7029
  dataDescriptor = true;
7020
7030
  if (zip64 || zip64 === UNDEFINED_VALUE) {
7021
- zip64 = true;
7022
- uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
7031
+ zip64 = unknownSize = true;
7032
+ maximumCompressedSize = MAX_32_BITS + 1;
7023
7033
  }
7024
7034
  } else {
7025
7035
  options.uncompressedSize = uncompressedSize = contentSize;
@@ -7034,7 +7044,7 @@
7034
7044
  if (emptyEntry && !zipCrypto && getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR) === UNDEFINED_VALUE) {
7035
7045
  dataDescriptor = false;
7036
7046
  }
7037
- const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
7047
+ const zip64UncompressedSize = zip64Enabled || unknownSize || uncompressedSize >= MAX_32_BITS;
7038
7048
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
7039
7049
  if (zip64UncompressedSize || zip64CompressedSize) {
7040
7050
  if (zip64 === false) {
@@ -7050,6 +7060,8 @@
7050
7060
  dataDescriptor,
7051
7061
  emptyEntry,
7052
7062
  zip64,
7063
+ zip64Enabled,
7064
+ unknownSize,
7053
7065
  zip64UncompressedSize,
7054
7066
  zip64CompressedSize,
7055
7067
  uncompressedSize,
@@ -7248,6 +7260,7 @@
7248
7260
  rawPassword,
7249
7261
  level,
7250
7262
  zip64,
7263
+ zip64Enabled,
7251
7264
  zip64UncompressedSize,
7252
7265
  zip64CompressedSize,
7253
7266
  zipCrypto,
@@ -7288,6 +7301,7 @@
7288
7301
  lockFileEntry,
7289
7302
  versionMadeBy,
7290
7303
  zip64,
7304
+ zip64Enabled,
7291
7305
  directory: Boolean(directory),
7292
7306
  executable: Boolean(executable),
7293
7307
  filenameUTF8: true,
@@ -7431,13 +7445,14 @@
7431
7445
  zip64UncompressedSize,
7432
7446
  zip64CompressedSize,
7433
7447
  uncompressedSize,
7448
+ unknownSize,
7434
7449
  crc32
7435
7450
  } = options;
7436
7451
  let { version, compressionMethod } = options;
7437
7452
  const compressed = !directory && isCompressed(compressionMethod, level);
7438
7453
  let rawLocalExtraFieldZip64;
7439
7454
  const uncompressedFile = passThrough || !compressed;
7440
- const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
7455
+ const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || (uncompressedFile && !unknownSize)));
7441
7456
  const writeLocalExtraFieldZip64 = zip64ExtraFieldComplete || (zip64 && dataDescriptor && (zip64UncompressedSize || zip64CompressedSize));
7442
7457
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
7443
7458
  const length = 4 + 16;
@@ -7571,6 +7586,10 @@
7571
7586
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
7572
7587
  }
7573
7588
  const dosLastModDate = new Date(Math.ceil(Math.floor(lastModDate.getTime() / 1000) / 2) * 2000);
7589
+ const clampedLastModDate = dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate;
7590
+ const storedLastModDate = getLength(rawExtraFieldExtendedTimestamp) ?
7591
+ new Date(getTimeUnix(lastModDate) * 1000) :
7592
+ getLength(rawExtraFieldNTFS) ? lastModDate : clampedLastModDate;
7574
7593
  const {
7575
7594
  headerArray,
7576
7595
  headerView,
@@ -7580,7 +7599,7 @@
7580
7599
  bitFlag: getBitFlag(level, useUnicodeFileNames, dataDescriptor, encrypted, compressionMethod),
7581
7600
  compressionMethod,
7582
7601
  uncompressedSize,
7583
- lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
7602
+ lastModDate: clampedLastModDate,
7584
7603
  rawLastModDate: rawLastModDateOption,
7585
7604
  rawFilename,
7586
7605
  zip64CompressedSize,
@@ -7615,7 +7634,7 @@
7615
7634
  localHeaderView,
7616
7635
  headerArray,
7617
7636
  headerView,
7618
- lastModDate,
7637
+ lastModDate: storedLastModDate,
7619
7638
  rawLastModDate,
7620
7639
  encrypted,
7621
7640
  compressed,
@@ -7787,14 +7806,15 @@
7787
7806
 
7788
7807
 
7789
7808
  async function closeFile(zipWriter, comment, options) {
7790
- const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7809
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(zipWriter.fileEntries);
7791
7810
  const { directoryStart, directoryEnd, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7792
7811
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7793
- await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength });
7812
+ await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength, zip64Entries });
7794
7813
  }
7795
7814
 
7796
7815
  function createDirectoryRecords(files) {
7797
7816
  let directoryDataLength = 0;
7817
+ let zip64Entries = false;
7798
7818
  for (const [, fileEntry] of files) {
7799
7819
  const {
7800
7820
  rawFilename,
@@ -7807,11 +7827,20 @@
7807
7827
  extendedTimestamp,
7808
7828
  extraFieldExtendedTimestampFlag,
7809
7829
  lastModDate,
7810
- zip64UncompressedSize,
7811
- zip64CompressedSize,
7830
+ zip64Enabled,
7812
7831
  uncompressedSize,
7813
7832
  compressedSize
7814
7833
  } = fileEntry;
7834
+ let { zip64UncompressedSize, zip64CompressedSize } = fileEntry;
7835
+ if (!zip64Enabled) {
7836
+ if (zip64UncompressedSize && uncompressedSize < MAX_32_BITS) {
7837
+ zip64UncompressedSize = fileEntry.zip64UncompressedSize = false;
7838
+ }
7839
+ if (zip64CompressedSize && compressedSize < MAX_32_BITS) {
7840
+ zip64CompressedSize = fileEntry.zip64CompressedSize = false;
7841
+ }
7842
+ }
7843
+ zip64Entries = zip64Entries || zip64UncompressedSize || zip64CompressedSize;
7815
7844
  const zip64Offset = fileEntry.offset >= MAX_32_BITS;
7816
7845
  const zip64DiskNumberStart = fileEntry.diskNumberStart >= MAX_16_BITS;
7817
7846
  let rawExtraFieldZip64;
@@ -7865,7 +7894,7 @@
7865
7894
  }
7866
7895
  directoryDataLength += CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
7867
7896
  }
7868
- return directoryDataLength;
7897
+ return { directoryDataLength, zip64Entries };
7869
7898
  }
7870
7899
 
7871
7900
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
@@ -7985,7 +8014,7 @@
7985
8014
 
7986
8015
  async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7987
8016
  const { writer } = zipWriter;
7988
- const { directoryStart, directoryEnd, signatureLength } = cdInfo;
8017
+ const { directoryStart, directoryEnd, signatureLength, zip64Entries } = cdInfo;
7989
8018
  let { directoryDataLength } = cdInfo;
7990
8019
  let fileEntriesLength = zipWriter.fileEntries.size;
7991
8020
  let diskNumber = directoryStart.diskNumber;
@@ -8005,6 +8034,8 @@
8005
8034
  } else {
8006
8035
  zip64 = true;
8007
8036
  }
8037
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
8038
+ zip64 = true;
8008
8039
  }
8009
8040
  const endOfdirectoryRecord = createRecordWriter(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8010
8041
  if (exceedsAvailableSize(writer, getLength(endOfdirectoryRecord.array) + commentLength)) {
@@ -8508,7 +8539,7 @@
8508
8539
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8509
8540
  */
8510
8541
 
8511
- const VERSION = "2.11.2";
8542
+ const VERSION = "2.11.3";
8512
8543
 
8513
8544
  /*
8514
8545
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9068,6 +9099,7 @@
9068
9099
  exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
9069
9100
  exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
9070
9101
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
9102
+ exports.ERR_INVALID_READER = ERR_INVALID_READER;
9071
9103
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
9072
9104
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
9073
9105
  exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;
@@ -9094,6 +9126,7 @@
9094
9126
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
9095
9127
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
9096
9128
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
9129
+ exports.ERR_UNSUPPORTED_SPLIT_USDZ = ERR_UNSUPPORTED_SPLIT_USDZ;
9097
9130
  exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
9098
9131
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
9099
9132
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;