@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.
@@ -4374,7 +4374,7 @@
4374
4374
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
4375
4375
  const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
4376
4376
  const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
4377
- const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (make sure 'keepOrder' is set to 'true')";
4377
+ const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (set the 'zip64' option to 'true')";
4378
4378
  const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
4379
4379
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
4380
4380
  const ERR_INVALID_UID = "Invalid uid (must be integer 0..2^32-1)";
@@ -4790,14 +4790,11 @@
4790
4790
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
4791
4791
  }
4792
4792
  }
4793
- const { diskOffset, diskNumber, maxSize } = zipWriter.writer;
4793
+ const { diskOffset, diskNumber } = zipWriter.writer;
4794
4794
  const zip64UncompressedSize = zip64Enabled || uncompressedSize > MAX_32_BITS;
4795
4795
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize > MAX_32_BITS;
4796
- const zip64Offset = zip64Enabled || zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset > MAX_32_BITS;
4797
- const supportZip64SplitFile = getOptionValue(zipWriter, options, OPTION_SUPPORT_ZIP64_SPLIT_FILE, true);
4798
- const zip64DiskNumberStart = (supportZip64SplitFile && zip64Enabled) || diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) > MAX_16_BITS;
4799
- if (zip64Offset || zip64UncompressedSize || zip64CompressedSize || zip64DiskNumberStart) {
4800
- if (zip64 === false || !keepOrder) {
4796
+ if (zip64UncompressedSize || zip64CompressedSize) {
4797
+ if (zip64 === false) {
4801
4798
  throw new Error(ERR_UNSUPPORTED_FORMAT);
4802
4799
  } else {
4803
4800
  zip64 = true;
@@ -4817,8 +4814,6 @@
4817
4814
  zip64,
4818
4815
  zip64UncompressedSize,
4819
4816
  zip64CompressedSize,
4820
- zip64Offset,
4821
- zip64DiskNumberStart,
4822
4817
  password,
4823
4818
  rawPassword,
4824
4819
  level,
@@ -4946,7 +4941,6 @@
4946
4941
  await writeData(fileWriter, localHeaderArray);
4947
4942
  }
4948
4943
  fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
4949
- const { zip64 } = fileEntry;
4950
4944
  if (!bufferedWrite) {
4951
4945
  writingEntryData = false;
4952
4946
  }
@@ -4958,9 +4952,6 @@
4958
4952
  writingBufferedEntryData = true;
4959
4953
  fileEntry.diskNumberStart = writer.diskNumber;
4960
4954
  fileEntry.offset = zipWriter.offset - writer.diskOffset;
4961
- if (zip64) {
4962
- updateZip64ExtraField(fileEntry);
4963
- }
4964
4955
  updateLocalHeader(fileEntry, localHeaderView, options);
4965
4956
  await skipDiskIfNeeded(writable);
4966
4957
  await writeData(writer, localHeaderArray);
@@ -4969,12 +4960,6 @@
4969
4960
  writingBufferedEntryData = false;
4970
4961
  } else {
4971
4962
  fileEntry.offset = zipWriter.offset - diskOffset;
4972
- if (zip64) {
4973
- updateZip64ExtraField(fileEntry);
4974
- }
4975
- }
4976
- if (fileEntry.offset > MAX_32_BITS && !zip64) {
4977
- throw new Error(ERR_UNSUPPORTED_FORMAT);
4978
4963
  }
4979
4964
  zipWriter.offset += fileEntry.size;
4980
4965
  return fileEntry;
@@ -5064,8 +5049,6 @@
5064
5049
  zip64,
5065
5050
  zip64UncompressedSize,
5066
5051
  zip64CompressedSize,
5067
- zip64Offset,
5068
- zip64DiskNumberStart,
5069
5052
  zipCrypto,
5070
5053
  dataDescriptor,
5071
5054
  directory,
@@ -5203,9 +5186,7 @@
5203
5186
  signature,
5204
5187
  extraFieldExtendedTimestampFlag,
5205
5188
  zip64UncompressedSize,
5206
- zip64CompressedSize,
5207
- zip64Offset,
5208
- zip64DiskNumberStart
5189
+ zip64CompressedSize
5209
5190
  });
5210
5191
  return fileEntry;
5211
5192
  }
@@ -5229,74 +5210,41 @@
5229
5210
  encrypted,
5230
5211
  zip64UncompressedSize,
5231
5212
  zip64CompressedSize,
5232
- zip64Offset,
5233
- zip64DiskNumberStart,
5234
- uncompressedSize,
5235
- offset,
5236
- diskNumberStart
5213
+ uncompressedSize
5237
5214
  } = options;
5238
5215
  let { version, compressionMethod } = options;
5239
5216
  const compressed = !directory && (level > 0 || (level === UNDEFINED_VALUE && compressionMethod !== 0));
5240
- let rawExtraFieldZip64;
5241
5217
  let rawLocalExtraFieldZip64;
5242
5218
  const uncompressedFile = passThrough || !compressed;
5243
5219
  const zip64ExtraFieldComplete = zip64 && (options.bufferedWrite || ((!zip64UncompressedSize && !zip64CompressedSize) || uncompressedFile));
5244
5220
  if (zip64) {
5245
- let rawExtraFieldZip64Length = 4;
5246
5221
  let rawLocalExtraFieldZip64Length = 4;
5247
5222
  if (zip64UncompressedSize) {
5248
- rawExtraFieldZip64Length += 8;
5249
5223
  rawLocalExtraFieldZip64Length += 8;
5250
5224
  }
5251
5225
  if (zip64CompressedSize) {
5252
- rawExtraFieldZip64Length += 8;
5253
5226
  rawLocalExtraFieldZip64Length += 8;
5254
5227
  }
5255
- if (zip64Offset) {
5256
- rawExtraFieldZip64Length += 8;
5257
- }
5258
- if (zip64DiskNumberStart) {
5259
- rawExtraFieldZip64Length += 4;
5260
- }
5261
- rawExtraFieldZip64 = new Uint8Array(rawExtraFieldZip64Length);
5262
- const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
5263
5228
  rawLocalExtraFieldZip64 = new Uint8Array(rawLocalExtraFieldZip64Length);
5264
5229
  const rawLocalExtraFieldZip64View = getDataView(rawLocalExtraFieldZip64);
5265
- setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
5266
- setUint16(rawExtraFieldZip64View, 2, getLength(rawExtraFieldZip64) - 4);
5267
5230
  setUint16(rawLocalExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
5268
5231
  setUint16(rawLocalExtraFieldZip64View, 2, getLength(rawLocalExtraFieldZip64) - 4);
5269
5232
  if (zip64ExtraFieldComplete) {
5270
- const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
5271
5233
  const rawLocalExtraFieldZip64View = getDataView(rawLocalExtraFieldZip64);
5272
- let rawExtraFieldZip64Offset = 4;
5273
5234
  let rawLocalExtraFieldZip64Offset = 4;
5274
5235
  if (zip64UncompressedSize) {
5275
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(uncompressedSize));
5276
- rawExtraFieldZip64Offset += 8;
5277
5236
  setBigUint64(rawLocalExtraFieldZip64View, rawLocalExtraFieldZip64Offset, BigInt(uncompressedSize));
5278
5237
  rawLocalExtraFieldZip64Offset += 8;
5279
5238
  }
5280
5239
  if (zip64CompressedSize && uncompressedFile) {
5281
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(uncompressedSize));
5282
- rawExtraFieldZip64Offset += 8;
5283
5240
  setBigUint64(rawLocalExtraFieldZip64View, rawLocalExtraFieldZip64Offset, BigInt(uncompressedSize));
5284
5241
  rawLocalExtraFieldZip64Offset += 8;
5285
5242
  }
5286
- if (zip64Offset) {
5287
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(offset));
5288
- rawExtraFieldZip64Offset += 8;
5289
- }
5290
- if (zip64DiskNumberStart) {
5291
- setUint32(rawExtraFieldZip64View, rawExtraFieldZip64Offset, diskNumberStart);
5292
- rawExtraFieldZip64Offset += 4;
5293
- }
5294
5243
  if (rawLocalExtraFieldZip64Offset == 4) {
5295
5244
  rawLocalExtraFieldZip64 = new Uint8Array();
5296
5245
  }
5297
5246
  }
5298
5247
  } else {
5299
- rawExtraFieldZip64 = new Uint8Array();
5300
5248
  rawLocalExtraFieldZip64 = new Uint8Array();
5301
5249
  }
5302
5250
  let rawExtraFieldAES;
@@ -5453,7 +5401,7 @@
5453
5401
  version,
5454
5402
  compressionMethod,
5455
5403
  extraFieldExtendedTimestampFlag,
5456
- rawExtraFieldZip64,
5404
+ rawExtraFieldZip64: new Uint8Array(),
5457
5405
  localExtraFieldZip64Length,
5458
5406
  rawExtraFieldExtendedTimestamp,
5459
5407
  rawExtraFieldNTFS,
@@ -5625,35 +5573,6 @@
5625
5573
  }
5626
5574
  }
5627
5575
 
5628
- function updateZip64ExtraField({
5629
- compressedSize,
5630
- uncompressedSize,
5631
- offset,
5632
- diskNumberStart,
5633
- zip64UncompressedSize,
5634
- zip64CompressedSize,
5635
- zip64Offset,
5636
- zip64DiskNumberStart,
5637
- rawExtraFieldZip64
5638
- }) {
5639
- const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
5640
- let rawExtraFieldZip64Offset = 4;
5641
- if (zip64UncompressedSize) {
5642
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(uncompressedSize));
5643
- rawExtraFieldZip64Offset += 8;
5644
- }
5645
- if (zip64CompressedSize) {
5646
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(compressedSize));
5647
- rawExtraFieldZip64Offset += 8;
5648
- }
5649
- if (zip64Offset) {
5650
- setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(offset));
5651
- rawExtraFieldZip64Offset += 8;
5652
- }
5653
- if (zip64DiskNumberStart) {
5654
- setUint32(rawExtraFieldZip64View, rawExtraFieldZip64Offset, diskNumberStart);
5655
- }
5656
- }
5657
5576
 
5658
5577
  async function closeFile(zipWriter, comment, options) {
5659
5578
  const { files, writer } = zipWriter;
@@ -5666,7 +5585,6 @@
5666
5585
  for (const [, fileEntry] of files) {
5667
5586
  const {
5668
5587
  rawFilename,
5669
- rawExtraFieldZip64,
5670
5588
  rawExtraFieldAES,
5671
5589
  rawComment,
5672
5590
  rawExtraFieldNTFS,
@@ -5674,8 +5592,36 @@
5674
5592
  rawExtraField,
5675
5593
  extendedTimestamp,
5676
5594
  extraFieldExtendedTimestampFlag,
5677
- lastModDate
5595
+ lastModDate,
5596
+ zip64UncompressedSize,
5597
+ zip64CompressedSize,
5598
+ uncompressedSize,
5599
+ compressedSize
5678
5600
  } = fileEntry;
5601
+ const zip64Offset = fileEntry.offset > MAX_32_BITS;
5602
+ const zip64DiskNumberStart = fileEntry.diskNumberStart > MAX_16_BITS;
5603
+ let rawExtraFieldZip64;
5604
+ if (zip64Offset || zip64DiskNumberStart || zip64UncompressedSize || zip64CompressedSize) {
5605
+ let length = 4;
5606
+ if (zip64UncompressedSize) length += 8;
5607
+ if (zip64CompressedSize) length += 8;
5608
+ if (zip64Offset) length += 8;
5609
+ if (zip64DiskNumberStart) length += 4;
5610
+ rawExtraFieldZip64 = new Uint8Array(length);
5611
+ const zip64View = getDataView(rawExtraFieldZip64);
5612
+ setUint16(zip64View, 0, EXTRAFIELD_TYPE_ZIP64);
5613
+ setUint16(zip64View, 2, length - 4);
5614
+ let zip64FieldOffset = 4;
5615
+ if (zip64UncompressedSize) { setBigUint64(zip64View, zip64FieldOffset, BigInt(uncompressedSize)); zip64FieldOffset += 8; }
5616
+ if (zip64CompressedSize) { setBigUint64(zip64View, zip64FieldOffset, BigInt(compressedSize)); zip64FieldOffset += 8; }
5617
+ if (zip64Offset) { setBigUint64(zip64View, zip64FieldOffset, BigInt(fileEntry.offset)); zip64FieldOffset += 8; }
5618
+ if (zip64DiskNumberStart) { setUint32(zip64View, zip64FieldOffset, fileEntry.diskNumberStart); }
5619
+ } else {
5620
+ rawExtraFieldZip64 = new Uint8Array();
5621
+ }
5622
+ fileEntry.rawExtraFieldZip64 = rawExtraFieldZip64;
5623
+ fileEntry.zip64Offset = zip64Offset;
5624
+ fileEntry.zip64DiskNumberStart = zip64DiskNumberStart;
5679
5625
  let rawExtraFieldTimestamp;
5680
5626
  if (extendedTimestamp) {
5681
5627
  rawExtraFieldTimestamp = new Uint8Array(9);
@@ -5717,7 +5663,6 @@
5717
5663
  versionMadeBy,
5718
5664
  headerArray,
5719
5665
  headerView,
5720
- zip64,
5721
5666
  zip64UncompressedSize,
5722
5667
  zip64CompressedSize,
5723
5668
  zip64DiskNumberStart,
@@ -5743,7 +5688,7 @@
5743
5688
  directoryOffset += 2;
5744
5689
  setUint16(directoryView, directoryOffset, getLength(rawComment));
5745
5690
  directoryOffset += 2;
5746
- setUint16(directoryView, directoryOffset, zip64 && zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
5691
+ setUint16(directoryView, directoryOffset, zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
5747
5692
  directoryOffset += 2;
5748
5693
  setUint16(directoryView, directoryOffset, internalFileAttributes);
5749
5694
  directoryOffset += 2;
@@ -5751,7 +5696,7 @@
5751
5696
  setUint32(directoryView, directoryOffset, externalFileAttributes);
5752
5697
  }
5753
5698
  directoryOffset += 4;
5754
- setUint32(directoryView, directoryOffset, zip64 && zip64Offset ? MAX_32_BITS : fileEntryOffset);
5699
+ setUint32(directoryView, directoryOffset, zip64Offset ? MAX_32_BITS : fileEntryOffset);
5755
5700
  directoryOffset += 4;
5756
5701
  arraySet(directoryArray, rawFilename, directoryOffset);
5757
5702
  directoryOffset += getLength(rawFilename);