@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.
@@ -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
  /*
@@ -3610,11 +3610,10 @@
3610
3610
  const data = await readUint8Array(reader, offset + chunkOffset, dataSize);
3611
3611
  if (data.length) {
3612
3612
  controller.enqueue(data);
3613
+ chunkOffset += data.length;
3613
3614
  }
3614
- if ((chunkOffset + chunkSize >= size) || (!data.length && dataSize)) {
3615
+ if ((size !== UNDEFINED_VALUE && chunkOffset >= size) || (!data.length && dataSize)) {
3615
3616
  controller.close();
3616
- } else {
3617
- chunkOffset += chunkSize;
3618
3617
  }
3619
3618
  }
3620
3619
  });
@@ -6249,6 +6248,7 @@
6249
6248
  const ERR_INVALID_VERSION = "Version exceeds 65535";
6250
6249
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
6251
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";
6252
6252
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
6253
6253
  const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
6254
6254
  const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
@@ -6263,6 +6263,7 @@
6263
6263
  const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
6264
6264
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
6265
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)";
6266
6267
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
6267
6268
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
6268
6269
  const ERR_INVALID_GID = "Invalid gid (must be integer 0..2^32-1)";
@@ -6294,6 +6295,9 @@
6294
6295
  const addSplitZipSignature =
6295
6296
  availableSize > 0 && availableSize !== INFINITY_VALUE &&
6296
6297
  maxSize > 0 && maxSize !== INFINITY_VALUE;
6298
+ if (addSplitZipSignature && options[OPTION_USDZ]) {
6299
+ throw new Error(ERR_UNSUPPORTED_SPLIT_USDZ);
6300
+ }
6297
6301
  Object.assign(this, {
6298
6302
  writer,
6299
6303
  addSplitZipSignature,
@@ -6305,6 +6309,7 @@
6305
6309
  pendingAddFileCalls: new Set(),
6306
6310
  pendingErrors: [],
6307
6311
  bufferedWrites: 0,
6312
+ directWrites: 0,
6308
6313
  lastFileEntry: UNDEFINED_VALUE
6309
6314
  });
6310
6315
  }
@@ -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,
@@ -7080,6 +7092,7 @@
7080
7092
  const usdz = zipWriter.options[OPTION_USDZ];
7081
7093
  let fileEntry = pendingFileEntry;
7082
7094
  let bufferedWrite;
7095
+ let directWrite;
7083
7096
  let releaseLockWriter;
7084
7097
  let writingBufferedEntryData;
7085
7098
  let writingEntryData;
@@ -7089,7 +7102,7 @@
7089
7102
  const lockPreviousFileEntry = keepOrder && previousFileEntry ? previousFileEntry.lockFileEntry : UNDEFINED_VALUE;
7090
7103
  fileEntries.set(name, fileEntry);
7091
7104
  try {
7092
- if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
7105
+ if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || zipWriter.directWrites || (!dataDescriptor && !emptyEntry)) {
7093
7106
  bufferedWrite = true;
7094
7107
  zipWriter.bufferedWrites++;
7095
7108
  if (options.createTempStream) {
@@ -7100,6 +7113,8 @@
7100
7113
  fileWriter.size = 0;
7101
7114
  await initStream(writer);
7102
7115
  } else {
7116
+ directWrite = true;
7117
+ zipWriter.directWrites++;
7103
7118
  fileWriter = writer;
7104
7119
  await lockPreviousFileEntry;
7105
7120
  await requestLockWriter();
@@ -7178,6 +7193,9 @@
7178
7193
  if (bufferedWrite) {
7179
7194
  zipWriter.bufferedWrites--;
7180
7195
  }
7196
+ if (directWrite) {
7197
+ zipWriter.directWrites--;
7198
+ }
7181
7199
  if (releaseLockFileEntry) {
7182
7200
  releaseLockFileEntry(lockPreviousFileEntry);
7183
7201
  }
@@ -7242,6 +7260,7 @@
7242
7260
  rawPassword,
7243
7261
  level,
7244
7262
  zip64,
7263
+ zip64Enabled,
7245
7264
  zip64UncompressedSize,
7246
7265
  zip64CompressedSize,
7247
7266
  zipCrypto,
@@ -7282,6 +7301,7 @@
7282
7301
  lockFileEntry,
7283
7302
  versionMadeBy,
7284
7303
  zip64,
7304
+ zip64Enabled,
7285
7305
  directory: Boolean(directory),
7286
7306
  executable: Boolean(executable),
7287
7307
  filenameUTF8: true,
@@ -7322,8 +7342,8 @@
7322
7342
  }
7323
7343
  const { writable } = writer;
7324
7344
  if (reader) {
7325
- const readable = toCompatibleReadable(createReadable(reader));
7326
7345
  const size = reader.size;
7346
+ const readable = toCompatibleReadable(createReadable(reader, { size }));
7327
7347
  const workerOptions = {
7328
7348
  options: {
7329
7349
  codecType: CODEC_DEFLATE,
@@ -7425,13 +7445,14 @@
7425
7445
  zip64UncompressedSize,
7426
7446
  zip64CompressedSize,
7427
7447
  uncompressedSize,
7448
+ unknownSize,
7428
7449
  crc32
7429
7450
  } = options;
7430
7451
  let { version, compressionMethod } = options;
7431
7452
  const compressed = !directory && isCompressed(compressionMethod, level);
7432
7453
  let rawLocalExtraFieldZip64;
7433
7454
  const uncompressedFile = passThrough || !compressed;
7434
- const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
7455
+ const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || (uncompressedFile && !unknownSize)));
7435
7456
  const writeLocalExtraFieldZip64 = zip64ExtraFieldComplete || (zip64 && dataDescriptor && (zip64UncompressedSize || zip64CompressedSize));
7436
7457
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
7437
7458
  const length = 4 + 16;
@@ -7565,6 +7586,10 @@
7565
7586
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
7566
7587
  }
7567
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;
7568
7593
  const {
7569
7594
  headerArray,
7570
7595
  headerView,
@@ -7574,7 +7599,7 @@
7574
7599
  bitFlag: getBitFlag(level, useUnicodeFileNames, dataDescriptor, encrypted, compressionMethod),
7575
7600
  compressionMethod,
7576
7601
  uncompressedSize,
7577
- lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
7602
+ lastModDate: clampedLastModDate,
7578
7603
  rawLastModDate: rawLastModDateOption,
7579
7604
  rawFilename,
7580
7605
  zip64CompressedSize,
@@ -7609,7 +7634,7 @@
7609
7634
  localHeaderView,
7610
7635
  headerArray,
7611
7636
  headerView,
7612
- lastModDate,
7637
+ lastModDate: storedLastModDate,
7613
7638
  rawLastModDate,
7614
7639
  encrypted,
7615
7640
  compressed,
@@ -7781,14 +7806,15 @@
7781
7806
 
7782
7807
 
7783
7808
  async function closeFile(zipWriter, comment, options) {
7784
- const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7809
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(zipWriter.fileEntries);
7785
7810
  const { directoryStart, directoryEnd, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7786
7811
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7787
- await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength });
7812
+ await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength, zip64Entries });
7788
7813
  }
7789
7814
 
7790
7815
  function createDirectoryRecords(files) {
7791
7816
  let directoryDataLength = 0;
7817
+ let zip64Entries = false;
7792
7818
  for (const [, fileEntry] of files) {
7793
7819
  const {
7794
7820
  rawFilename,
@@ -7801,11 +7827,20 @@
7801
7827
  extendedTimestamp,
7802
7828
  extraFieldExtendedTimestampFlag,
7803
7829
  lastModDate,
7804
- zip64UncompressedSize,
7805
- zip64CompressedSize,
7830
+ zip64Enabled,
7806
7831
  uncompressedSize,
7807
7832
  compressedSize
7808
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;
7809
7844
  const zip64Offset = fileEntry.offset >= MAX_32_BITS;
7810
7845
  const zip64DiskNumberStart = fileEntry.diskNumberStart >= MAX_16_BITS;
7811
7846
  let rawExtraFieldZip64;
@@ -7859,7 +7894,7 @@
7859
7894
  }
7860
7895
  directoryDataLength += CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
7861
7896
  }
7862
- return directoryDataLength;
7897
+ return { directoryDataLength, zip64Entries };
7863
7898
  }
7864
7899
 
7865
7900
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
@@ -7979,7 +8014,7 @@
7979
8014
 
7980
8015
  async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7981
8016
  const { writer } = zipWriter;
7982
- const { directoryStart, directoryEnd, signatureLength } = cdInfo;
8017
+ const { directoryStart, directoryEnd, signatureLength, zip64Entries } = cdInfo;
7983
8018
  let { directoryDataLength } = cdInfo;
7984
8019
  let fileEntriesLength = zipWriter.fileEntries.size;
7985
8020
  let diskNumber = directoryStart.diskNumber;
@@ -7999,6 +8034,8 @@
7999
8034
  } else {
8000
8035
  zip64 = true;
8001
8036
  }
8037
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
8038
+ zip64 = true;
8002
8039
  }
8003
8040
  const endOfdirectoryRecord = createRecordWriter(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8004
8041
  if (exceedsAvailableSize(writer, getLength(endOfdirectoryRecord.array) + commentLength)) {
@@ -8502,7 +8539,7 @@
8502
8539
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8503
8540
  */
8504
8541
 
8505
- const VERSION = "2.11.1";
8542
+ const VERSION = "2.11.3";
8506
8543
 
8507
8544
  /*
8508
8545
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9024,6 +9061,7 @@
9024
9061
  exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
9025
9062
  exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
9026
9063
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
9064
+ exports.ERR_INVALID_READER = ERR_INVALID_READER;
9027
9065
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
9028
9066
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
9029
9067
  exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;
@@ -9050,6 +9088,7 @@
9050
9088
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
9051
9089
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
9052
9090
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
9091
+ exports.ERR_UNSUPPORTED_SPLIT_USDZ = ERR_UNSUPPORTED_SPLIT_USDZ;
9053
9092
  exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
9054
9093
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
9055
9094
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;