@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
  /*
@@ -6268,6 +6268,7 @@
6268
6268
  const ERR_INVALID_VERSION = "Version exceeds 65535";
6269
6269
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
6270
6270
  const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
6271
+ const ERR_UNSUPPORTED_SPLIT_USDZ = "Split zip files are not supported in USDZ files";
6271
6272
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
6272
6273
  const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
6273
6274
  const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
@@ -6282,6 +6283,7 @@
6282
6283
  const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
6283
6284
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
6284
6285
  const ERR_UNDEFINED_READER = "Undefined reader";
6286
+ const ERR_INVALID_READER = "Invalid reader (must be a Reader instance, a ReadableStream instance, or an object with a 'readable' property)";
6285
6287
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
6286
6288
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
6287
6289
  const ERR_INVALID_GID = "Invalid gid (must be integer 0..2^32-1)";
@@ -6313,6 +6315,9 @@
6313
6315
  const addSplitZipSignature =
6314
6316
  availableSize > 0 && availableSize !== INFINITY_VALUE &&
6315
6317
  maxSize > 0 && maxSize !== INFINITY_VALUE;
6318
+ if (addSplitZipSignature && options[OPTION_USDZ]) {
6319
+ throw new Error(ERR_UNSUPPORTED_SPLIT_USDZ);
6320
+ }
6316
6321
  Object.assign(this, {
6317
6322
  writer,
6318
6323
  addSplitZipSignature,
@@ -6428,6 +6433,7 @@
6428
6433
  }
6429
6434
  const { offset, diskNumberStart } = entryPositions.get(entry);
6430
6435
  Object.assign(entry, {
6436
+ zip64Enabled: true,
6431
6437
  zip64UncompressedSize,
6432
6438
  zip64CompressedSize,
6433
6439
  offset,
@@ -7003,6 +7009,9 @@
7003
7009
  if (reader) {
7004
7010
  reader = new GenericReader(reader);
7005
7011
  await initStream(reader);
7012
+ if (!reader.readable && !reader.readUint8Array) {
7013
+ throw new Error(ERR_INVALID_READER);
7014
+ }
7006
7015
  ({ size: contentSize } = reader);
7007
7016
  }
7008
7017
  return Object.assign({ reader }, resolveEntrySizes(zipWriter, Boolean(reader), contentSize, metadata, options));
@@ -7013,6 +7022,7 @@
7013
7022
  let { dataDescriptor, zip64, level, compressionMethod } = metadata;
7014
7023
  let maximumCompressedSize = 0;
7015
7024
  let uncompressedSize = 0;
7025
+ let unknownSize = false;
7016
7026
  if (passThrough && hasContent) {
7017
7027
  uncompressedSize = options[PROPERTY_NAME_UNCOMPRESSED_SIZE];
7018
7028
  if (uncompressedSize === UNDEFINED_VALUE) {
@@ -7038,8 +7048,8 @@
7038
7048
  if (contentSize === UNDEFINED_VALUE) {
7039
7049
  dataDescriptor = true;
7040
7050
  if (zip64 || zip64 === UNDEFINED_VALUE) {
7041
- zip64 = true;
7042
- uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
7051
+ zip64 = unknownSize = true;
7052
+ maximumCompressedSize = MAX_32_BITS + 1;
7043
7053
  }
7044
7054
  } else {
7045
7055
  options.uncompressedSize = uncompressedSize = contentSize;
@@ -7054,7 +7064,7 @@
7054
7064
  if (emptyEntry && !zipCrypto && getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR) === UNDEFINED_VALUE) {
7055
7065
  dataDescriptor = false;
7056
7066
  }
7057
- const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
7067
+ const zip64UncompressedSize = zip64Enabled || unknownSize || uncompressedSize >= MAX_32_BITS;
7058
7068
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
7059
7069
  if (zip64UncompressedSize || zip64CompressedSize) {
7060
7070
  if (zip64 === false) {
@@ -7070,6 +7080,8 @@
7070
7080
  dataDescriptor,
7071
7081
  emptyEntry,
7072
7082
  zip64,
7083
+ zip64Enabled,
7084
+ unknownSize,
7073
7085
  zip64UncompressedSize,
7074
7086
  zip64CompressedSize,
7075
7087
  uncompressedSize,
@@ -7143,7 +7155,7 @@
7143
7155
  if (layoutDependsOnWriteOrder && !writeOrderGuaranteed) {
7144
7156
  throw new Error(ERR_UNDETERMINED_SIZE);
7145
7157
  }
7146
- const directoryDataLength = createDirectoryRecords(files);
7158
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(files);
7147
7159
  let zip64 = getOptionValue(zipWriter, writerOptions, PROPERTY_NAME_ZIP64);
7148
7160
  if (offset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || files.size >= MAX_16_BITS) {
7149
7161
  if (zip64 === false) {
@@ -7151,6 +7163,8 @@
7151
7163
  } else {
7152
7164
  zip64 = true;
7153
7165
  }
7166
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
7167
+ zip64 = true;
7154
7168
  }
7155
7169
  return offset - initialOffset + directoryDataLength + commentLength + (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
7156
7170
  }
@@ -7343,6 +7357,7 @@
7343
7357
  rawPassword,
7344
7358
  level,
7345
7359
  zip64,
7360
+ zip64Enabled,
7346
7361
  zip64UncompressedSize,
7347
7362
  zip64CompressedSize,
7348
7363
  zipCrypto,
@@ -7383,6 +7398,7 @@
7383
7398
  lockFileEntry,
7384
7399
  versionMadeBy,
7385
7400
  zip64,
7401
+ zip64Enabled,
7386
7402
  directory: Boolean(directory),
7387
7403
  executable: Boolean(executable),
7388
7404
  filenameUTF8: true,
@@ -7526,13 +7542,14 @@
7526
7542
  zip64UncompressedSize,
7527
7543
  zip64CompressedSize,
7528
7544
  uncompressedSize,
7545
+ unknownSize,
7529
7546
  crc32
7530
7547
  } = options;
7531
7548
  let { version, compressionMethod } = options;
7532
7549
  const compressed = !directory && isCompressed(compressionMethod, level);
7533
7550
  let rawLocalExtraFieldZip64;
7534
7551
  const uncompressedFile = passThrough || !compressed;
7535
- const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
7552
+ const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || (uncompressedFile && !unknownSize)));
7536
7553
  const writeLocalExtraFieldZip64 = zip64ExtraFieldComplete || (zip64 && dataDescriptor && (zip64UncompressedSize || zip64CompressedSize));
7537
7554
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
7538
7555
  const length = 4 + 16;
@@ -7666,6 +7683,10 @@
7666
7683
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
7667
7684
  }
7668
7685
  const dosLastModDate = new Date(Math.ceil(Math.floor(lastModDate.getTime() / 1000) / 2) * 2000);
7686
+ const clampedLastModDate = dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate;
7687
+ const storedLastModDate = getLength(rawExtraFieldExtendedTimestamp) ?
7688
+ new Date(getTimeUnix(lastModDate) * 1000) :
7689
+ getLength(rawExtraFieldNTFS) ? lastModDate : clampedLastModDate;
7669
7690
  const {
7670
7691
  headerArray,
7671
7692
  headerView,
@@ -7675,7 +7696,7 @@
7675
7696
  bitFlag: getBitFlag(level, useUnicodeFileNames, dataDescriptor, encrypted, compressionMethod),
7676
7697
  compressionMethod,
7677
7698
  uncompressedSize,
7678
- lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
7699
+ lastModDate: clampedLastModDate,
7679
7700
  rawLastModDate: rawLastModDateOption,
7680
7701
  rawFilename,
7681
7702
  zip64CompressedSize,
@@ -7710,7 +7731,7 @@
7710
7731
  localHeaderView,
7711
7732
  headerArray,
7712
7733
  headerView,
7713
- lastModDate,
7734
+ lastModDate: storedLastModDate,
7714
7735
  rawLastModDate,
7715
7736
  encrypted,
7716
7737
  compressed,
@@ -7882,14 +7903,15 @@
7882
7903
 
7883
7904
 
7884
7905
  async function closeFile(zipWriter, comment, options) {
7885
- const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7906
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(zipWriter.fileEntries);
7886
7907
  const { directoryStart, directoryEnd, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7887
7908
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7888
- await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength });
7909
+ await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength, zip64Entries });
7889
7910
  }
7890
7911
 
7891
7912
  function createDirectoryRecords(files) {
7892
7913
  let directoryDataLength = 0;
7914
+ let zip64Entries = false;
7893
7915
  for (const [, fileEntry] of files) {
7894
7916
  const {
7895
7917
  rawFilename,
@@ -7902,11 +7924,20 @@
7902
7924
  extendedTimestamp,
7903
7925
  extraFieldExtendedTimestampFlag,
7904
7926
  lastModDate,
7905
- zip64UncompressedSize,
7906
- zip64CompressedSize,
7927
+ zip64Enabled,
7907
7928
  uncompressedSize,
7908
7929
  compressedSize
7909
7930
  } = fileEntry;
7931
+ let { zip64UncompressedSize, zip64CompressedSize } = fileEntry;
7932
+ if (!zip64Enabled) {
7933
+ if (zip64UncompressedSize && uncompressedSize < MAX_32_BITS) {
7934
+ zip64UncompressedSize = fileEntry.zip64UncompressedSize = false;
7935
+ }
7936
+ if (zip64CompressedSize && compressedSize < MAX_32_BITS) {
7937
+ zip64CompressedSize = fileEntry.zip64CompressedSize = false;
7938
+ }
7939
+ }
7940
+ zip64Entries = zip64Entries || zip64UncompressedSize || zip64CompressedSize;
7910
7941
  const zip64Offset = fileEntry.offset >= MAX_32_BITS;
7911
7942
  const zip64DiskNumberStart = fileEntry.diskNumberStart >= MAX_16_BITS;
7912
7943
  let rawExtraFieldZip64;
@@ -7960,7 +7991,7 @@
7960
7991
  }
7961
7992
  directoryDataLength += CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
7962
7993
  }
7963
- return directoryDataLength;
7994
+ return { directoryDataLength, zip64Entries };
7964
7995
  }
7965
7996
 
7966
7997
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
@@ -8080,7 +8111,7 @@
8080
8111
 
8081
8112
  async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
8082
8113
  const { writer } = zipWriter;
8083
- const { directoryStart, directoryEnd, signatureLength } = cdInfo;
8114
+ const { directoryStart, directoryEnd, signatureLength, zip64Entries } = cdInfo;
8084
8115
  let { directoryDataLength } = cdInfo;
8085
8116
  let fileEntriesLength = zipWriter.fileEntries.size;
8086
8117
  let diskNumber = directoryStart.diskNumber;
@@ -8100,6 +8131,8 @@
8100
8131
  } else {
8101
8132
  zip64 = true;
8102
8133
  }
8134
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
8135
+ zip64 = true;
8103
8136
  }
8104
8137
  const endOfdirectoryRecord = createRecordWriter(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8105
8138
  if (exceedsAvailableSize(writer, getLength(endOfdirectoryRecord.array) + commentLength)) {
@@ -8603,7 +8636,7 @@
8603
8636
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8604
8637
  */
8605
8638
 
8606
- const VERSION = "2.11.2";
8639
+ const VERSION = "2.11.3";
8607
8640
 
8608
8641
  /*
8609
8642
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9627,12 +9660,14 @@
9627
9660
  if (options.bufferedWrite === UNDEFINED_VALUE) {
9628
9661
  options.bufferedWrite = true;
9629
9662
  }
9630
- const entries = zipEntry.getChildren({ recursive: true }).filter(child => !isImplicitDirectory(child)).map(child => {
9663
+ const children = zipEntry.getChildren({ recursive: true });
9664
+ const entries = children.filter(child => !isImplicitDirectory(child)).map(child => {
9631
9665
  const { name, entryOptions } = getChildEntryOptions(child, zipEntry, options);
9632
9666
  return { name, size: child.directory ? 0 : getDeterminedSize(child, isPassThrough(child, options)), options: entryOptions };
9633
9667
  });
9634
9668
  const writeOrderGuaranteed = !options.bufferedWrite ||
9635
- (entries.every(entry => entry.options.keepOrder !== false) && zipEntry.children.every(child => !child.children.length));
9669
+ (entries.every(entry => entry.options.keepOrder !== false) &&
9670
+ children.every(child => isImplicitDirectory(child) || !child.children.length));
9636
9671
  return getEntriesSize(options, entries, writeOrderGuaranteed, options.globalComment);
9637
9672
  }
9638
9673
 
@@ -10661,6 +10696,7 @@
10661
10696
  exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
10662
10697
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
10663
10698
  exports.ERR_INVALID_PASS_THROUGH = ERR_INVALID_PASS_THROUGH;
10699
+ exports.ERR_INVALID_READER = ERR_INVALID_READER;
10664
10700
  exports.ERR_INVALID_READER_OPTIONS = ERR_INVALID_READER_OPTIONS;
10665
10701
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
10666
10702
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
@@ -10689,6 +10725,7 @@
10689
10725
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
10690
10726
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
10691
10727
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
10728
+ exports.ERR_UNSUPPORTED_SPLIT_USDZ = ERR_UNSUPPORTED_SPLIT_USDZ;
10692
10729
  exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
10693
10730
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
10694
10731
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;