@zip.js/zip.js 2.11.1 → 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
  /*
@@ -3608,11 +3608,10 @@
3608
3608
  const data = await readUint8Array(reader, offset + chunkOffset, dataSize);
3609
3609
  if (data.length) {
3610
3610
  controller.enqueue(data);
3611
+ chunkOffset += data.length;
3611
3612
  }
3612
- if ((chunkOffset + chunkSize >= size) || (!data.length && dataSize)) {
3613
+ if ((size !== UNDEFINED_VALUE && chunkOffset >= size) || (!data.length && dataSize)) {
3613
3614
  controller.close();
3614
- } else {
3615
- chunkOffset += chunkSize;
3616
3615
  }
3617
3616
  }
3618
3617
  });
@@ -6247,6 +6246,7 @@
6247
6246
  const ERR_INVALID_VERSION = "Version exceeds 65535";
6248
6247
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
6249
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";
6250
6250
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
6251
6251
  const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
6252
6252
  const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
@@ -6261,6 +6261,7 @@
6261
6261
  const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
6262
6262
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
6263
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)";
6264
6265
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
6265
6266
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
6266
6267
  const ERR_INVALID_GID = "Invalid gid (must be integer 0..2^32-1)";
@@ -6292,6 +6293,9 @@
6292
6293
  const addSplitZipSignature =
6293
6294
  availableSize > 0 && availableSize !== INFINITY_VALUE &&
6294
6295
  maxSize > 0 && maxSize !== INFINITY_VALUE;
6296
+ if (addSplitZipSignature && options[OPTION_USDZ]) {
6297
+ throw new Error(ERR_UNSUPPORTED_SPLIT_USDZ);
6298
+ }
6295
6299
  Object.assign(this, {
6296
6300
  writer,
6297
6301
  addSplitZipSignature,
@@ -6303,6 +6307,7 @@
6303
6307
  pendingAddFileCalls: new Set(),
6304
6308
  pendingErrors: [],
6305
6309
  bufferedWrites: 0,
6310
+ directWrites: 0,
6306
6311
  lastFileEntry: UNDEFINED_VALUE
6307
6312
  });
6308
6313
  }
@@ -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,
@@ -7078,6 +7090,7 @@
7078
7090
  const usdz = zipWriter.options[OPTION_USDZ];
7079
7091
  let fileEntry = pendingFileEntry;
7080
7092
  let bufferedWrite;
7093
+ let directWrite;
7081
7094
  let releaseLockWriter;
7082
7095
  let writingBufferedEntryData;
7083
7096
  let writingEntryData;
@@ -7087,7 +7100,7 @@
7087
7100
  const lockPreviousFileEntry = keepOrder && previousFileEntry ? previousFileEntry.lockFileEntry : UNDEFINED_VALUE;
7088
7101
  fileEntries.set(name, fileEntry);
7089
7102
  try {
7090
- if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
7103
+ if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || zipWriter.directWrites || (!dataDescriptor && !emptyEntry)) {
7091
7104
  bufferedWrite = true;
7092
7105
  zipWriter.bufferedWrites++;
7093
7106
  if (options.createTempStream) {
@@ -7098,6 +7111,8 @@
7098
7111
  fileWriter.size = 0;
7099
7112
  await initStream(writer);
7100
7113
  } else {
7114
+ directWrite = true;
7115
+ zipWriter.directWrites++;
7101
7116
  fileWriter = writer;
7102
7117
  await lockPreviousFileEntry;
7103
7118
  await requestLockWriter();
@@ -7176,6 +7191,9 @@
7176
7191
  if (bufferedWrite) {
7177
7192
  zipWriter.bufferedWrites--;
7178
7193
  }
7194
+ if (directWrite) {
7195
+ zipWriter.directWrites--;
7196
+ }
7179
7197
  if (releaseLockFileEntry) {
7180
7198
  releaseLockFileEntry(lockPreviousFileEntry);
7181
7199
  }
@@ -7240,6 +7258,7 @@
7240
7258
  rawPassword,
7241
7259
  level,
7242
7260
  zip64,
7261
+ zip64Enabled,
7243
7262
  zip64UncompressedSize,
7244
7263
  zip64CompressedSize,
7245
7264
  zipCrypto,
@@ -7280,6 +7299,7 @@
7280
7299
  lockFileEntry,
7281
7300
  versionMadeBy,
7282
7301
  zip64,
7302
+ zip64Enabled,
7283
7303
  directory: Boolean(directory),
7284
7304
  executable: Boolean(executable),
7285
7305
  filenameUTF8: true,
@@ -7320,8 +7340,8 @@
7320
7340
  }
7321
7341
  const { writable } = writer;
7322
7342
  if (reader) {
7323
- const readable = toCompatibleReadable(createReadable(reader));
7324
7343
  const size = reader.size;
7344
+ const readable = toCompatibleReadable(createReadable(reader, { size }));
7325
7345
  const workerOptions = {
7326
7346
  options: {
7327
7347
  codecType: CODEC_DEFLATE,
@@ -7423,13 +7443,14 @@
7423
7443
  zip64UncompressedSize,
7424
7444
  zip64CompressedSize,
7425
7445
  uncompressedSize,
7446
+ unknownSize,
7426
7447
  crc32
7427
7448
  } = options;
7428
7449
  let { version, compressionMethod } = options;
7429
7450
  const compressed = !directory && isCompressed(compressionMethod, level);
7430
7451
  let rawLocalExtraFieldZip64;
7431
7452
  const uncompressedFile = passThrough || !compressed;
7432
- const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
7453
+ const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || (uncompressedFile && !unknownSize)));
7433
7454
  const writeLocalExtraFieldZip64 = zip64ExtraFieldComplete || (zip64 && dataDescriptor && (zip64UncompressedSize || zip64CompressedSize));
7434
7455
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
7435
7456
  const length = 4 + 16;
@@ -7563,6 +7584,10 @@
7563
7584
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
7564
7585
  }
7565
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;
7566
7591
  const {
7567
7592
  headerArray,
7568
7593
  headerView,
@@ -7572,7 +7597,7 @@
7572
7597
  bitFlag: getBitFlag(level, useUnicodeFileNames, dataDescriptor, encrypted, compressionMethod),
7573
7598
  compressionMethod,
7574
7599
  uncompressedSize,
7575
- lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
7600
+ lastModDate: clampedLastModDate,
7576
7601
  rawLastModDate: rawLastModDateOption,
7577
7602
  rawFilename,
7578
7603
  zip64CompressedSize,
@@ -7607,7 +7632,7 @@
7607
7632
  localHeaderView,
7608
7633
  headerArray,
7609
7634
  headerView,
7610
- lastModDate,
7635
+ lastModDate: storedLastModDate,
7611
7636
  rawLastModDate,
7612
7637
  encrypted,
7613
7638
  compressed,
@@ -7779,14 +7804,15 @@
7779
7804
 
7780
7805
 
7781
7806
  async function closeFile(zipWriter, comment, options) {
7782
- const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7807
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(zipWriter.fileEntries);
7783
7808
  const { directoryStart, directoryEnd, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7784
7809
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7785
- await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength });
7810
+ await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength, zip64Entries });
7786
7811
  }
7787
7812
 
7788
7813
  function createDirectoryRecords(files) {
7789
7814
  let directoryDataLength = 0;
7815
+ let zip64Entries = false;
7790
7816
  for (const [, fileEntry] of files) {
7791
7817
  const {
7792
7818
  rawFilename,
@@ -7799,11 +7825,20 @@
7799
7825
  extendedTimestamp,
7800
7826
  extraFieldExtendedTimestampFlag,
7801
7827
  lastModDate,
7802
- zip64UncompressedSize,
7803
- zip64CompressedSize,
7828
+ zip64Enabled,
7804
7829
  uncompressedSize,
7805
7830
  compressedSize
7806
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;
7807
7842
  const zip64Offset = fileEntry.offset >= MAX_32_BITS;
7808
7843
  const zip64DiskNumberStart = fileEntry.diskNumberStart >= MAX_16_BITS;
7809
7844
  let rawExtraFieldZip64;
@@ -7857,7 +7892,7 @@
7857
7892
  }
7858
7893
  directoryDataLength += CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
7859
7894
  }
7860
- return directoryDataLength;
7895
+ return { directoryDataLength, zip64Entries };
7861
7896
  }
7862
7897
 
7863
7898
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
@@ -7977,7 +8012,7 @@
7977
8012
 
7978
8013
  async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7979
8014
  const { writer } = zipWriter;
7980
- const { directoryStart, directoryEnd, signatureLength } = cdInfo;
8015
+ const { directoryStart, directoryEnd, signatureLength, zip64Entries } = cdInfo;
7981
8016
  let { directoryDataLength } = cdInfo;
7982
8017
  let fileEntriesLength = zipWriter.fileEntries.size;
7983
8018
  let diskNumber = directoryStart.diskNumber;
@@ -7997,6 +8032,8 @@
7997
8032
  } else {
7998
8033
  zip64 = true;
7999
8034
  }
8035
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
8036
+ zip64 = true;
8000
8037
  }
8001
8038
  const endOfdirectoryRecord = createRecordWriter(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8002
8039
  if (exceedsAvailableSize(writer, getLength(endOfdirectoryRecord.array) + commentLength)) {
@@ -8500,7 +8537,7 @@
8500
8537
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8501
8538
  */
8502
8539
 
8503
- const VERSION = "2.11.1";
8540
+ const VERSION = "2.11.3";
8504
8541
 
8505
8542
  /*
8506
8543
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -8991,6 +9028,7 @@
8991
9028
  exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
8992
9029
  exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
8993
9030
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
9031
+ exports.ERR_INVALID_READER = ERR_INVALID_READER;
8994
9032
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
8995
9033
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
8996
9034
  exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;
@@ -9017,6 +9055,7 @@
9017
9055
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
9018
9056
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
9019
9057
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
9058
+ exports.ERR_UNSUPPORTED_SPLIT_USDZ = ERR_UNSUPPORTED_SPLIT_USDZ;
9020
9059
  exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
9021
9060
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
9022
9061
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;