@zip.js/zip.js 2.6.60 → 2.6.61

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-full.js CHANGED
@@ -7534,12 +7534,9 @@
7534
7534
  const commentOffset = endOfDirectoryInfo.offset;
7535
7535
  const commentLength = getUint16(endOfDirectoryView, 20);
7536
7536
  const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
7537
- const lastDiskNumber = getUint16(endOfDirectoryView, 4);
7537
+ let lastDiskNumber = getUint16(endOfDirectoryView, 4);
7538
7538
  const expectedLastDiskNumber = reader.lastDiskNumber || 0;
7539
7539
  let diskNumber = getUint16(endOfDirectoryView, 6);
7540
- if (expectedLastDiskNumber != lastDiskNumber) {
7541
- throw new Error(ERR_SPLIT_ZIP_FILE);
7542
- }
7543
7540
  let filesLength = getUint16(endOfDirectoryView, 8);
7544
7541
  let prependedDataLength = 0;
7545
7542
  let startOffset = 0;
@@ -7563,8 +7560,11 @@
7563
7560
  if (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
7564
7561
  throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
7565
7562
  }
7563
+ if (lastDiskNumber == MAX_16_BITS) {
7564
+ lastDiskNumber = getUint32(endOfDirectoryView, 16);
7565
+ }
7566
7566
  if (diskNumber == MAX_16_BITS) {
7567
- diskNumber = getUint32(endOfDirectoryView, 16);
7567
+ diskNumber = getUint32(endOfDirectoryView, 20);
7568
7568
  }
7569
7569
  if (filesLength == MAX_16_BITS) {
7570
7570
  filesLength = getBigUint64(endOfDirectoryView, 32);
@@ -7574,6 +7574,9 @@
7574
7574
  }
7575
7575
  directoryDataOffset -= directoryDataLength;
7576
7576
  }
7577
+ if (expectedLastDiskNumber != lastDiskNumber) {
7578
+ throw new Error(ERR_SPLIT_ZIP_FILE);
7579
+ }
7577
7580
  if (directoryDataOffset < 0 || directoryDataOffset >= reader.size) {
7578
7581
  throw new Error(ERR_BAD_FORMAT);
7579
7582
  }
@@ -8070,7 +8073,6 @@
8070
8073
  const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (make sure 'keepOrder' is set to 'true')";
8071
8074
 
8072
8075
  const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
8073
- const EXTRAFIELD_LENGTH_ZIP64 = 28;
8074
8076
 
8075
8077
  let workers = 0;
8076
8078
  const pendingEntries = [];
@@ -8213,6 +8215,7 @@
8213
8215
  let maximumCompressedSize = 0;
8214
8216
  let maximumEntrySize = 0;
8215
8217
  let uncompressedSize = 0;
8218
+ const zip64Enabled = zip64 === true;
8216
8219
  if (reader) {
8217
8220
  reader = initReader(reader);
8218
8221
  await initStream(reader);
@@ -8228,10 +8231,12 @@
8228
8231
  }
8229
8232
  }
8230
8233
  const { diskOffset, diskNumber, maxSize } = zipWriter.writer;
8231
- if (zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS ||
8232
- uncompressedSize >= MAX_32_BITS ||
8233
- maximumCompressedSize >= MAX_32_BITS ||
8234
- diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) >= MAX_16_BITS) {
8234
+ const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
8235
+ const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
8236
+ const zip64Offset = zip64Enabled || zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS;
8237
+ const supportZip64SplitFile = getOptionValue(zipWriter, options, "supportZip64SplitFile", true);
8238
+ const zip64DiskNumberStart = (supportZip64SplitFile && zip64Enabled) || diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) >= MAX_16_BITS;
8239
+ if (zip64Offset || zip64UncompressedSize || zip64CompressedSize || zip64DiskNumberStart) {
8235
8240
  if (zip64 === false || !keepOrder) {
8236
8241
  throw new Error(ERR_UNSUPPORTED_FORMAT);
8237
8242
  } else {
@@ -8249,6 +8254,10 @@
8249
8254
  creationDate,
8250
8255
  rawExtraField,
8251
8256
  zip64,
8257
+ zip64UncompressedSize,
8258
+ zip64CompressedSize,
8259
+ zip64Offset,
8260
+ zip64DiskNumberStart,
8252
8261
  password,
8253
8262
  level,
8254
8263
  useWebWorkers,
@@ -8346,7 +8355,7 @@
8346
8355
  await requestLockWriter();
8347
8356
  writingBufferedEntryData = true;
8348
8357
  if (!dataDescriptor) {
8349
- blob = await writeMissingHeaderInfo(fileEntry, blob, writable, options);
8358
+ blob = await writeExtraHeaderInfo(fileEntry, blob, writable, options);
8350
8359
  }
8351
8360
  await skipDiskIfNeeded(writable);
8352
8361
  fileEntry.diskNumberStart = writer.diskNumber;
@@ -8357,7 +8366,7 @@
8357
8366
  }
8358
8367
  fileEntry.offset = zipWriter.offset - diskOffset;
8359
8368
  if (fileEntry.zip64) {
8360
- setZip64OffsetInfo(fileEntry);
8369
+ setZip64ExtraInfo(fileEntry, options);
8361
8370
  } else if (fileEntry.offset >= MAX_32_BITS) {
8362
8371
  throw new Error(ERR_UNSUPPORTED_FORMAT);
8363
8372
  }
@@ -8395,7 +8404,7 @@
8395
8404
 
8396
8405
  async function requestLockWriter() {
8397
8406
  zipWriter.writerLocked = true;
8398
- const { lockWriter } = zipWriter;
8407
+ const { lockWriter } = zipWriter;
8399
8408
  zipWriter.lockWriter = new Promise(resolve => releaseLockWriter = () => {
8400
8409
  zipWriter.writerLocked = false;
8401
8410
  resolve();
@@ -8437,6 +8446,10 @@
8437
8446
  password,
8438
8447
  level,
8439
8448
  zip64,
8449
+ zip64UncompressedSize,
8450
+ zip64CompressedSize,
8451
+ zip64Offset,
8452
+ zip64DiskNumberStart,
8440
8453
  zipCrypto,
8441
8454
  dataDescriptor,
8442
8455
  directory,
@@ -8509,7 +8522,25 @@
8509
8522
  } else {
8510
8523
  await writeData(writable, localHeaderArray);
8511
8524
  }
8512
- const rawExtraFieldZip64 = zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array();
8525
+ let rawExtraFieldZip64;
8526
+ if (zip64) {
8527
+ let rawExtraFieldZip64Length = 4;
8528
+ if (zip64UncompressedSize) {
8529
+ rawExtraFieldZip64Length += 8;
8530
+ }
8531
+ if (zip64CompressedSize) {
8532
+ rawExtraFieldZip64Length += 8;
8533
+ }
8534
+ if (zip64Offset) {
8535
+ rawExtraFieldZip64Length += 8;
8536
+ }
8537
+ if (zip64DiskNumberStart) {
8538
+ rawExtraFieldZip64Length += 4;
8539
+ }
8540
+ rawExtraFieldZip64 = new Uint8Array(rawExtraFieldZip64Length);
8541
+ } else {
8542
+ rawExtraFieldZip64 = new Uint8Array();
8543
+ }
8513
8544
  if (reader) {
8514
8545
  setEntryInfo({
8515
8546
  signature,
@@ -8524,6 +8555,7 @@
8524
8555
  await writeData(writable, dataDescriptorArray);
8525
8556
  }
8526
8557
  Object.assign(fileEntry, {
8558
+ uncompressedSize,
8527
8559
  compressedSize,
8528
8560
  lastModDate,
8529
8561
  rawLastModDate,
@@ -8535,7 +8567,11 @@
8535
8567
  version,
8536
8568
  headerArray,
8537
8569
  signature,
8538
- rawExtraFieldZip64
8570
+ rawExtraFieldZip64,
8571
+ zip64UncompressedSize,
8572
+ zip64CompressedSize,
8573
+ zip64Offset,
8574
+ zip64DiskNumberStart
8539
8575
  });
8540
8576
  return fileEntry;
8541
8577
  }
@@ -8712,6 +8748,8 @@
8712
8748
  } = dataDescriptorInfo;
8713
8749
  const {
8714
8750
  zip64,
8751
+ zip64UncompressedSize,
8752
+ zip64CompressedSize,
8715
8753
  zipCrypto,
8716
8754
  dataDescriptor
8717
8755
  } = options;
@@ -8724,11 +8762,17 @@
8724
8762
  if (zip64) {
8725
8763
  const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
8726
8764
  setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
8727
- setUint16(rawExtraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64);
8728
- setUint32(headerView, 14, MAX_32_BITS);
8729
- setBigUint64(rawExtraFieldZip64View, 12, BigInt(compressedSize));
8730
- setUint32(headerView, 18, MAX_32_BITS);
8731
- setBigUint64(rawExtraFieldZip64View, 4, BigInt(uncompressedSize));
8765
+ setUint16(rawExtraFieldZip64View, 2, rawExtraFieldZip64.length - 4);
8766
+ let rawExtraFieldZip64Offset = 4;
8767
+ if (zip64UncompressedSize) {
8768
+ setUint32(headerView, 18, MAX_32_BITS);
8769
+ setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(uncompressedSize));
8770
+ rawExtraFieldZip64Offset += 8;
8771
+ }
8772
+ if (zip64CompressedSize) {
8773
+ setUint32(headerView, 14, MAX_32_BITS);
8774
+ setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(compressedSize));
8775
+ }
8732
8776
  if (dataDescriptor) {
8733
8777
  setBigUint64(dataDescriptorView, dataDescriptorOffset + 4, BigInt(compressedSize));
8734
8778
  setBigUint64(dataDescriptorView, dataDescriptorOffset + 12, BigInt(uncompressedSize));
@@ -8743,7 +8787,7 @@
8743
8787
  }
8744
8788
  }
8745
8789
 
8746
- async function writeMissingHeaderInfo(fileEntry, entryData, writable, { zipCrypto }) {
8790
+ async function writeExtraHeaderInfo(fileEntry, entryData, writable, { zipCrypto }) {
8747
8791
  const arrayBuffer = await sliceAsArrayBuffer(entryData, 0, 26);
8748
8792
  const arrayBufferView = new DataView(arrayBuffer);
8749
8793
  if (!fileEntry.encrypted || zipCrypto) {
@@ -8760,11 +8804,24 @@
8760
8804
  return entryData.slice(arrayBuffer.byteLength);
8761
8805
  }
8762
8806
 
8763
- function setZip64OffsetInfo(fileEntry) {
8807
+ function setZip64ExtraInfo(fileEntry, options) {
8764
8808
  const { rawExtraFieldZip64, offset, diskNumberStart } = fileEntry;
8809
+ const { zip64UncompressedSize, zip64CompressedSize, zip64Offset, zip64DiskNumberStart } = options;
8765
8810
  const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
8766
- setBigUint64(rawExtraFieldZip64View, 20, BigInt(offset));
8767
- setUint32(rawExtraFieldZip64View, 28, diskNumberStart);
8811
+ let rawExtraFieldZip64Offset = 4;
8812
+ if (zip64UncompressedSize) {
8813
+ rawExtraFieldZip64Offset += 8;
8814
+ }
8815
+ if (zip64CompressedSize) {
8816
+ rawExtraFieldZip64Offset += 8;
8817
+ }
8818
+ if (zip64Offset) {
8819
+ setBigUint64(rawExtraFieldZip64View, rawExtraFieldZip64Offset, BigInt(offset));
8820
+ rawExtraFieldZip64Offset += 8;
8821
+ }
8822
+ if (zip64DiskNumberStart) {
8823
+ setUint32(rawExtraFieldZip64View, rawExtraFieldZip64Offset, diskNumberStart);
8824
+ }
8768
8825
  }
8769
8826
 
8770
8827
  async function closeFile(zipWriter, comment, options) {
@@ -8811,12 +8868,18 @@
8811
8868
  headerArray,
8812
8869
  directory,
8813
8870
  zip64,
8871
+ zip64UncompressedSize,
8872
+ zip64CompressedSize,
8873
+ zip64DiskNumberStart,
8874
+ zip64Offset,
8814
8875
  msDosCompatible,
8815
8876
  internalFileAttribute,
8816
8877
  externalFileAttribute,
8817
8878
  extendedTimestamp,
8818
8879
  lastModDate,
8819
- diskNumberStart
8880
+ diskNumberStart,
8881
+ uncompressedSize,
8882
+ compressedSize
8820
8883
  } = fileEntry;
8821
8884
  let rawExtraFieldExtendedTimestamp;
8822
8885
  if (extendedTimestamp) {
@@ -8832,17 +8895,24 @@
8832
8895
  const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraField);
8833
8896
  setUint32(directoryView, offset, CENTRAL_FILE_HEADER_SIGNATURE);
8834
8897
  setUint16(directoryView, offset + 4, versionMadeBy);
8898
+ const headerView = getDataView(headerArray);
8899
+ if (!zip64UncompressedSize) {
8900
+ setUint32(headerView, 18, uncompressedSize);
8901
+ }
8902
+ if (!zip64CompressedSize) {
8903
+ setUint32(headerView, 14, compressedSize);
8904
+ }
8835
8905
  arraySet(directoryArray, headerArray, offset + 6);
8836
8906
  setUint16(directoryView, offset + 30, extraFieldLength);
8837
8907
  setUint16(directoryView, offset + 32, getLength(rawComment));
8838
- setUint16(directoryView, offset + 34, zip64 ? MAX_16_BITS : diskNumberStart);
8908
+ setUint16(directoryView, offset + 34, zip64 && zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
8839
8909
  setUint16(directoryView, offset + 36, internalFileAttribute);
8840
8910
  if (externalFileAttribute) {
8841
8911
  setUint32(directoryView, offset + 38, externalFileAttribute);
8842
8912
  } else if (directory && msDosCompatible) {
8843
8913
  setUint8(directoryView, offset + 38, FILE_ATTR_MSDOS_DIR_MASK);
8844
8914
  }
8845
- setUint32(directoryView, offset + 42, zip64 ? MAX_32_BITS : fileEntryOffset);
8915
+ setUint32(directoryView, offset + 42, zip64 && zip64Offset ? MAX_32_BITS : fileEntryOffset);
8846
8916
  arraySet(directoryArray, rawFilename, offset + 46);
8847
8917
  arraySet(directoryArray, rawExtraFieldZip64, offset + 46 + getLength(rawFilename));
8848
8918
  arraySet(directoryArray, rawExtraFieldAES, offset + 46 + getLength(rawFilename, rawExtraFieldZip64));
@@ -8896,7 +8966,11 @@
8896
8966
  setUint32(endOfdirectoryView, 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
8897
8967
  setBigUint64(endOfdirectoryView, 64, BigInt(directoryOffset) + BigInt(directoryDataLength));
8898
8968
  setUint32(endOfdirectoryView, 72, lastDiskNumber + 1);
8899
- diskNumber = MAX_16_BITS;
8969
+ const supportZip64SplitFile = getOptionValue(zipWriter, options, "supportZip64SplitFile", true);
8970
+ if (supportZip64SplitFile) {
8971
+ lastDiskNumber = MAX_16_BITS;
8972
+ diskNumber = MAX_16_BITS;
8973
+ }
8900
8974
  filesLength = MAX_16_BITS;
8901
8975
  directoryOffset = MAX_32_BITS;
8902
8976
  directoryDataLength = MAX_32_BITS;