@zip.js/zip.js 2.11.2 → 2.11.4

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
  /*
@@ -217,6 +217,8 @@
217
217
  const ERR_INVALID_FUNCTION_OPTION = "Invalid option (must be a function)";
218
218
  const ERR_INVALID_SIGNAL = "Invalid signal (must be an AbortSignal instance)";
219
219
  const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
220
+ const ERR_ABORTED = "The operation was aborted";
221
+ const ABORT_ERROR_NAME = "AbortError";
220
222
 
221
223
  function checkFunctionOption(value) {
222
224
  if (value && typeof value != FUNCTION_TYPE) {
@@ -232,6 +234,12 @@
232
234
  return signal || UNDEFINED_VALUE;
233
235
  }
234
236
 
237
+ function throwIfAborted(signal) {
238
+ if (signal && signal.aborted) {
239
+ throw signal.reason === UNDEFINED_VALUE ? new DOMException(ERR_ABORTED, ABORT_ERROR_NAME) : signal.reason;
240
+ }
241
+ }
242
+
235
243
  function checkPasswordOption(password, rawPassword) {
236
244
  if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
237
245
  throw new Error(ERR_INVALID_PASSWORD_TYPE);
@@ -3754,11 +3762,13 @@
3754
3762
  const reader = this;
3755
3763
  const { sourceBlob, size } = reader;
3756
3764
  const { offset = 0, size: readSize = size - offset } = options || {};
3757
- if (!offset && readSize >= size) {
3758
- return toCompatibleReadable(sourceBlob.stream());
3759
- }
3760
- if (blobSliceReliable) {
3761
- return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
3765
+ if (typeof sourceBlob.stream == FUNCTION_TYPE) {
3766
+ if (!offset && readSize >= size) {
3767
+ return toCompatibleReadable(sourceBlob.stream());
3768
+ }
3769
+ if (blobSliceReliable) {
3770
+ return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
3771
+ }
3762
3772
  }
3763
3773
  return super.createReadable(options);
3764
3774
  }
@@ -5174,27 +5184,28 @@
5174
5184
  const { done, value } = await gen.next();
5175
5185
  if (done)
5176
5186
  return controller.close();
5177
- const chunk = {
5178
- ...value,
5179
- readable: (function () {
5180
- const { readable, writable } = new TransformStream();
5181
- if (value.getData) {
5182
- getData();
5183
- return readable;
5184
- }
5187
+ const entryReadable = (function () {
5188
+ const { readable, writable } = new TransformStream();
5189
+ if (value.getData) {
5190
+ getData();
5191
+ return readable;
5192
+ }
5185
5193
 
5186
- async function getData() {
5194
+ async function getData() {
5195
+ try {
5196
+ await value.getData(writable);
5197
+ } catch (error) {
5187
5198
  try {
5188
- await value.getData(writable);
5189
- } catch (error) {
5190
- try {
5191
- await writable.abort(error);
5192
- } catch {
5193
- // ignored
5194
- }
5199
+ await writable.abort(error);
5200
+ } catch {
5201
+ // ignored
5195
5202
  }
5196
5203
  }
5197
- })()
5204
+ }
5205
+ })();
5206
+ const chunk = {
5207
+ ...value,
5208
+ readable: entryReadable
5198
5209
  };
5199
5210
  delete chunk.getData;
5200
5211
  controller.enqueue(chunk);
@@ -5340,6 +5351,7 @@
5340
5351
  const size = compressedSize;
5341
5352
  const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
5342
5353
  const signal = checkSignalOption(getOptionValue$1(zipEntry, options, OPTION_SIGNAL));
5354
+ throwIfAborted(signal);
5343
5355
  const checkPasswordOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
5344
5356
  let checkOverlappingEntry = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
5345
5357
  const checkOverlappingEntryOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY_ONLY);
@@ -6246,6 +6258,7 @@
6246
6258
  const ERR_INVALID_VERSION = "Version exceeds 65535";
6247
6259
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
6248
6260
  const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
6261
+ const ERR_UNSUPPORTED_SPLIT_USDZ = "Split zip files are not supported in USDZ files";
6249
6262
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
6250
6263
  const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
6251
6264
  const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
@@ -6260,6 +6273,7 @@
6260
6273
  const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
6261
6274
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
6262
6275
  const ERR_UNDEFINED_READER = "Undefined reader";
6276
+ const ERR_INVALID_READER = "Invalid reader (must be a Reader instance, a ReadableStream instance, or an object with a 'readable' property)";
6263
6277
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
6264
6278
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
6265
6279
  const ERR_INVALID_GID = "Invalid gid (must be integer 0..2^32-1)";
@@ -6291,6 +6305,9 @@
6291
6305
  const addSplitZipSignature =
6292
6306
  availableSize > 0 && availableSize !== INFINITY_VALUE &&
6293
6307
  maxSize > 0 && maxSize !== INFINITY_VALUE;
6308
+ if (addSplitZipSignature && options[OPTION_USDZ]) {
6309
+ throw new Error(ERR_UNSUPPORTED_SPLIT_USDZ);
6310
+ }
6294
6311
  Object.assign(this, {
6295
6312
  writer,
6296
6313
  addSplitZipSignature,
@@ -6406,6 +6423,7 @@
6406
6423
  }
6407
6424
  const { offset, diskNumberStart } = entryPositions.get(entry);
6408
6425
  Object.assign(entry, {
6426
+ zip64Enabled: true,
6409
6427
  zip64UncompressedSize,
6410
6428
  zip64CompressedSize,
6411
6429
  offset,
@@ -6864,6 +6882,7 @@
6864
6882
  const createTempStream = getFunctionOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
6865
6883
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, true);
6866
6884
  const signal = checkSignalOption(getOptionValue(zipWriter, options, OPTION_SIGNAL));
6885
+ throwIfAborted(signal);
6867
6886
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
6868
6887
  const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
6869
6888
  const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
@@ -6981,6 +7000,9 @@
6981
7000
  if (reader) {
6982
7001
  reader = new GenericReader(reader);
6983
7002
  await initStream(reader);
7003
+ if (!reader.readable && !reader.readUint8Array) {
7004
+ throw new Error(ERR_INVALID_READER);
7005
+ }
6984
7006
  ({ size: contentSize } = reader);
6985
7007
  }
6986
7008
  return Object.assign({ reader }, resolveEntrySizes(zipWriter, Boolean(reader), contentSize, metadata, options));
@@ -6991,6 +7013,7 @@
6991
7013
  let { dataDescriptor, zip64, level, compressionMethod } = metadata;
6992
7014
  let maximumCompressedSize = 0;
6993
7015
  let uncompressedSize = 0;
7016
+ let unknownSize = false;
6994
7017
  if (passThrough && hasContent) {
6995
7018
  uncompressedSize = options[PROPERTY_NAME_UNCOMPRESSED_SIZE];
6996
7019
  if (uncompressedSize === UNDEFINED_VALUE) {
@@ -7016,8 +7039,8 @@
7016
7039
  if (contentSize === UNDEFINED_VALUE) {
7017
7040
  dataDescriptor = true;
7018
7041
  if (zip64 || zip64 === UNDEFINED_VALUE) {
7019
- zip64 = true;
7020
- uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
7042
+ zip64 = unknownSize = true;
7043
+ maximumCompressedSize = MAX_32_BITS + 1;
7021
7044
  }
7022
7045
  } else {
7023
7046
  options.uncompressedSize = uncompressedSize = contentSize;
@@ -7032,7 +7055,7 @@
7032
7055
  if (emptyEntry && !zipCrypto && getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR) === UNDEFINED_VALUE) {
7033
7056
  dataDescriptor = false;
7034
7057
  }
7035
- const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
7058
+ const zip64UncompressedSize = zip64Enabled || unknownSize || uncompressedSize >= MAX_32_BITS;
7036
7059
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
7037
7060
  if (zip64UncompressedSize || zip64CompressedSize) {
7038
7061
  if (zip64 === false) {
@@ -7048,6 +7071,8 @@
7048
7071
  dataDescriptor,
7049
7072
  emptyEntry,
7050
7073
  zip64,
7074
+ zip64Enabled,
7075
+ unknownSize,
7051
7076
  zip64UncompressedSize,
7052
7077
  zip64CompressedSize,
7053
7078
  uncompressedSize,
@@ -7246,6 +7271,7 @@
7246
7271
  rawPassword,
7247
7272
  level,
7248
7273
  zip64,
7274
+ zip64Enabled,
7249
7275
  zip64UncompressedSize,
7250
7276
  zip64CompressedSize,
7251
7277
  zipCrypto,
@@ -7286,6 +7312,7 @@
7286
7312
  lockFileEntry,
7287
7313
  versionMadeBy,
7288
7314
  zip64,
7315
+ zip64Enabled,
7289
7316
  directory: Boolean(directory),
7290
7317
  executable: Boolean(executable),
7291
7318
  filenameUTF8: true,
@@ -7429,13 +7456,14 @@
7429
7456
  zip64UncompressedSize,
7430
7457
  zip64CompressedSize,
7431
7458
  uncompressedSize,
7459
+ unknownSize,
7432
7460
  crc32
7433
7461
  } = options;
7434
7462
  let { version, compressionMethod } = options;
7435
7463
  const compressed = !directory && isCompressed(compressionMethod, level);
7436
7464
  let rawLocalExtraFieldZip64;
7437
7465
  const uncompressedFile = passThrough || !compressed;
7438
- const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
7466
+ const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || !dataDescriptor || ((!zip64UncompressedSize && !zip64CompressedSize) || (uncompressedFile && !unknownSize)));
7439
7467
  const writeLocalExtraFieldZip64 = zip64ExtraFieldComplete || (zip64 && dataDescriptor && (zip64UncompressedSize || zip64CompressedSize));
7440
7468
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
7441
7469
  const length = 4 + 16;
@@ -7569,6 +7597,10 @@
7569
7597
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
7570
7598
  }
7571
7599
  const dosLastModDate = new Date(Math.ceil(Math.floor(lastModDate.getTime() / 1000) / 2) * 2000);
7600
+ const clampedLastModDate = dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate;
7601
+ const storedLastModDate = getLength(rawExtraFieldExtendedTimestamp) ?
7602
+ new Date(getTimeUnix(lastModDate) * 1000) :
7603
+ getLength(rawExtraFieldNTFS) ? lastModDate : clampedLastModDate;
7572
7604
  const {
7573
7605
  headerArray,
7574
7606
  headerView,
@@ -7578,7 +7610,7 @@
7578
7610
  bitFlag: getBitFlag(level, useUnicodeFileNames, dataDescriptor, encrypted, compressionMethod),
7579
7611
  compressionMethod,
7580
7612
  uncompressedSize,
7581
- lastModDate: dosLastModDate < MIN_DATE ? MIN_DATE : dosLastModDate > MAX_DATE ? MAX_DATE : dosLastModDate,
7613
+ lastModDate: clampedLastModDate,
7582
7614
  rawLastModDate: rawLastModDateOption,
7583
7615
  rawFilename,
7584
7616
  zip64CompressedSize,
@@ -7613,7 +7645,7 @@
7613
7645
  localHeaderView,
7614
7646
  headerArray,
7615
7647
  headerView,
7616
- lastModDate,
7648
+ lastModDate: storedLastModDate,
7617
7649
  rawLastModDate,
7618
7650
  encrypted,
7619
7651
  compressed,
@@ -7785,14 +7817,15 @@
7785
7817
 
7786
7818
 
7787
7819
  async function closeFile(zipWriter, comment, options) {
7788
- const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7820
+ const { directoryDataLength, zip64Entries } = createDirectoryRecords(zipWriter.fileEntries);
7789
7821
  const { directoryStart, directoryEnd, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7790
7822
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7791
- await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength });
7823
+ await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryEnd, directoryDataLength, signatureLength, zip64Entries });
7792
7824
  }
7793
7825
 
7794
7826
  function createDirectoryRecords(files) {
7795
7827
  let directoryDataLength = 0;
7828
+ let zip64Entries = false;
7796
7829
  for (const [, fileEntry] of files) {
7797
7830
  const {
7798
7831
  rawFilename,
@@ -7805,11 +7838,20 @@
7805
7838
  extendedTimestamp,
7806
7839
  extraFieldExtendedTimestampFlag,
7807
7840
  lastModDate,
7808
- zip64UncompressedSize,
7809
- zip64CompressedSize,
7841
+ zip64Enabled,
7810
7842
  uncompressedSize,
7811
7843
  compressedSize
7812
7844
  } = fileEntry;
7845
+ let { zip64UncompressedSize, zip64CompressedSize } = fileEntry;
7846
+ if (!zip64Enabled) {
7847
+ if (zip64UncompressedSize && uncompressedSize < MAX_32_BITS) {
7848
+ zip64UncompressedSize = fileEntry.zip64UncompressedSize = false;
7849
+ }
7850
+ if (zip64CompressedSize && compressedSize < MAX_32_BITS) {
7851
+ zip64CompressedSize = fileEntry.zip64CompressedSize = false;
7852
+ }
7853
+ }
7854
+ zip64Entries = zip64Entries || zip64UncompressedSize || zip64CompressedSize;
7813
7855
  const zip64Offset = fileEntry.offset >= MAX_32_BITS;
7814
7856
  const zip64DiskNumberStart = fileEntry.diskNumberStart >= MAX_16_BITS;
7815
7857
  let rawExtraFieldZip64;
@@ -7863,7 +7905,7 @@
7863
7905
  }
7864
7906
  directoryDataLength += CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
7865
7907
  }
7866
- return directoryDataLength;
7908
+ return { directoryDataLength, zip64Entries };
7867
7909
  }
7868
7910
 
7869
7911
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
@@ -7983,7 +8025,7 @@
7983
8025
 
7984
8026
  async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7985
8027
  const { writer } = zipWriter;
7986
- const { directoryStart, directoryEnd, signatureLength } = cdInfo;
8028
+ const { directoryStart, directoryEnd, signatureLength, zip64Entries } = cdInfo;
7987
8029
  let { directoryDataLength } = cdInfo;
7988
8030
  let fileEntriesLength = zipWriter.fileEntries.size;
7989
8031
  let diskNumber = directoryStart.diskNumber;
@@ -8003,6 +8045,8 @@
8003
8045
  } else {
8004
8046
  zip64 = true;
8005
8047
  }
8048
+ } else if (zip64 === UNDEFINED_VALUE && zip64Entries) {
8049
+ zip64 = true;
8006
8050
  }
8007
8051
  const endOfdirectoryRecord = createRecordWriter(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8008
8052
  if (exceedsAvailableSize(writer, getLength(endOfdirectoryRecord.array) + commentLength)) {
@@ -8506,7 +8550,7 @@
8506
8550
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8507
8551
  */
8508
8552
 
8509
- const VERSION = "2.11.2";
8553
+ const VERSION = "2.11.4";
8510
8554
 
8511
8555
  /*
8512
8556
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -8997,6 +9041,7 @@
8997
9041
  exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
8998
9042
  exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
8999
9043
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
9044
+ exports.ERR_INVALID_READER = ERR_INVALID_READER;
9000
9045
  exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
9001
9046
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
9002
9047
  exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;
@@ -9023,6 +9068,7 @@
9023
9068
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
9024
9069
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
9025
9070
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
9071
+ exports.ERR_UNSUPPORTED_SPLIT_USDZ = ERR_UNSUPPORTED_SPLIT_USDZ;
9026
9072
  exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
9027
9073
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
9028
9074
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;