@zip.js/zip.js 2.8.22 → 2.8.24

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/index.cjs CHANGED
@@ -4372,7 +4372,7 @@ const ERR_INVALID_VERSION = "Version exceeds 65535";
4372
4372
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
4373
4373
  const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
4374
4374
  const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
4375
- const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (make sure 'keepOrder' is set to 'true')";
4375
+ const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (set the 'zip64' option to 'true')";
4376
4376
  const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
4377
4377
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
4378
4378
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
@@ -4788,14 +4788,11 @@ async function addFile(zipWriter, name, reader, options) {
4788
4788
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
4789
4789
  }
4790
4790
  }
4791
- const { diskOffset, diskNumber, maxSize } = zipWriter.writer;
4791
+ const { diskOffset, diskNumber } = zipWriter.writer;
4792
4792
  const zip64UncompressedSize = zip64Enabled || uncompressedSize > MAX_32_BITS;
4793
4793
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize > MAX_32_BITS;
4794
- const zip64Offset = zip64Enabled || zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset > MAX_32_BITS;
4795
- const supportZip64SplitFile = getOptionValue(zipWriter, options, OPTION_SUPPORT_ZIP64_SPLIT_FILE, true);
4796
- const zip64DiskNumberStart = (supportZip64SplitFile && zip64Enabled) || diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) > MAX_16_BITS;
4797
- if (zip64Offset || zip64UncompressedSize || zip64CompressedSize || zip64DiskNumberStart) {
4798
- if (zip64 === false || !keepOrder) {
4794
+ if (zip64UncompressedSize || zip64CompressedSize) {
4795
+ if (zip64 === false) {
4799
4796
  throw new Error(ERR_UNSUPPORTED_FORMAT);
4800
4797
  } else {
4801
4798
  zip64 = true;
@@ -4815,8 +4812,6 @@ async function addFile(zipWriter, name, reader, options) {
4815
4812
  zip64,
4816
4813
  zip64UncompressedSize,
4817
4814
  zip64CompressedSize,
4818
- zip64Offset,
4819
- zip64DiskNumberStart,
4820
4815
  password,
4821
4816
  rawPassword,
4822
4817
  level,
@@ -4944,7 +4939,6 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
4944
4939
  await writeData(fileWriter, localHeaderArray);
4945
4940
  }
4946
4941
  fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
4947
- const { zip64 } = fileEntry;
4948
4942
  if (!bufferedWrite) {
4949
4943
  writingEntryData = false;
4950
4944
  }
@@ -4956,9 +4950,6 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
4956
4950
  writingBufferedEntryData = true;
4957
4951
  fileEntry.diskNumberStart = writer.diskNumber;
4958
4952
  fileEntry.offset = zipWriter.offset - writer.diskOffset;
4959
- if (zip64) {
4960
- updateZip64ExtraField(fileEntry);
4961
- }
4962
4953
  updateLocalHeader(fileEntry, localHeaderView, options);
4963
4954
  await skipDiskIfNeeded(writable);
4964
4955
  await writeData(writer, localHeaderArray);
@@ -4967,12 +4958,6 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
4967
4958
  writingBufferedEntryData = false;
4968
4959
  } else {
4969
4960
  fileEntry.offset = zipWriter.offset - diskOffset;
4970
- if (zip64) {
4971
- updateZip64ExtraField(fileEntry);
4972
- }
4973
- }
4974
- if (fileEntry.offset > MAX_32_BITS && !zip64) {
4975
- throw new Error(ERR_UNSUPPORTED_FORMAT);
4976
4961
  }
4977
4962
  zipWriter.offset += fileEntry.size;
4978
4963
  return fileEntry;
@@ -5062,8 +5047,6 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
5062
5047
  zip64,
5063
5048
  zip64UncompressedSize,
5064
5049
  zip64CompressedSize,
5065
- zip64Offset,
5066
- zip64DiskNumberStart,
5067
5050
  zipCrypto,
5068
5051
  dataDescriptor,
5069
5052
  directory,
@@ -5201,9 +5184,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
5201
5184
  signature,
5202
5185
  extraFieldExtendedTimestampFlag,
5203
5186
  zip64UncompressedSize,
5204
- zip64CompressedSize,
5205
- zip64Offset,
5206
- zip64DiskNumberStart
5187
+ zip64CompressedSize
5207
5188
  });
5208
5189
  return fileEntry;
5209
5190
  }
@@ -5227,74 +5208,41 @@ function getHeaderInfo(options) {
5227
5208
  encrypted,
5228
5209
  zip64UncompressedSize,
5229
5210
  zip64CompressedSize,
5230
- zip64Offset,
5231
- zip64DiskNumberStart,
5232
- uncompressedSize,
5233
- offset,
5234
- diskNumberStart
5211
+ uncompressedSize
5235
5212
  } = options;
5236
5213
  let { version, compressionMethod } = options;
5237
5214
  const compressed = !directory && (level > 0 || (level === UNDEFINED_VALUE && compressionMethod !== 0));
5238
- let rawExtraFieldZip64;
5239
5215
  let rawLocalExtraFieldZip64;
5240
5216
  const uncompressedFile = passThrough || !compressed;
5241
5217
  const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
5242
5218
  if (zip64) {
5243
- let rawExtraFieldZip64Length = 4;
5244
5219
  let rawLocalExtraFieldZip64Length = 4;
5245
5220
  if (zip64UncompressedSize) {
5246
- rawExtraFieldZip64Length += 8;
5247
5221
  rawLocalExtraFieldZip64Length += 8;
5248
5222
  }
5249
5223
  if (zip64CompressedSize) {
5250
- rawExtraFieldZip64Length += 8;
5251
5224
  rawLocalExtraFieldZip64Length += 8;
5252
5225
  }
5253
- if (zip64Offset) {
5254
- rawExtraFieldZip64Length += 8;
5255
- }
5256
- if (zip64DiskNumberStart) {
5257
- rawExtraFieldZip64Length += 4;
5258
- }
5259
- rawExtraFieldZip64 = new Uint8Array(rawExtraFieldZip64Length);
5260
- const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
5261
5226
  rawLocalExtraFieldZip64 = new Uint8Array(rawLocalExtraFieldZip64Length);
5262
5227
  const rawLocalExtraFieldZip64View = getDataView(rawLocalExtraFieldZip64);
5263
- setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
5264
- setUint16(rawExtraFieldZip64View, 2, getLength(rawExtraFieldZip64) - 4);
5265
5228
  setUint16(rawLocalExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
5266
5229
  setUint16(rawLocalExtraFieldZip64View, 2, getLength(rawLocalExtraFieldZip64) - 4);
5267
5230
  if (zip64ExtraFieldComplete) {
5268
- const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
5269
5231
  const rawLocalExtraFieldZip64View = getDataView(rawLocalExtraFieldZip64);
5270
- let rawExtraFieldZip64Offset = 4;
5271
5232
  let rawLocalExtraFieldZip64Offset = 4;
5272
5233
  if (zip64UncompressedSize) {
5273
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(uncompressedSize));
5274
- rawExtraFieldZip64Offset += 8;
5275
5234
  setBigUint64(rawLocalExtraFieldZip64View, rawLocalExtraFieldZip64Offset, BigInt(uncompressedSize));
5276
5235
  rawLocalExtraFieldZip64Offset += 8;
5277
5236
  }
5278
5237
  if (zip64CompressedSize && uncompressedFile) {
5279
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(uncompressedSize));
5280
- rawExtraFieldZip64Offset += 8;
5281
5238
  setBigUint64(rawLocalExtraFieldZip64View, rawLocalExtraFieldZip64Offset, BigInt(uncompressedSize));
5282
5239
  rawLocalExtraFieldZip64Offset += 8;
5283
5240
  }
5284
- if (zip64Offset) {
5285
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(offset));
5286
- rawExtraFieldZip64Offset += 8;
5287
- }
5288
- if (zip64DiskNumberStart) {
5289
- setUint32(rawExtraFieldZip64View, rawExtraFieldZip64Offset, diskNumberStart);
5290
- rawExtraFieldZip64Offset += 4;
5291
- }
5292
5241
  if (rawLocalExtraFieldZip64Offset == 4) {
5293
5242
  rawLocalExtraFieldZip64 = new Uint8Array();
5294
5243
  }
5295
5244
  }
5296
5245
  } else {
5297
- rawExtraFieldZip64 = new Uint8Array();
5298
5246
  rawLocalExtraFieldZip64 = new Uint8Array();
5299
5247
  }
5300
5248
  let rawExtraFieldAES;
@@ -5451,7 +5399,7 @@ function getHeaderInfo(options) {
5451
5399
  version,
5452
5400
  compressionMethod,
5453
5401
  extraFieldExtendedTimestampFlag,
5454
- rawExtraFieldZip64,
5402
+ rawExtraFieldZip64: new Uint8Array(),
5455
5403
  localExtraFieldZip64Length,
5456
5404
  rawExtraFieldExtendedTimestamp,
5457
5405
  rawExtraFieldNTFS,
@@ -5623,35 +5571,6 @@ function updateLocalHeader({
5623
5571
  }
5624
5572
  }
5625
5573
 
5626
- function updateZip64ExtraField({
5627
- compressedSize,
5628
- uncompressedSize,
5629
- offset,
5630
- diskNumberStart,
5631
- zip64UncompressedSize,
5632
- zip64CompressedSize,
5633
- zip64Offset,
5634
- zip64DiskNumberStart,
5635
- rawExtraFieldZip64
5636
- }) {
5637
- const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
5638
- let rawExtraFieldZip64Offset = 4;
5639
- if (zip64UncompressedSize) {
5640
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(uncompressedSize));
5641
- rawExtraFieldZip64Offset += 8;
5642
- }
5643
- if (zip64CompressedSize) {
5644
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(compressedSize));
5645
- rawExtraFieldZip64Offset += 8;
5646
- }
5647
- if (zip64Offset) {
5648
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(offset));
5649
- rawExtraFieldZip64Offset += 8;
5650
- }
5651
- if (zip64DiskNumberStart) {
5652
- setUint32(rawExtraFieldZip64View, rawExtraFieldZip64Offset, diskNumberStart);
5653
- }
5654
- }
5655
5574
 
5656
5575
  async function closeFile(zipWriter, comment, options) {
5657
5576
  const { files, writer } = zipWriter;
@@ -5664,7 +5583,6 @@ async function closeFile(zipWriter, comment, options) {
5664
5583
  for (const [, fileEntry] of files) {
5665
5584
  const {
5666
5585
  rawFilename,
5667
- rawExtraFieldZip64,
5668
5586
  rawExtraFieldAES,
5669
5587
  rawComment,
5670
5588
  rawExtraFieldNTFS,
@@ -5672,8 +5590,36 @@ async function closeFile(zipWriter, comment, options) {
5672
5590
  rawExtraField,
5673
5591
  extendedTimestamp,
5674
5592
  extraFieldExtendedTimestampFlag,
5675
- lastModDate
5593
+ lastModDate,
5594
+ zip64UncompressedSize,
5595
+ zip64CompressedSize,
5596
+ uncompressedSize,
5597
+ compressedSize
5676
5598
  } = fileEntry;
5599
+ const zip64Offset = fileEntry.offset > MAX_32_BITS;
5600
+ const zip64DiskNumberStart = fileEntry.diskNumberStart > MAX_16_BITS;
5601
+ let rawExtraFieldZip64;
5602
+ if (zip64Offset || zip64DiskNumberStart || zip64UncompressedSize || zip64CompressedSize) {
5603
+ let length = 4;
5604
+ if (zip64UncompressedSize) length += 8;
5605
+ if (zip64CompressedSize) length += 8;
5606
+ if (zip64Offset) length += 8;
5607
+ if (zip64DiskNumberStart) length += 4;
5608
+ rawExtraFieldZip64 = new Uint8Array(length);
5609
+ const zip64View = getDataView(rawExtraFieldZip64);
5610
+ setUint16(zip64View, 0, EXTRAFIELD_TYPE_ZIP64);
5611
+ setUint16(zip64View, 2, length - 4);
5612
+ let zip64FieldOffset = 4;
5613
+ if (zip64UncompressedSize) { setBigUint64(zip64View, zip64FieldOffset, BigInt(uncompressedSize)); zip64FieldOffset += 8; }
5614
+ if (zip64CompressedSize) { setBigUint64(zip64View, zip64FieldOffset, BigInt(compressedSize)); zip64FieldOffset += 8; }
5615
+ if (zip64Offset) { setBigUint64(zip64View, zip64FieldOffset, BigInt(fileEntry.offset)); zip64FieldOffset += 8; }
5616
+ if (zip64DiskNumberStart) { setUint32(zip64View, zip64FieldOffset, fileEntry.diskNumberStart); }
5617
+ } else {
5618
+ rawExtraFieldZip64 = new Uint8Array();
5619
+ }
5620
+ fileEntry.rawExtraFieldZip64 = rawExtraFieldZip64;
5621
+ fileEntry.zip64Offset = zip64Offset;
5622
+ fileEntry.zip64DiskNumberStart = zip64DiskNumberStart;
5677
5623
  let rawExtraFieldTimestamp;
5678
5624
  if (extendedTimestamp) {
5679
5625
  rawExtraFieldTimestamp = new Uint8Array(9);
@@ -5715,7 +5661,6 @@ async function closeFile(zipWriter, comment, options) {
5715
5661
  versionMadeBy,
5716
5662
  headerArray,
5717
5663
  headerView,
5718
- zip64,
5719
5664
  zip64UncompressedSize,
5720
5665
  zip64CompressedSize,
5721
5666
  zip64DiskNumberStart,
@@ -5741,7 +5686,7 @@ async function closeFile(zipWriter, comment, options) {
5741
5686
  directoryOffset += 2;
5742
5687
  setUint16(directoryView, directoryOffset, getLength(rawComment));
5743
5688
  directoryOffset += 2;
5744
- setUint16(directoryView, directoryOffset, zip64 && zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
5689
+ setUint16(directoryView, directoryOffset, zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
5745
5690
  directoryOffset += 2;
5746
5691
  setUint16(directoryView, directoryOffset, internalFileAttributes);
5747
5692
  directoryOffset += 2;
@@ -5749,7 +5694,7 @@ async function closeFile(zipWriter, comment, options) {
5749
5694
  setUint32(directoryView, directoryOffset, externalFileAttributes);
5750
5695
  }
5751
5696
  directoryOffset += 4;
5752
- setUint32(directoryView, directoryOffset, zip64 && zip64Offset ? MAX_32_BITS : fileEntryOffset);
5697
+ setUint32(directoryView, directoryOffset, zip64Offset ? MAX_32_BITS : fileEntryOffset);
5753
5698
  directoryOffset += 4;
5754
5699
  arraySet(directoryArray, rawFilename, directoryOffset);
5755
5700
  directoryOffset += getLength(rawFilename);
package/index.d.ts CHANGED
@@ -1448,8 +1448,7 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
1448
1448
  /**
1449
1449
  * `true` to keep the order of the entry physically in the zip file.
1450
1450
  *
1451
- * When set to `true`, the use of web workers will be improved. However, it also prevents files larger than 4GB from being created without setting the `zip64` option to `true` explicitly.
1452
- * Another solution to improve the use of web workers is to add entries from smallest to largest in uncompressed size.
1451
+ * When set to `true`, the use of web workers will be improved.
1453
1452
  *
1454
1453
  * @defaultValue true
1455
1454
  */