@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.
package/dist/zip-core.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
  /*
@@ -6246,6 +6246,7 @@
6246
6246
  const ERR_INVALID_VERSION = "Version exceeds 65535";
6247
6247
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
6248
6248
  const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
6249
+ const ERR_UNSUPPORTED_SPLIT_USDZ = "Split zip files are not supported in USDZ files";
6249
6250
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
6250
6251
  const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
6251
6252
  const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
@@ -6260,6 +6261,7 @@
6260
6261
  const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
6261
6262
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
6262
6263
  const ERR_UNDEFINED_READER = "Undefined reader";
6264
+ const ERR_INVALID_READER = "Invalid reader (must be a Reader instance, a ReadableStream instance, or an object with a 'readable' property)";
6263
6265
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
6264
6266
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
6265
6267
  const ERR_INVALID_GID = "Invalid gid (must be integer 0..2^32-1)";
@@ -6291,6 +6293,9 @@
6291
6293
  const addSplitZipSignature =
6292
6294
  availableSize > 0 && availableSize !== INFINITY_VALUE &&
6293
6295
  maxSize > 0 && maxSize !== INFINITY_VALUE;
6296
+ if (addSplitZipSignature && options[OPTION_USDZ]) {
6297
+ throw new Error(ERR_UNSUPPORTED_SPLIT_USDZ);
6298
+ }
6294
6299
  Object.assign(this, {
6295
6300
  writer,
6296
6301
  addSplitZipSignature,
@@ -6406,6 +6411,7 @@
6406
6411
  }
6407
6412
  const { offset, diskNumberStart } = entryPositions.get(entry);
6408
6413
  Object.assign(entry, {
6414
+ zip64Enabled: true,
6409
6415
  zip64UncompressedSize,
6410
6416
  zip64CompressedSize,
6411
6417
  offset,
@@ -6981,6 +6987,9 @@
6981
6987
  if (reader) {
6982
6988
  reader = new GenericReader(reader);
6983
6989
  await initStream(reader);
6990
+ if (!reader.readable && !reader.readUint8Array) {
6991
+ throw new Error(ERR_INVALID_READER);
6992
+ }
6984
6993
  ({ size: contentSize } = reader);
6985
6994
  }
6986
6995
  return Object.assign({ reader }, resolveEntrySizes(zipWriter, Boolean(reader), contentSize, metadata, options));
@@ -6991,6 +7000,7 @@
6991
7000
  let { dataDescriptor, zip64, level, compressionMethod } = metadata;
6992
7001
  let maximumCompressedSize = 0;
6993
7002
  let uncompressedSize = 0;
7003
+ let unknownSize = false;
6994
7004
  if (passThrough && hasContent) {
6995
7005
  uncompressedSize = options[PROPERTY_NAME_UNCOMPRESSED_SIZE];
6996
7006
  if (uncompressedSize === UNDEFINED_VALUE) {
@@ -7016,8 +7026,8 @@
7016
7026
  if (contentSize === UNDEFINED_VALUE) {
7017
7027
  dataDescriptor = true;
7018
7028
  if (zip64 || zip64 === UNDEFINED_VALUE) {
7019
- zip64 = true;
7020
- uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
7029
+ zip64 = unknownSize = true;
7030
+ maximumCompressedSize = MAX_32_BITS + 1;
7021
7031
  }
7022
7032
  } else {
7023
7033
  options.uncompressedSize = uncompressedSize = contentSize;
@@ -7032,7 +7042,7 @@
7032
7042
  if (emptyEntry && !zipCrypto && getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR) === UNDEFINED_VALUE) {
7033
7043
  dataDescriptor = false;
7034
7044
  }
7035
- const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
7045
+ const zip64UncompressedSize = zip64Enabled || unknownSize || uncompressedSize >= MAX_32_BITS;
7036
7046
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
7037
7047
  if (zip64UncompressedSize || zip64CompressedSize) {
7038
7048
  if (zip64 === false) {
@@ -7048,6 +7058,8 @@
7048
7058
  dataDescriptor,
7049
7059
  emptyEntry,
7050
7060
  zip64,
7061
+ zip64Enabled,
7062
+ unknownSize,
7051
7063
  zip64UncompressedSize,
7052
7064
  zip64CompressedSize,
7053
7065
  uncompressedSize,
@@ -7246,6 +7258,7 @@
7246
7258
  rawPassword,
7247
7259
  level,
7248
7260
  zip64,
7261
+ zip64Enabled,
7249
7262
  zip64UncompressedSize,
7250
7263
  zip64CompressedSize,
7251
7264
  zipCrypto,
@@ -7286,6 +7299,7 @@
7286
7299
  lockFileEntry,
7287
7300
  versionMadeBy,
7288
7301
  zip64,
7302
+ zip64Enabled,
7289
7303
  directory: Boolean(directory),
7290
7304
  executable: Boolean(executable),
7291
7305
  filenameUTF8: true,
@@ -7429,13 +7443,14 @@
7429
7443
  zip64UncompressedSize,
7430
7444
  zip64CompressedSize,
7431
7445
  uncompressedSize,
7446
+ unknownSize,
7432
7447
  crc32
7433
7448
  } = options;
7434
7449
  let { version, compressionMethod } = options;
7435
7450
  const compressed = !directory && isCompressed(compressionMethod, level);
7436
7451
  let rawLocalExtraFieldZip64;
7437
7452
  const uncompressedFile = passThrough || !compressed;
7438
- const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
7453
+ const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || (uncompressedFile && !unknownSize)));
7439
7454
  const writeLocalExtraFieldZip64 = zip64ExtraFieldComplete || (zip64 && dataDescriptor && (zip64UncompressedSize || zip64CompressedSize));
7440
7455
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
7441
7456
  const length = 4 + 16;
@@ -7569,6 +7584,10 @@
7569
7584
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
7570
7585
  }
7571
7586
  const dosLastModDate = new Date(Math.ceil(Math.floor(lastModDate.getTime() / 1000) / 2) * 2000);
7587
+ const clampedLastModDate = dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate;
7588
+ const storedLastModDate = getLength(rawExtraFieldExtendedTimestamp) ?
7589
+ new Date(getTimeUnix(lastModDate) * 1000) :
7590
+ getLength(rawExtraFieldNTFS) ? lastModDate : clampedLastModDate;
7572
7591
  const {
7573
7592
  headerArray,
7574
7593
  headerView,
@@ -7578,7 +7597,7 @@
7578
7597
  bitFlag: getBitFlag(level, useUnicodeFileNames, dataDescriptor, encrypted, compressionMethod),
7579
7598
  compressionMethod,
7580
7599
  uncompressedSize,
7581
- lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
7600
+ lastModDate: clampedLastModDate,
7582
7601
  rawLastModDate: rawLastModDateOption,
7583
7602
  rawFilename,
7584
7603
  zip64CompressedSize,
@@ -7613,7 +7632,7 @@
7613
7632
  localHeaderView,
7614
7633
  headerArray,
7615
7634
  headerView,
7616
- lastModDate,
7635
+ lastModDate: storedLastModDate,
7617
7636
  rawLastModDate,
7618
7637
  encrypted,
7619
7638
  compressed,
@@ -7785,14 +7804,15 @@
7785
7804
 
7786
7805
 
7787
7806
  async function closeFile(zipWriter, comment, options) {
7788
- const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7807
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(zipWriter.fileEntries);
7789
7808
  const { directoryStart, directoryEnd, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7790
7809
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7791
- await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength });
7810
+ await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength, zip64Entries });
7792
7811
  }
7793
7812
 
7794
7813
  function createDirectoryRecords(files) {
7795
7814
  let directoryDataLength = 0;
7815
+ let zip64Entries = false;
7796
7816
  for (const [, fileEntry] of files) {
7797
7817
  const {
7798
7818
  rawFilename,
@@ -7805,11 +7825,20 @@
7805
7825
  extendedTimestamp,
7806
7826
  extraFieldExtendedTimestampFlag,
7807
7827
  lastModDate,
7808
- zip64UncompressedSize,
7809
- zip64CompressedSize,
7828
+ zip64Enabled,
7810
7829
  uncompressedSize,
7811
7830
  compressedSize
7812
7831
  } = fileEntry;
7832
+ let { zip64UncompressedSize, zip64CompressedSize } = fileEntry;
7833
+ if (!zip64Enabled) {
7834
+ if (zip64UncompressedSize && uncompressedSize < MAX_32_BITS) {
7835
+ zip64UncompressedSize = fileEntry.zip64UncompressedSize = false;
7836
+ }
7837
+ if (zip64CompressedSize && compressedSize < MAX_32_BITS) {
7838
+ zip64CompressedSize = fileEntry.zip64CompressedSize = false;
7839
+ }
7840
+ }
7841
+ zip64Entries = zip64Entries || zip64UncompressedSize || zip64CompressedSize;
7813
7842
  const zip64Offset = fileEntry.offset >= MAX_32_BITS;
7814
7843
  const zip64DiskNumberStart = fileEntry.diskNumberStart >= MAX_16_BITS;
7815
7844
  let rawExtraFieldZip64;
@@ -7863,7 +7892,7 @@
7863
7892
  }
7864
7893
  directoryDataLength += CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
7865
7894
  }
7866
- return directoryDataLength;
7895
+ return { directoryDataLength, zip64Entries };
7867
7896
  }
7868
7897
 
7869
7898
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
@@ -7983,7 +8012,7 @@
7983
8012
 
7984
8013
  async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7985
8014
  const { writer } = zipWriter;
7986
- const { directoryStart, directoryEnd, signatureLength } = cdInfo;
8015
+ const { directoryStart, directoryEnd, signatureLength, zip64Entries } = cdInfo;
7987
8016
  let { directoryDataLength } = cdInfo;
7988
8017
  let fileEntriesLength = zipWriter.fileEntries.size;
7989
8018
  let diskNumber = directoryStart.diskNumber;
@@ -8003,6 +8032,8 @@
8003
8032
  } else {
8004
8033
  zip64 = true;
8005
8034
  }
8035
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
8036
+ zip64 = true;
8006
8037
  }
8007
8038
  const endOfdirectoryRecord = createRecordWriter(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8008
8039
  if (exceedsAvailableSize(writer, getLength(endOfdirectoryRecord.array) + commentLength)) {
@@ -8506,7 +8537,7 @@
8506
8537
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8507
8538
  */
8508
8539
 
8509
- const VERSION = "2.11.2";
8540
+ const VERSION = "2.11.3";
8510
8541
 
8511
8542
  /*
8512
8543
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -8997,6 +9028,7 @@
8997
9028
  exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
8998
9029
  exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
8999
9030
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
9031
+ exports.ERR_INVALID_READER = ERR_INVALID_READER;
9000
9032
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
9001
9033
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
9002
9034
  exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;
@@ -9023,6 +9055,7 @@
9023
9055
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
9024
9056
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
9025
9057
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
9058
+ exports.ERR_UNSUPPORTED_SPLIT_USDZ = ERR_UNSUPPORTED_SPLIT_USDZ;
9026
9059
  exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
9027
9060
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
9028
9061
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;