@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
  });
@@ -6269,6 +6268,7 @@
6269
6268
  const ERR_INVALID_VERSION = "Version exceeds 65535";
6270
6269
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
6271
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";
6272
6272
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
6273
6273
  const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
6274
6274
  const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
@@ -6283,6 +6283,7 @@
6283
6283
  const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
6284
6284
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
6285
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)";
6286
6287
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
6287
6288
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
6288
6289
  const ERR_INVALID_GID = "Invalid gid (must be integer 0..2^32-1)";
@@ -6314,6 +6315,9 @@
6314
6315
  const addSplitZipSignature =
6315
6316
  availableSize > 0 && availableSize !== INFINITY_VALUE &&
6316
6317
  maxSize > 0 && maxSize !== INFINITY_VALUE;
6318
+ if (addSplitZipSignature && options[OPTION_USDZ]) {
6319
+ throw new Error(ERR_UNSUPPORTED_SPLIT_USDZ);
6320
+ }
6317
6321
  Object.assign(this, {
6318
6322
  writer,
6319
6323
  addSplitZipSignature,
@@ -6325,6 +6329,7 @@
6325
6329
  pendingAddFileCalls: new Set(),
6326
6330
  pendingErrors: [],
6327
6331
  bufferedWrites: 0,
6332
+ directWrites: 0,
6328
6333
  lastFileEntry: UNDEFINED_VALUE
6329
6334
  });
6330
6335
  }
@@ -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
  }
@@ -7175,6 +7189,7 @@
7175
7189
  const usdz = zipWriter.options[OPTION_USDZ];
7176
7190
  let fileEntry = pendingFileEntry;
7177
7191
  let bufferedWrite;
7192
+ let directWrite;
7178
7193
  let releaseLockWriter;
7179
7194
  let writingBufferedEntryData;
7180
7195
  let writingEntryData;
@@ -7184,7 +7199,7 @@
7184
7199
  const lockPreviousFileEntry = keepOrder && previousFileEntry ? previousFileEntry.lockFileEntry : UNDEFINED_VALUE;
7185
7200
  fileEntries.set(name, fileEntry);
7186
7201
  try {
7187
- if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
7202
+ if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || zipWriter.directWrites || (!dataDescriptor && !emptyEntry)) {
7188
7203
  bufferedWrite = true;
7189
7204
  zipWriter.bufferedWrites++;
7190
7205
  if (options.createTempStream) {
@@ -7195,6 +7210,8 @@
7195
7210
  fileWriter.size = 0;
7196
7211
  await initStream(writer);
7197
7212
  } else {
7213
+ directWrite = true;
7214
+ zipWriter.directWrites++;
7198
7215
  fileWriter = writer;
7199
7216
  await lockPreviousFileEntry;
7200
7217
  await requestLockWriter();
@@ -7273,6 +7290,9 @@
7273
7290
  if (bufferedWrite) {
7274
7291
  zipWriter.bufferedWrites--;
7275
7292
  }
7293
+ if (directWrite) {
7294
+ zipWriter.directWrites--;
7295
+ }
7276
7296
  if (releaseLockFileEntry) {
7277
7297
  releaseLockFileEntry(lockPreviousFileEntry);
7278
7298
  }
@@ -7337,6 +7357,7 @@
7337
7357
  rawPassword,
7338
7358
  level,
7339
7359
  zip64,
7360
+ zip64Enabled,
7340
7361
  zip64UncompressedSize,
7341
7362
  zip64CompressedSize,
7342
7363
  zipCrypto,
@@ -7377,6 +7398,7 @@
7377
7398
  lockFileEntry,
7378
7399
  versionMadeBy,
7379
7400
  zip64,
7401
+ zip64Enabled,
7380
7402
  directory: Boolean(directory),
7381
7403
  executable: Boolean(executable),
7382
7404
  filenameUTF8: true,
@@ -7417,8 +7439,8 @@
7417
7439
  }
7418
7440
  const { writable } = writer;
7419
7441
  if (reader) {
7420
- const readable = toCompatibleReadable(createReadable(reader));
7421
7442
  const size = reader.size;
7443
+ const readable = toCompatibleReadable(createReadable(reader, { size }));
7422
7444
  const workerOptions = {
7423
7445
  options: {
7424
7446
  codecType: CODEC_DEFLATE,
@@ -7520,13 +7542,14 @@
7520
7542
  zip64UncompressedSize,
7521
7543
  zip64CompressedSize,
7522
7544
  uncompressedSize,
7545
+ unknownSize,
7523
7546
  crc32
7524
7547
  } = options;
7525
7548
  let { version, compressionMethod } = options;
7526
7549
  const compressed = !directory && isCompressed(compressionMethod, level);
7527
7550
  let rawLocalExtraFieldZip64;
7528
7551
  const uncompressedFile = passThrough || !compressed;
7529
- const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
7552
+ const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || (uncompressedFile && !unknownSize)));
7530
7553
  const writeLocalExtraFieldZip64 = zip64ExtraFieldComplete || (zip64 && dataDescriptor && (zip64UncompressedSize || zip64CompressedSize));
7531
7554
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
7532
7555
  const length = 4 + 16;
@@ -7660,6 +7683,10 @@
7660
7683
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
7661
7684
  }
7662
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;
7663
7690
  const {
7664
7691
  headerArray,
7665
7692
  headerView,
@@ -7669,7 +7696,7 @@
7669
7696
  bitFlag: getBitFlag(level, useUnicodeFileNames, dataDescriptor, encrypted, compressionMethod),
7670
7697
  compressionMethod,
7671
7698
  uncompressedSize,
7672
- lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
7699
+ lastModDate: clampedLastModDate,
7673
7700
  rawLastModDate: rawLastModDateOption,
7674
7701
  rawFilename,
7675
7702
  zip64CompressedSize,
@@ -7704,7 +7731,7 @@
7704
7731
  localHeaderView,
7705
7732
  headerArray,
7706
7733
  headerView,
7707
- lastModDate,
7734
+ lastModDate: storedLastModDate,
7708
7735
  rawLastModDate,
7709
7736
  encrypted,
7710
7737
  compressed,
@@ -7876,14 +7903,15 @@
7876
7903
 
7877
7904
 
7878
7905
  async function closeFile(zipWriter, comment, options) {
7879
- const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7906
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(zipWriter.fileEntries);
7880
7907
  const { directoryStart, directoryEnd, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7881
7908
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7882
- await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength });
7909
+ await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength, zip64Entries });
7883
7910
  }
7884
7911
 
7885
7912
  function createDirectoryRecords(files) {
7886
7913
  let directoryDataLength = 0;
7914
+ let zip64Entries = false;
7887
7915
  for (const [, fileEntry] of files) {
7888
7916
  const {
7889
7917
  rawFilename,
@@ -7896,11 +7924,20 @@
7896
7924
  extendedTimestamp,
7897
7925
  extraFieldExtendedTimestampFlag,
7898
7926
  lastModDate,
7899
- zip64UncompressedSize,
7900
- zip64CompressedSize,
7927
+ zip64Enabled,
7901
7928
  uncompressedSize,
7902
7929
  compressedSize
7903
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;
7904
7941
  const zip64Offset = fileEntry.offset >= MAX_32_BITS;
7905
7942
  const zip64DiskNumberStart = fileEntry.diskNumberStart >= MAX_16_BITS;
7906
7943
  let rawExtraFieldZip64;
@@ -7954,7 +7991,7 @@
7954
7991
  }
7955
7992
  directoryDataLength += CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
7956
7993
  }
7957
- return directoryDataLength;
7994
+ return { directoryDataLength, zip64Entries };
7958
7995
  }
7959
7996
 
7960
7997
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
@@ -8074,7 +8111,7 @@
8074
8111
 
8075
8112
  async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
8076
8113
  const { writer } = zipWriter;
8077
- const { directoryStart, directoryEnd, signatureLength } = cdInfo;
8114
+ const { directoryStart, directoryEnd, signatureLength, zip64Entries } = cdInfo;
8078
8115
  let { directoryDataLength } = cdInfo;
8079
8116
  let fileEntriesLength = zipWriter.fileEntries.size;
8080
8117
  let diskNumber = directoryStart.diskNumber;
@@ -8094,6 +8131,8 @@
8094
8131
  } else {
8095
8132
  zip64 = true;
8096
8133
  }
8134
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
8135
+ zip64 = true;
8097
8136
  }
8098
8137
  const endOfdirectoryRecord = createRecordWriter(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8099
8138
  if (exceedsAvailableSize(writer, getLength(endOfdirectoryRecord.array) + commentLength)) {
@@ -8597,7 +8636,7 @@
8597
8636
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8598
8637
  */
8599
8638
 
8600
- const VERSION = "2.11.1";
8639
+ const VERSION = "2.11.3";
8601
8640
 
8602
8641
  /*
8603
8642
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9621,12 +9660,14 @@
9621
9660
  if (options.bufferedWrite === UNDEFINED_VALUE) {
9622
9661
  options.bufferedWrite = true;
9623
9662
  }
9624
- 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 => {
9625
9665
  const { name, entryOptions } = getChildEntryOptions(child, zipEntry, options);
9626
9666
  return { name, size: child.directory ? 0 : getDeterminedSize(child, isPassThrough(child, options)), options: entryOptions };
9627
9667
  });
9628
9668
  const writeOrderGuaranteed = !options.bufferedWrite ||
9629
- (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));
9630
9671
  return getEntriesSize(options, entries, writeOrderGuaranteed, options.globalComment);
9631
9672
  }
9632
9673
 
@@ -10655,6 +10696,7 @@
10655
10696
  exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
10656
10697
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
10657
10698
  exports.ERR_INVALID_PASS_THROUGH = ERR_INVALID_PASS_THROUGH;
10699
+ exports.ERR_INVALID_READER = ERR_INVALID_READER;
10658
10700
  exports.ERR_INVALID_READER_OPTIONS = ERR_INVALID_READER_OPTIONS;
10659
10701
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
10660
10702
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
@@ -10683,6 +10725,7 @@
10683
10725
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
10684
10726
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
10685
10727
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
10728
+ exports.ERR_UNSUPPORTED_SPLIT_USDZ = ERR_UNSUPPORTED_SPLIT_USDZ;
10686
10729
  exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
10687
10730
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
10688
10731
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;