@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
  /*
@@ -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
  });
@@ -6267,6 +6266,7 @@
6267
6266
  const ERR_INVALID_VERSION = "Version exceeds 65535";
6268
6267
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
6269
6268
  const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
6269
+ const ERR_UNSUPPORTED_SPLIT_USDZ = "Split zip files are not supported in USDZ files";
6270
6270
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
6271
6271
  const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
6272
6272
  const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
@@ -6281,6 +6281,7 @@
6281
6281
  const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
6282
6282
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
6283
6283
  const ERR_UNDEFINED_READER = "Undefined reader";
6284
+ const ERR_INVALID_READER = "Invalid reader (must be a Reader instance, a ReadableStream instance, or an object with a 'readable' property)";
6284
6285
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
6285
6286
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
6286
6287
  const ERR_INVALID_GID = "Invalid gid (must be integer 0..2^32-1)";
@@ -6312,6 +6313,9 @@
6312
6313
  const addSplitZipSignature =
6313
6314
  availableSize > 0 && availableSize !== INFINITY_VALUE &&
6314
6315
  maxSize > 0 && maxSize !== INFINITY_VALUE;
6316
+ if (addSplitZipSignature && options[OPTION_USDZ]) {
6317
+ throw new Error(ERR_UNSUPPORTED_SPLIT_USDZ);
6318
+ }
6315
6319
  Object.assign(this, {
6316
6320
  writer,
6317
6321
  addSplitZipSignature,
@@ -6323,6 +6327,7 @@
6323
6327
  pendingAddFileCalls: new Set(),
6324
6328
  pendingErrors: [],
6325
6329
  bufferedWrites: 0,
6330
+ directWrites: 0,
6326
6331
  lastFileEntry: UNDEFINED_VALUE
6327
6332
  });
6328
6333
  }
@@ -6426,6 +6431,7 @@
6426
6431
  }
6427
6432
  const { offset, diskNumberStart } = entryPositions.get(entry);
6428
6433
  Object.assign(entry, {
6434
+ zip64Enabled: true,
6429
6435
  zip64UncompressedSize,
6430
6436
  zip64CompressedSize,
6431
6437
  offset,
@@ -7001,6 +7007,9 @@
7001
7007
  if (reader) {
7002
7008
  reader = new GenericReader(reader);
7003
7009
  await initStream(reader);
7010
+ if (!reader.readable && !reader.readUint8Array) {
7011
+ throw new Error(ERR_INVALID_READER);
7012
+ }
7004
7013
  ({ size: contentSize } = reader);
7005
7014
  }
7006
7015
  return Object.assign({ reader }, resolveEntrySizes(zipWriter, Boolean(reader), contentSize, metadata, options));
@@ -7011,6 +7020,7 @@
7011
7020
  let { dataDescriptor, zip64, level, compressionMethod } = metadata;
7012
7021
  let maximumCompressedSize = 0;
7013
7022
  let uncompressedSize = 0;
7023
+ let unknownSize = false;
7014
7024
  if (passThrough && hasContent) {
7015
7025
  uncompressedSize = options[PROPERTY_NAME_UNCOMPRESSED_SIZE];
7016
7026
  if (uncompressedSize === UNDEFINED_VALUE) {
@@ -7036,8 +7046,8 @@
7036
7046
  if (contentSize === UNDEFINED_VALUE) {
7037
7047
  dataDescriptor = true;
7038
7048
  if (zip64 || zip64 === UNDEFINED_VALUE) {
7039
- zip64 = true;
7040
- uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
7049
+ zip64 = unknownSize = true;
7050
+ maximumCompressedSize = MAX_32_BITS + 1;
7041
7051
  }
7042
7052
  } else {
7043
7053
  options.uncompressedSize = uncompressedSize = contentSize;
@@ -7052,7 +7062,7 @@
7052
7062
  if (emptyEntry && !zipCrypto && getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR) === UNDEFINED_VALUE) {
7053
7063
  dataDescriptor = false;
7054
7064
  }
7055
- const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
7065
+ const zip64UncompressedSize = zip64Enabled || unknownSize || uncompressedSize >= MAX_32_BITS;
7056
7066
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
7057
7067
  if (zip64UncompressedSize || zip64CompressedSize) {
7058
7068
  if (zip64 === false) {
@@ -7068,6 +7078,8 @@
7068
7078
  dataDescriptor,
7069
7079
  emptyEntry,
7070
7080
  zip64,
7081
+ zip64Enabled,
7082
+ unknownSize,
7071
7083
  zip64UncompressedSize,
7072
7084
  zip64CompressedSize,
7073
7085
  uncompressedSize,
@@ -7141,7 +7153,7 @@
7141
7153
  if (layoutDependsOnWriteOrder && !writeOrderGuaranteed) {
7142
7154
  throw new Error(ERR_UNDETERMINED_SIZE);
7143
7155
  }
7144
- const directoryDataLength = createDirectoryRecords(files);
7156
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(files);
7145
7157
  let zip64 = getOptionValue(zipWriter, writerOptions, PROPERTY_NAME_ZIP64);
7146
7158
  if (offset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || files.size >= MAX_16_BITS) {
7147
7159
  if (zip64 === false) {
@@ -7149,6 +7161,8 @@
7149
7161
  } else {
7150
7162
  zip64 = true;
7151
7163
  }
7164
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
7165
+ zip64 = true;
7152
7166
  }
7153
7167
  return offset - initialOffset + directoryDataLength + commentLength + (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
7154
7168
  }
@@ -7173,6 +7187,7 @@
7173
7187
  const usdz = zipWriter.options[OPTION_USDZ];
7174
7188
  let fileEntry = pendingFileEntry;
7175
7189
  let bufferedWrite;
7190
+ let directWrite;
7176
7191
  let releaseLockWriter;
7177
7192
  let writingBufferedEntryData;
7178
7193
  let writingEntryData;
@@ -7182,7 +7197,7 @@
7182
7197
  const lockPreviousFileEntry = keepOrder && previousFileEntry ? previousFileEntry.lockFileEntry : UNDEFINED_VALUE;
7183
7198
  fileEntries.set(name, fileEntry);
7184
7199
  try {
7185
- if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
7200
+ if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || zipWriter.directWrites || (!dataDescriptor && !emptyEntry)) {
7186
7201
  bufferedWrite = true;
7187
7202
  zipWriter.bufferedWrites++;
7188
7203
  if (options.createTempStream) {
@@ -7193,6 +7208,8 @@
7193
7208
  fileWriter.size = 0;
7194
7209
  await initStream(writer);
7195
7210
  } else {
7211
+ directWrite = true;
7212
+ zipWriter.directWrites++;
7196
7213
  fileWriter = writer;
7197
7214
  await lockPreviousFileEntry;
7198
7215
  await requestLockWriter();
@@ -7271,6 +7288,9 @@
7271
7288
  if (bufferedWrite) {
7272
7289
  zipWriter.bufferedWrites--;
7273
7290
  }
7291
+ if (directWrite) {
7292
+ zipWriter.directWrites--;
7293
+ }
7274
7294
  if (releaseLockFileEntry) {
7275
7295
  releaseLockFileEntry(lockPreviousFileEntry);
7276
7296
  }
@@ -7335,6 +7355,7 @@
7335
7355
  rawPassword,
7336
7356
  level,
7337
7357
  zip64,
7358
+ zip64Enabled,
7338
7359
  zip64UncompressedSize,
7339
7360
  zip64CompressedSize,
7340
7361
  zipCrypto,
@@ -7375,6 +7396,7 @@
7375
7396
  lockFileEntry,
7376
7397
  versionMadeBy,
7377
7398
  zip64,
7399
+ zip64Enabled,
7378
7400
  directory: Boolean(directory),
7379
7401
  executable: Boolean(executable),
7380
7402
  filenameUTF8: true,
@@ -7415,8 +7437,8 @@
7415
7437
  }
7416
7438
  const { writable } = writer;
7417
7439
  if (reader) {
7418
- const readable = toCompatibleReadable(createReadable(reader));
7419
7440
  const size = reader.size;
7441
+ const readable = toCompatibleReadable(createReadable(reader, { size }));
7420
7442
  const workerOptions = {
7421
7443
  options: {
7422
7444
  codecType: CODEC_DEFLATE,
@@ -7518,13 +7540,14 @@
7518
7540
  zip64UncompressedSize,
7519
7541
  zip64CompressedSize,
7520
7542
  uncompressedSize,
7543
+ unknownSize,
7521
7544
  crc32
7522
7545
  } = options;
7523
7546
  let { version, compressionMethod } = options;
7524
7547
  const compressed = !directory && isCompressed(compressionMethod, level);
7525
7548
  let rawLocalExtraFieldZip64;
7526
7549
  const uncompressedFile = passThrough || !compressed;
7527
- const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
7550
+ const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || (uncompressedFile && !unknownSize)));
7528
7551
  const writeLocalExtraFieldZip64 = zip64ExtraFieldComplete || (zip64 && dataDescriptor && (zip64UncompressedSize || zip64CompressedSize));
7529
7552
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
7530
7553
  const length = 4 + 16;
@@ -7658,6 +7681,10 @@
7658
7681
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
7659
7682
  }
7660
7683
  const dosLastModDate = new Date(Math.ceil(Math.floor(lastModDate.getTime() / 1000) / 2) * 2000);
7684
+ const clampedLastModDate = dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate;
7685
+ const storedLastModDate = getLength(rawExtraFieldExtendedTimestamp) ?
7686
+ new Date(getTimeUnix(lastModDate) * 1000) :
7687
+ getLength(rawExtraFieldNTFS) ? lastModDate : clampedLastModDate;
7661
7688
  const {
7662
7689
  headerArray,
7663
7690
  headerView,
@@ -7667,7 +7694,7 @@
7667
7694
  bitFlag: getBitFlag(level, useUnicodeFileNames, dataDescriptor, encrypted, compressionMethod),
7668
7695
  compressionMethod,
7669
7696
  uncompressedSize,
7670
- lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
7697
+ lastModDate: clampedLastModDate,
7671
7698
  rawLastModDate: rawLastModDateOption,
7672
7699
  rawFilename,
7673
7700
  zip64CompressedSize,
@@ -7702,7 +7729,7 @@
7702
7729
  localHeaderView,
7703
7730
  headerArray,
7704
7731
  headerView,
7705
- lastModDate,
7732
+ lastModDate: storedLastModDate,
7706
7733
  rawLastModDate,
7707
7734
  encrypted,
7708
7735
  compressed,
@@ -7874,14 +7901,15 @@
7874
7901
 
7875
7902
 
7876
7903
  async function closeFile(zipWriter, comment, options) {
7877
- const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7904
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(zipWriter.fileEntries);
7878
7905
  const { directoryStart, directoryEnd, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7879
7906
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7880
- await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength });
7907
+ await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength, zip64Entries });
7881
7908
  }
7882
7909
 
7883
7910
  function createDirectoryRecords(files) {
7884
7911
  let directoryDataLength = 0;
7912
+ let zip64Entries = false;
7885
7913
  for (const [, fileEntry] of files) {
7886
7914
  const {
7887
7915
  rawFilename,
@@ -7894,11 +7922,20 @@
7894
7922
  extendedTimestamp,
7895
7923
  extraFieldExtendedTimestampFlag,
7896
7924
  lastModDate,
7897
- zip64UncompressedSize,
7898
- zip64CompressedSize,
7925
+ zip64Enabled,
7899
7926
  uncompressedSize,
7900
7927
  compressedSize
7901
7928
  } = fileEntry;
7929
+ let { zip64UncompressedSize, zip64CompressedSize } = fileEntry;
7930
+ if (!zip64Enabled) {
7931
+ if (zip64UncompressedSize && uncompressedSize < MAX_32_BITS) {
7932
+ zip64UncompressedSize = fileEntry.zip64UncompressedSize = false;
7933
+ }
7934
+ if (zip64CompressedSize && compressedSize < MAX_32_BITS) {
7935
+ zip64CompressedSize = fileEntry.zip64CompressedSize = false;
7936
+ }
7937
+ }
7938
+ zip64Entries = zip64Entries || zip64UncompressedSize || zip64CompressedSize;
7902
7939
  const zip64Offset = fileEntry.offset >= MAX_32_BITS;
7903
7940
  const zip64DiskNumberStart = fileEntry.diskNumberStart >= MAX_16_BITS;
7904
7941
  let rawExtraFieldZip64;
@@ -7952,7 +7989,7 @@
7952
7989
  }
7953
7990
  directoryDataLength += CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
7954
7991
  }
7955
- return directoryDataLength;
7992
+ return { directoryDataLength, zip64Entries };
7956
7993
  }
7957
7994
 
7958
7995
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
@@ -8072,7 +8109,7 @@
8072
8109
 
8073
8110
  async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
8074
8111
  const { writer } = zipWriter;
8075
- const { directoryStart, directoryEnd, signatureLength } = cdInfo;
8112
+ const { directoryStart, directoryEnd, signatureLength, zip64Entries } = cdInfo;
8076
8113
  let { directoryDataLength } = cdInfo;
8077
8114
  let fileEntriesLength = zipWriter.fileEntries.size;
8078
8115
  let diskNumber = directoryStart.diskNumber;
@@ -8092,6 +8129,8 @@
8092
8129
  } else {
8093
8130
  zip64 = true;
8094
8131
  }
8132
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
8133
+ zip64 = true;
8095
8134
  }
8096
8135
  const endOfdirectoryRecord = createRecordWriter(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8097
8136
  if (exceedsAvailableSize(writer, getLength(endOfdirectoryRecord.array) + commentLength)) {
@@ -8595,7 +8634,7 @@
8595
8634
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8596
8635
  */
8597
8636
 
8598
- const VERSION = "2.11.1";
8637
+ const VERSION = "2.11.3";
8599
8638
 
8600
8639
  /*
8601
8640
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9581,12 +9620,14 @@
9581
9620
  if (options.bufferedWrite === UNDEFINED_VALUE) {
9582
9621
  options.bufferedWrite = true;
9583
9622
  }
9584
- const entries = zipEntry.getChildren({ recursive: true }).filter(child => !isImplicitDirectory(child)).map(child => {
9623
+ const children = zipEntry.getChildren({ recursive: true });
9624
+ const entries = children.filter(child => !isImplicitDirectory(child)).map(child => {
9585
9625
  const { name, entryOptions } = getChildEntryOptions(child, zipEntry, options);
9586
9626
  return { name, size: child.directory ? 0 : getDeterminedSize(child, isPassThrough(child, options)), options: entryOptions };
9587
9627
  });
9588
9628
  const writeOrderGuaranteed = !options.bufferedWrite ||
9589
- (entries.every(entry => entry.options.keepOrder !== false) && zipEntry.children.every(child => !child.children.length));
9629
+ (entries.every(entry => entry.options.keepOrder !== false) &&
9630
+ children.every(child => isImplicitDirectory(child) || !child.children.length));
9590
9631
  return getEntriesSize(options, entries, writeOrderGuaranteed, options.globalComment);
9591
9632
  }
9592
9633
 
@@ -10520,6 +10561,7 @@
10520
10561
  exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
10521
10562
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
10522
10563
  exports.ERR_INVALID_PASS_THROUGH = ERR_INVALID_PASS_THROUGH;
10564
+ exports.ERR_INVALID_READER = ERR_INVALID_READER;
10523
10565
  exports.ERR_INVALID_READER_OPTIONS = ERR_INVALID_READER_OPTIONS;
10524
10566
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
10525
10567
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
@@ -10548,6 +10590,7 @@
10548
10590
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
10549
10591
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
10550
10592
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
10593
+ exports.ERR_UNSUPPORTED_SPLIT_USDZ = ERR_UNSUPPORTED_SPLIT_USDZ;
10551
10594
  exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
10552
10595
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
10553
10596
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;