@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-fs.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
  /*
@@ -3614,11 +3614,10 @@
3614
3614
  const data = await readUint8Array(reader, offset + chunkOffset, dataSize);
3615
3615
  if (data.length) {
3616
3616
  controller.enqueue(data);
3617
+ chunkOffset += data.length;
3617
3618
  }
3618
- if ((chunkOffset + chunkSize >= size) || (!data.length && dataSize)) {
3619
+ if ((size !== UNDEFINED_VALUE && chunkOffset >= size) || (!data.length && dataSize)) {
3619
3620
  controller.close();
3620
- } else {
3621
- chunkOffset += chunkSize;
3622
3621
  }
3623
3622
  }
3624
3623
  });
@@ -6273,6 +6272,7 @@
6273
6272
  const ERR_INVALID_VERSION = "Version exceeds 65535";
6274
6273
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
6275
6274
  const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
6275
+ const ERR_UNSUPPORTED_SPLIT_USDZ = "Split zip files are not supported in USDZ files";
6276
6276
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
6277
6277
  const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
6278
6278
  const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
@@ -6287,6 +6287,7 @@
6287
6287
  const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
6288
6288
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
6289
6289
  const ERR_UNDEFINED_READER = "Undefined reader";
6290
+ const ERR_INVALID_READER = "Invalid reader (must be a Reader instance, a ReadableStream instance, or an object with a 'readable' property)";
6290
6291
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
6291
6292
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
6292
6293
  const ERR_INVALID_GID = "Invalid gid (must be integer 0..2^32-1)";
@@ -6318,6 +6319,9 @@
6318
6319
  const addSplitZipSignature =
6319
6320
  availableSize > 0 && availableSize !== INFINITY_VALUE &&
6320
6321
  maxSize > 0 && maxSize !== INFINITY_VALUE;
6322
+ if (addSplitZipSignature && options[OPTION_USDZ]) {
6323
+ throw new Error(ERR_UNSUPPORTED_SPLIT_USDZ);
6324
+ }
6321
6325
  Object.assign(this, {
6322
6326
  writer,
6323
6327
  addSplitZipSignature,
@@ -6329,6 +6333,7 @@
6329
6333
  pendingAddFileCalls: new Set(),
6330
6334
  pendingErrors: [],
6331
6335
  bufferedWrites: 0,
6336
+ directWrites: 0,
6332
6337
  lastFileEntry: UNDEFINED_VALUE
6333
6338
  });
6334
6339
  }
@@ -6432,6 +6437,7 @@
6432
6437
  }
6433
6438
  const { offset, diskNumberStart } = entryPositions.get(entry);
6434
6439
  Object.assign(entry, {
6440
+ zip64Enabled: true,
6435
6441
  zip64UncompressedSize,
6436
6442
  zip64CompressedSize,
6437
6443
  offset,
@@ -7007,6 +7013,9 @@
7007
7013
  if (reader) {
7008
7014
  reader = new GenericReader(reader);
7009
7015
  await initStream(reader);
7016
+ if (!reader.readable && !reader.readUint8Array) {
7017
+ throw new Error(ERR_INVALID_READER);
7018
+ }
7010
7019
  ({ size: contentSize } = reader);
7011
7020
  }
7012
7021
  return Object.assign({ reader }, resolveEntrySizes(zipWriter, Boolean(reader), contentSize, metadata, options));
@@ -7017,6 +7026,7 @@
7017
7026
  let { dataDescriptor, zip64, level, compressionMethod } = metadata;
7018
7027
  let maximumCompressedSize = 0;
7019
7028
  let uncompressedSize = 0;
7029
+ let unknownSize = false;
7020
7030
  if (passThrough && hasContent) {
7021
7031
  uncompressedSize = options[PROPERTY_NAME_UNCOMPRESSED_SIZE];
7022
7032
  if (uncompressedSize === UNDEFINED_VALUE) {
@@ -7042,8 +7052,8 @@
7042
7052
  if (contentSize === UNDEFINED_VALUE) {
7043
7053
  dataDescriptor = true;
7044
7054
  if (zip64 || zip64 === UNDEFINED_VALUE) {
7045
- zip64 = true;
7046
- uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
7055
+ zip64 = unknownSize = true;
7056
+ maximumCompressedSize = MAX_32_BITS + 1;
7047
7057
  }
7048
7058
  } else {
7049
7059
  options.uncompressedSize = uncompressedSize = contentSize;
@@ -7058,7 +7068,7 @@
7058
7068
  if (emptyEntry && !zipCrypto && getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR) === UNDEFINED_VALUE) {
7059
7069
  dataDescriptor = false;
7060
7070
  }
7061
- const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
7071
+ const zip64UncompressedSize = zip64Enabled || unknownSize || uncompressedSize >= MAX_32_BITS;
7062
7072
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
7063
7073
  if (zip64UncompressedSize || zip64CompressedSize) {
7064
7074
  if (zip64 === false) {
@@ -7074,6 +7084,8 @@
7074
7084
  dataDescriptor,
7075
7085
  emptyEntry,
7076
7086
  zip64,
7087
+ zip64Enabled,
7088
+ unknownSize,
7077
7089
  zip64UncompressedSize,
7078
7090
  zip64CompressedSize,
7079
7091
  uncompressedSize,
@@ -7147,7 +7159,7 @@
7147
7159
  if (layoutDependsOnWriteOrder && !writeOrderGuaranteed) {
7148
7160
  throw new Error(ERR_UNDETERMINED_SIZE);
7149
7161
  }
7150
- const directoryDataLength = createDirectoryRecords(files);
7162
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(files);
7151
7163
  let zip64 = getOptionValue(zipWriter, writerOptions, PROPERTY_NAME_ZIP64);
7152
7164
  if (offset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || files.size >= MAX_16_BITS) {
7153
7165
  if (zip64 === false) {
@@ -7155,6 +7167,8 @@
7155
7167
  } else {
7156
7168
  zip64 = true;
7157
7169
  }
7170
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
7171
+ zip64 = true;
7158
7172
  }
7159
7173
  return offset - initialOffset + directoryDataLength + commentLength + (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
7160
7174
  }
@@ -7179,6 +7193,7 @@
7179
7193
  const usdz = zipWriter.options[OPTION_USDZ];
7180
7194
  let fileEntry = pendingFileEntry;
7181
7195
  let bufferedWrite;
7196
+ let directWrite;
7182
7197
  let releaseLockWriter;
7183
7198
  let writingBufferedEntryData;
7184
7199
  let writingEntryData;
@@ -7188,7 +7203,7 @@
7188
7203
  const lockPreviousFileEntry = keepOrder && previousFileEntry ? previousFileEntry.lockFileEntry : UNDEFINED_VALUE;
7189
7204
  fileEntries.set(name, fileEntry);
7190
7205
  try {
7191
- if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
7206
+ if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || zipWriter.directWrites || (!dataDescriptor && !emptyEntry)) {
7192
7207
  bufferedWrite = true;
7193
7208
  zipWriter.bufferedWrites++;
7194
7209
  if (options.createTempStream) {
@@ -7199,6 +7214,8 @@
7199
7214
  fileWriter.size = 0;
7200
7215
  await initStream(writer);
7201
7216
  } else {
7217
+ directWrite = true;
7218
+ zipWriter.directWrites++;
7202
7219
  fileWriter = writer;
7203
7220
  await lockPreviousFileEntry;
7204
7221
  await requestLockWriter();
@@ -7277,6 +7294,9 @@
7277
7294
  if (bufferedWrite) {
7278
7295
  zipWriter.bufferedWrites--;
7279
7296
  }
7297
+ if (directWrite) {
7298
+ zipWriter.directWrites--;
7299
+ }
7280
7300
  if (releaseLockFileEntry) {
7281
7301
  releaseLockFileEntry(lockPreviousFileEntry);
7282
7302
  }
@@ -7341,6 +7361,7 @@
7341
7361
  rawPassword,
7342
7362
  level,
7343
7363
  zip64,
7364
+ zip64Enabled,
7344
7365
  zip64UncompressedSize,
7345
7366
  zip64CompressedSize,
7346
7367
  zipCrypto,
@@ -7381,6 +7402,7 @@
7381
7402
  lockFileEntry,
7382
7403
  versionMadeBy,
7383
7404
  zip64,
7405
+ zip64Enabled,
7384
7406
  directory: Boolean(directory),
7385
7407
  executable: Boolean(executable),
7386
7408
  filenameUTF8: true,
@@ -7421,8 +7443,8 @@
7421
7443
  }
7422
7444
  const { writable } = writer;
7423
7445
  if (reader) {
7424
- const readable = toCompatibleReadable(createReadable(reader));
7425
7446
  const size = reader.size;
7447
+ const readable = toCompatibleReadable(createReadable(reader, { size }));
7426
7448
  const workerOptions = {
7427
7449
  options: {
7428
7450
  codecType: CODEC_DEFLATE,
@@ -7524,13 +7546,14 @@
7524
7546
  zip64UncompressedSize,
7525
7547
  zip64CompressedSize,
7526
7548
  uncompressedSize,
7549
+ unknownSize,
7527
7550
  crc32
7528
7551
  } = options;
7529
7552
  let { version, compressionMethod } = options;
7530
7553
  const compressed = !directory && isCompressed(compressionMethod, level);
7531
7554
  let rawLocalExtraFieldZip64;
7532
7555
  const uncompressedFile = passThrough || !compressed;
7533
- const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
7556
+ const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || (uncompressedFile && !unknownSize)));
7534
7557
  const writeLocalExtraFieldZip64 = zip64ExtraFieldComplete || (zip64 && dataDescriptor && (zip64UncompressedSize || zip64CompressedSize));
7535
7558
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
7536
7559
  const length = 4 + 16;
@@ -7664,6 +7687,10 @@
7664
7687
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
7665
7688
  }
7666
7689
  const dosLastModDate = new Date(Math.ceil(Math.floor(lastModDate.getTime() / 1000) / 2) * 2000);
7690
+ const clampedLastModDate = dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate;
7691
+ const storedLastModDate = getLength(rawExtraFieldExtendedTimestamp) ?
7692
+ new Date(getTimeUnix(lastModDate) * 1000) :
7693
+ getLength(rawExtraFieldNTFS) ? lastModDate : clampedLastModDate;
7667
7694
  const {
7668
7695
  headerArray,
7669
7696
  headerView,
@@ -7673,7 +7700,7 @@
7673
7700
  bitFlag: getBitFlag(level, useUnicodeFileNames, dataDescriptor, encrypted, compressionMethod),
7674
7701
  compressionMethod,
7675
7702
  uncompressedSize,
7676
- lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
7703
+ lastModDate: clampedLastModDate,
7677
7704
  rawLastModDate: rawLastModDateOption,
7678
7705
  rawFilename,
7679
7706
  zip64CompressedSize,
@@ -7708,7 +7735,7 @@
7708
7735
  localHeaderView,
7709
7736
  headerArray,
7710
7737
  headerView,
7711
- lastModDate,
7738
+ lastModDate: storedLastModDate,
7712
7739
  rawLastModDate,
7713
7740
  encrypted,
7714
7741
  compressed,
@@ -7880,14 +7907,15 @@
7880
7907
 
7881
7908
 
7882
7909
  async function closeFile(zipWriter, comment, options) {
7883
- const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7910
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(zipWriter.fileEntries);
7884
7911
  const { directoryStart, directoryEnd, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7885
7912
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7886
- await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength });
7913
+ await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength, zip64Entries });
7887
7914
  }
7888
7915
 
7889
7916
  function createDirectoryRecords(files) {
7890
7917
  let directoryDataLength = 0;
7918
+ let zip64Entries = false;
7891
7919
  for (const [, fileEntry] of files) {
7892
7920
  const {
7893
7921
  rawFilename,
@@ -7900,11 +7928,20 @@
7900
7928
  extendedTimestamp,
7901
7929
  extraFieldExtendedTimestampFlag,
7902
7930
  lastModDate,
7903
- zip64UncompressedSize,
7904
- zip64CompressedSize,
7931
+ zip64Enabled,
7905
7932
  uncompressedSize,
7906
7933
  compressedSize
7907
7934
  } = fileEntry;
7935
+ let { zip64UncompressedSize, zip64CompressedSize } = fileEntry;
7936
+ if (!zip64Enabled) {
7937
+ if (zip64UncompressedSize && uncompressedSize < MAX_32_BITS) {
7938
+ zip64UncompressedSize = fileEntry.zip64UncompressedSize = false;
7939
+ }
7940
+ if (zip64CompressedSize && compressedSize < MAX_32_BITS) {
7941
+ zip64CompressedSize = fileEntry.zip64CompressedSize = false;
7942
+ }
7943
+ }
7944
+ zip64Entries = zip64Entries || zip64UncompressedSize || zip64CompressedSize;
7908
7945
  const zip64Offset = fileEntry.offset >= MAX_32_BITS;
7909
7946
  const zip64DiskNumberStart = fileEntry.diskNumberStart >= MAX_16_BITS;
7910
7947
  let rawExtraFieldZip64;
@@ -7958,7 +7995,7 @@
7958
7995
  }
7959
7996
  directoryDataLength += CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
7960
7997
  }
7961
- return directoryDataLength;
7998
+ return { directoryDataLength, zip64Entries };
7962
7999
  }
7963
8000
 
7964
8001
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
@@ -8078,7 +8115,7 @@
8078
8115
 
8079
8116
  async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
8080
8117
  const { writer } = zipWriter;
8081
- const { directoryStart, directoryEnd, signatureLength } = cdInfo;
8118
+ const { directoryStart, directoryEnd, signatureLength, zip64Entries } = cdInfo;
8082
8119
  let { directoryDataLength } = cdInfo;
8083
8120
  let fileEntriesLength = zipWriter.fileEntries.size;
8084
8121
  let diskNumber = directoryStart.diskNumber;
@@ -8098,6 +8135,8 @@
8098
8135
  } else {
8099
8136
  zip64 = true;
8100
8137
  }
8138
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
8139
+ zip64 = true;
8101
8140
  }
8102
8141
  const endOfdirectoryRecord = createRecordWriter(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8103
8142
  if (exceedsAvailableSize(writer, getLength(endOfdirectoryRecord.array) + commentLength)) {
@@ -8601,7 +8640,7 @@
8601
8640
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8602
8641
  */
8603
8642
 
8604
- const VERSION = "2.11.1";
8643
+ const VERSION = "2.11.3";
8605
8644
 
8606
8645
  /*
8607
8646
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9997,12 +10036,14 @@
9997
10036
  if (options.bufferedWrite === UNDEFINED_VALUE) {
9998
10037
  options.bufferedWrite = true;
9999
10038
  }
10000
- const entries = zipEntry.getChildren({ recursive: true }).filter(child => !isImplicitDirectory(child)).map(child => {
10039
+ const children = zipEntry.getChildren({ recursive: true });
10040
+ const entries = children.filter(child => !isImplicitDirectory(child)).map(child => {
10001
10041
  const { name, entryOptions } = getChildEntryOptions(child, zipEntry, options);
10002
10042
  return { name, size: child.directory ? 0 : getDeterminedSize(child, isPassThrough(child, options)), options: entryOptions };
10003
10043
  });
10004
10044
  const writeOrderGuaranteed = !options.bufferedWrite ||
10005
- (entries.every(entry => entry.options.keepOrder !== false) && zipEntry.children.every(child => !child.children.length));
10045
+ (entries.every(entry => entry.options.keepOrder !== false) &&
10046
+ children.every(child => isImplicitDirectory(child) || !child.children.length));
10006
10047
  return getEntriesSize(options, entries, writeOrderGuaranteed, options.globalComment);
10007
10048
  }
10008
10049
 
@@ -11031,6 +11072,7 @@
11031
11072
  exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
11032
11073
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
11033
11074
  exports.ERR_INVALID_PASS_THROUGH = ERR_INVALID_PASS_THROUGH;
11075
+ exports.ERR_INVALID_READER = ERR_INVALID_READER;
11034
11076
  exports.ERR_INVALID_READER_OPTIONS = ERR_INVALID_READER_OPTIONS;
11035
11077
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
11036
11078
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
@@ -11059,6 +11101,7 @@
11059
11101
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
11060
11102
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
11061
11103
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
11104
+ exports.ERR_UNSUPPORTED_SPLIT_USDZ = ERR_UNSUPPORTED_SPLIT_USDZ;
11062
11105
  exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
11063
11106
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
11064
11107
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;