@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/dist/zip.js CHANGED
@@ -4378,7 +4378,7 @@
4378
4378
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
4379
4379
  const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
4380
4380
  const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
4381
- const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (make sure 'keepOrder' is set to 'true')";
4381
+ const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (set the 'zip64' option to 'true')";
4382
4382
  const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
4383
4383
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
4384
4384
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
@@ -4794,14 +4794,11 @@
4794
4794
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
4795
4795
  }
4796
4796
  }
4797
- const { diskOffset, diskNumber, maxSize } = zipWriter.writer;
4797
+ const { diskOffset, diskNumber } = zipWriter.writer;
4798
4798
  const zip64UncompressedSize = zip64Enabled || uncompressedSize > MAX_32_BITS;
4799
4799
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize > MAX_32_BITS;
4800
- const zip64Offset = zip64Enabled || zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset > MAX_32_BITS;
4801
- const supportZip64SplitFile = getOptionValue(zipWriter, options, OPTION_SUPPORT_ZIP64_SPLIT_FILE, true);
4802
- const zip64DiskNumberStart = (supportZip64SplitFile && zip64Enabled) || diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) > MAX_16_BITS;
4803
- if (zip64Offset || zip64UncompressedSize || zip64CompressedSize || zip64DiskNumberStart) {
4804
- if (zip64 === false || !keepOrder) {
4800
+ if (zip64UncompressedSize || zip64CompressedSize) {
4801
+ if (zip64 === false) {
4805
4802
  throw new Error(ERR_UNSUPPORTED_FORMAT);
4806
4803
  } else {
4807
4804
  zip64 = true;
@@ -4821,8 +4818,6 @@
4821
4818
  zip64,
4822
4819
  zip64UncompressedSize,
4823
4820
  zip64CompressedSize,
4824
- zip64Offset,
4825
- zip64DiskNumberStart,
4826
4821
  password,
4827
4822
  rawPassword,
4828
4823
  level,
@@ -4950,7 +4945,6 @@
4950
4945
  await writeData(fileWriter, localHeaderArray);
4951
4946
  }
4952
4947
  fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
4953
- const { zip64 } = fileEntry;
4954
4948
  if (!bufferedWrite) {
4955
4949
  writingEntryData = false;
4956
4950
  }
@@ -4962,9 +4956,6 @@
4962
4956
  writingBufferedEntryData = true;
4963
4957
  fileEntry.diskNumberStart = writer.diskNumber;
4964
4958
  fileEntry.offset = zipWriter.offset - writer.diskOffset;
4965
- if (zip64) {
4966
- updateZip64ExtraField(fileEntry);
4967
- }
4968
4959
  updateLocalHeader(fileEntry, localHeaderView, options);
4969
4960
  await skipDiskIfNeeded(writable);
4970
4961
  await writeData(writer, localHeaderArray);
@@ -4973,12 +4964,6 @@
4973
4964
  writingBufferedEntryData = false;
4974
4965
  } else {
4975
4966
  fileEntry.offset = zipWriter.offset - diskOffset;
4976
- if (zip64) {
4977
- updateZip64ExtraField(fileEntry);
4978
- }
4979
- }
4980
- if (fileEntry.offset > MAX_32_BITS && !zip64) {
4981
- throw new Error(ERR_UNSUPPORTED_FORMAT);
4982
4967
  }
4983
4968
  zipWriter.offset += fileEntry.size;
4984
4969
  return fileEntry;
@@ -5068,8 +5053,6 @@
5068
5053
  zip64,
5069
5054
  zip64UncompressedSize,
5070
5055
  zip64CompressedSize,
5071
- zip64Offset,
5072
- zip64DiskNumberStart,
5073
5056
  zipCrypto,
5074
5057
  dataDescriptor,
5075
5058
  directory,
@@ -5207,9 +5190,7 @@
5207
5190
  signature,
5208
5191
  extraFieldExtendedTimestampFlag,
5209
5192
  zip64UncompressedSize,
5210
- zip64CompressedSize,
5211
- zip64Offset,
5212
- zip64DiskNumberStart
5193
+ zip64CompressedSize
5213
5194
  });
5214
5195
  return fileEntry;
5215
5196
  }
@@ -5233,74 +5214,41 @@
5233
5214
  encrypted,
5234
5215
  zip64UncompressedSize,
5235
5216
  zip64CompressedSize,
5236
- zip64Offset,
5237
- zip64DiskNumberStart,
5238
- uncompressedSize,
5239
- offset,
5240
- diskNumberStart
5217
+ uncompressedSize
5241
5218
  } = options;
5242
5219
  let { version, compressionMethod } = options;
5243
5220
  const compressed = !directory && (level > 0 || (level === UNDEFINED_VALUE && compressionMethod !== 0));
5244
- let rawExtraFieldZip64;
5245
5221
  let rawLocalExtraFieldZip64;
5246
5222
  const uncompressedFile = passThrough || !compressed;
5247
5223
  const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
5248
5224
  if (zip64) {
5249
- let rawExtraFieldZip64Length = 4;
5250
5225
  let rawLocalExtraFieldZip64Length = 4;
5251
5226
  if (zip64UncompressedSize) {
5252
- rawExtraFieldZip64Length += 8;
5253
5227
  rawLocalExtraFieldZip64Length += 8;
5254
5228
  }
5255
5229
  if (zip64CompressedSize) {
5256
- rawExtraFieldZip64Length += 8;
5257
5230
  rawLocalExtraFieldZip64Length += 8;
5258
5231
  }
5259
- if (zip64Offset) {
5260
- rawExtraFieldZip64Length += 8;
5261
- }
5262
- if (zip64DiskNumberStart) {
5263
- rawExtraFieldZip64Length += 4;
5264
- }
5265
- rawExtraFieldZip64 = new Uint8Array(rawExtraFieldZip64Length);
5266
- const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
5267
5232
  rawLocalExtraFieldZip64 = new Uint8Array(rawLocalExtraFieldZip64Length);
5268
5233
  const rawLocalExtraFieldZip64View = getDataView(rawLocalExtraFieldZip64);
5269
- setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
5270
- setUint16(rawExtraFieldZip64View, 2, getLength(rawExtraFieldZip64) - 4);
5271
5234
  setUint16(rawLocalExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
5272
5235
  setUint16(rawLocalExtraFieldZip64View, 2, getLength(rawLocalExtraFieldZip64) - 4);
5273
5236
  if (zip64ExtraFieldComplete) {
5274
- const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
5275
5237
  const rawLocalExtraFieldZip64View = getDataView(rawLocalExtraFieldZip64);
5276
- let rawExtraFieldZip64Offset = 4;
5277
5238
  let rawLocalExtraFieldZip64Offset = 4;
5278
5239
  if (zip64UncompressedSize) {
5279
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(uncompressedSize));
5280
- rawExtraFieldZip64Offset += 8;
5281
5240
  setBigUint64(rawLocalExtraFieldZip64View, rawLocalExtraFieldZip64Offset, BigInt(uncompressedSize));
5282
5241
  rawLocalExtraFieldZip64Offset += 8;
5283
5242
  }
5284
5243
  if (zip64CompressedSize && uncompressedFile) {
5285
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(uncompressedSize));
5286
- rawExtraFieldZip64Offset += 8;
5287
5244
  setBigUint64(rawLocalExtraFieldZip64View, rawLocalExtraFieldZip64Offset, BigInt(uncompressedSize));
5288
5245
  rawLocalExtraFieldZip64Offset += 8;
5289
5246
  }
5290
- if (zip64Offset) {
5291
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(offset));
5292
- rawExtraFieldZip64Offset += 8;
5293
- }
5294
- if (zip64DiskNumberStart) {
5295
- setUint32(rawExtraFieldZip64View, rawExtraFieldZip64Offset, diskNumberStart);
5296
- rawExtraFieldZip64Offset += 4;
5297
- }
5298
5247
  if (rawLocalExtraFieldZip64Offset == 4) {
5299
5248
  rawLocalExtraFieldZip64 = new Uint8Array();
5300
5249
  }
5301
5250
  }
5302
5251
  } else {
5303
- rawExtraFieldZip64 = new Uint8Array();
5304
5252
  rawLocalExtraFieldZip64 = new Uint8Array();
5305
5253
  }
5306
5254
  let rawExtraFieldAES;
@@ -5457,7 +5405,7 @@
5457
5405
  version,
5458
5406
  compressionMethod,
5459
5407
  extraFieldExtendedTimestampFlag,
5460
- rawExtraFieldZip64,
5408
+ rawExtraFieldZip64: new Uint8Array(),
5461
5409
  localExtraFieldZip64Length,
5462
5410
  rawExtraFieldExtendedTimestamp,
5463
5411
  rawExtraFieldNTFS,
@@ -5629,35 +5577,6 @@
5629
5577
  }
5630
5578
  }
5631
5579
 
5632
- function updateZip64ExtraField({
5633
- compressedSize,
5634
- uncompressedSize,
5635
- offset,
5636
- diskNumberStart,
5637
- zip64UncompressedSize,
5638
- zip64CompressedSize,
5639
- zip64Offset,
5640
- zip64DiskNumberStart,
5641
- rawExtraFieldZip64
5642
- }) {
5643
- const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
5644
- let rawExtraFieldZip64Offset = 4;
5645
- if (zip64UncompressedSize) {
5646
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(uncompressedSize));
5647
- rawExtraFieldZip64Offset += 8;
5648
- }
5649
- if (zip64CompressedSize) {
5650
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(compressedSize));
5651
- rawExtraFieldZip64Offset += 8;
5652
- }
5653
- if (zip64Offset) {
5654
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(offset));
5655
- rawExtraFieldZip64Offset += 8;
5656
- }
5657
- if (zip64DiskNumberStart) {
5658
- setUint32(rawExtraFieldZip64View, rawExtraFieldZip64Offset, diskNumberStart);
5659
- }
5660
- }
5661
5580
 
5662
5581
  async function closeFile(zipWriter, comment, options) {
5663
5582
  const { files, writer } = zipWriter;
@@ -5670,7 +5589,6 @@
5670
5589
  for (const [, fileEntry] of files) {
5671
5590
  const {
5672
5591
  rawFilename,
5673
- rawExtraFieldZip64,
5674
5592
  rawExtraFieldAES,
5675
5593
  rawComment,
5676
5594
  rawExtraFieldNTFS,
@@ -5678,8 +5596,36 @@
5678
5596
  rawExtraField,
5679
5597
  extendedTimestamp,
5680
5598
  extraFieldExtendedTimestampFlag,
5681
- lastModDate
5599
+ lastModDate,
5600
+ zip64UncompressedSize,
5601
+ zip64CompressedSize,
5602
+ uncompressedSize,
5603
+ compressedSize
5682
5604
  } = fileEntry;
5605
+ const zip64Offset = fileEntry.offset > MAX_32_BITS;
5606
+ const zip64DiskNumberStart = fileEntry.diskNumberStart > MAX_16_BITS;
5607
+ let rawExtraFieldZip64;
5608
+ if (zip64Offset || zip64DiskNumberStart || zip64UncompressedSize || zip64CompressedSize) {
5609
+ let length = 4;
5610
+ if (zip64UncompressedSize) length += 8;
5611
+ if (zip64CompressedSize) length += 8;
5612
+ if (zip64Offset) length += 8;
5613
+ if (zip64DiskNumberStart) length += 4;
5614
+ rawExtraFieldZip64 = new Uint8Array(length);
5615
+ const zip64View = getDataView(rawExtraFieldZip64);
5616
+ setUint16(zip64View, 0, EXTRAFIELD_TYPE_ZIP64);
5617
+ setUint16(zip64View, 2, length - 4);
5618
+ let zip64FieldOffset = 4;
5619
+ if (zip64UncompressedSize) { setBigUint64(zip64View, zip64FieldOffset, BigInt(uncompressedSize)); zip64FieldOffset += 8; }
5620
+ if (zip64CompressedSize) { setBigUint64(zip64View, zip64FieldOffset, BigInt(compressedSize)); zip64FieldOffset += 8; }
5621
+ if (zip64Offset) { setBigUint64(zip64View, zip64FieldOffset, BigInt(fileEntry.offset)); zip64FieldOffset += 8; }
5622
+ if (zip64DiskNumberStart) { setUint32(zip64View, zip64FieldOffset, fileEntry.diskNumberStart); }
5623
+ } else {
5624
+ rawExtraFieldZip64 = new Uint8Array();
5625
+ }
5626
+ fileEntry.rawExtraFieldZip64 = rawExtraFieldZip64;
5627
+ fileEntry.zip64Offset = zip64Offset;
5628
+ fileEntry.zip64DiskNumberStart = zip64DiskNumberStart;
5683
5629
  let rawExtraFieldTimestamp;
5684
5630
  if (extendedTimestamp) {
5685
5631
  rawExtraFieldTimestamp = new Uint8Array(9);
@@ -5721,7 +5667,6 @@
5721
5667
  versionMadeBy,
5722
5668
  headerArray,
5723
5669
  headerView,
5724
- zip64,
5725
5670
  zip64UncompressedSize,
5726
5671
  zip64CompressedSize,
5727
5672
  zip64DiskNumberStart,
@@ -5747,7 +5692,7 @@
5747
5692
  directoryOffset += 2;
5748
5693
  setUint16(directoryView, directoryOffset, getLength(rawComment));
5749
5694
  directoryOffset += 2;
5750
- setUint16(directoryView, directoryOffset, zip64 && zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
5695
+ setUint16(directoryView, directoryOffset, zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
5751
5696
  directoryOffset += 2;
5752
5697
  setUint16(directoryView, directoryOffset, internalFileAttributes);
5753
5698
  directoryOffset += 2;
@@ -5755,7 +5700,7 @@
5755
5700
  setUint32(directoryView, directoryOffset, externalFileAttributes);
5756
5701
  }
5757
5702
  directoryOffset += 4;
5758
- setUint32(directoryView, directoryOffset, zip64 && zip64Offset ? MAX_32_BITS : fileEntryOffset);
5703
+ setUint32(directoryView, directoryOffset, zip64Offset ? MAX_32_BITS : fileEntryOffset);
5759
5704
  directoryOffset += 4;
5760
5705
  arraySet(directoryArray, rawFilename, directoryOffset);
5761
5706
  directoryOffset += getLength(rawFilename);