@zip.js/zip.js 2.8.54 → 2.8.56

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.
@@ -84,6 +84,7 @@
84
84
  const BITFLAG_DATA_DESCRIPTOR = 0b1000;
85
85
  const BITFLAG_STRONG_ENCRYPTION = 0b1000000;
86
86
  const BITFLAG_LANG_ENCODING_FLAG = 0b100000000000;
87
+ const BITFLAG_MASKED_LOCAL_HEADERS = 0b10000000000000;
87
88
  const FILE_ATTR_MSDOS_DIR_MASK = 0b10000;
88
89
  const FILE_ATTR_MSDOS_READONLY_MASK = 0x01;
89
90
  const FILE_ATTR_MSDOS_HIDDEN_MASK = 0x02;
@@ -233,6 +234,18 @@
233
234
  }
234
235
  }
235
236
 
237
+ function checkInteger(value, maxValue, errorMessage) {
238
+ if (!Number.isInteger(value) || value < 0 || value > maxValue) {
239
+ throw new Error(errorMessage);
240
+ }
241
+ }
242
+
243
+ function checkIntegerOption(value, maxValue, errorMessage) {
244
+ if (value !== UNDEFINED_VALUE) {
245
+ checkInteger(value, maxValue, errorMessage);
246
+ }
247
+ }
248
+
236
249
  function toNumber(value) {
237
250
  return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
238
251
  }
@@ -4192,6 +4205,7 @@
4192
4205
  let startOffset;
4193
4206
  let zip64EndOfDirectory;
4194
4207
  let zip64EndOfDirectoryVersion2;
4208
+ let zip64EndOfDirectoryLength = ZIP64_END_OF_CENTRAL_DIR_LENGTH;
4195
4209
  let directoryEncryptionInfo;
4196
4210
  const requiresZip64 = directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS || diskNumber == MAX_16_BITS;
4197
4211
  if (directoryDataOffset != MAX_32_BITS && diskNumber != MAX_16_BITS) {
@@ -4228,6 +4242,7 @@
4228
4242
  Number(getBigUint64(endOfDirectoryView, 4)) - (ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12),
4229
4243
  reader.size - directoryDataOffset - ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4230
4244
  if (extensibleDataLength > 0) {
4245
+ zip64EndOfDirectoryLength += extensibleDataLength;
4231
4246
  const rawExtensibleData = await readUint8Array(reader, directoryDataOffset + ZIP64_END_OF_CENTRAL_DIR_LENGTH, extensibleDataLength);
4232
4247
  directoryEncryptionInfo = getDirectoryEncryptionInfo(rawExtensibleData);
4233
4248
  }
@@ -4257,7 +4272,7 @@
4257
4272
  }
4258
4273
  let declaredDirectoryDataLength = directoryDataLength;
4259
4274
  const centralDirectoryEndOffset = endOfDirectoryInfo.offset -
4260
- (zip64EndOfDirectory ? ZIP64_END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH : 0);
4275
+ (zip64EndOfDirectory ? zip64EndOfDirectoryLength + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH : 0);
4261
4276
  if (directoryDataOffset >= reader.size) {
4262
4277
  prependedDataLength = reader.size - directoryDataOffset - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
4263
4278
  directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
@@ -4277,7 +4292,9 @@
4277
4292
  }
4278
4293
  const expectedDirectoryDataOffset = centralDirectoryEndOffset - directoryDataLength;
4279
4294
  if (directoryDataOffset != expectedDirectoryDataOffset && diskNumber == lastDiskNumber) {
4280
- const storedPointsAtDirectory = getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE;
4295
+ const storedPointsAtDirectory = getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE ||
4296
+ Boolean(directoryEncryptionInfo && directoryEncryptionInfo.compressedSize) ||
4297
+ detectEncryptedCentralDirectory(directoryView);
4281
4298
  let reconcile = !storedPointsAtDirectory;
4282
4299
  if (!reconcile && expectedDirectoryDataOffset >= 0 && expectedDirectoryDataOffset + 4 <= reader.size) {
4283
4300
  const expectedSignatureArray = await readUint8Array(reader, expectedDirectoryDataOffset, 4);
@@ -4306,11 +4323,13 @@
4306
4323
  zipReader.directoryOffset = directoryDataOffset;
4307
4324
  zipReader.directoryLength = declaredDirectoryDataLength;
4308
4325
  const decryptCentralDirectory = getFunctionOptionValue$1(zipReader, options, OPTION_DECRYPT_CENTRAL_DIRECTORY);
4309
- let decryptedDirectory;
4326
+ let decryptedDirectory, dataAfterEncryptedDirectory;
4310
4327
  if (decryptCentralDirectory && filesLength && directoryArray.length >= 4 &&
4311
4328
  getUint32$1(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
4312
4329
  (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4313
- directoryArray = await decryptCentralDirectory(directoryArray, directoryEncryptionInfo);
4330
+ const encryptedDirectoryDataLength = getEncryptedDirectoryDataLength(directoryEncryptionInfo, declaredDirectoryDataLength, directoryArray.length);
4331
+ dataAfterEncryptedDirectory = directoryArray.subarray(encryptedDirectoryDataLength);
4332
+ directoryArray = await decryptCentralDirectory(directoryArray.subarray(0, encryptedDirectoryDataLength), directoryEncryptionInfo);
4314
4333
  directoryView = getDataView(directoryArray);
4315
4334
  declaredDirectoryDataLength = directoryArray.length;
4316
4335
  decryptedDirectory = true;
@@ -4376,6 +4395,7 @@
4376
4395
  }
4377
4396
  Object.assign(fileEntry, {
4378
4397
  index: indexFile,
4398
+ decryptedDirectory,
4379
4399
  versionMadeBy,
4380
4400
  msDosCompatible,
4381
4401
  zip64: false,
@@ -4452,13 +4472,19 @@
4452
4472
  yield entry;
4453
4473
  }
4454
4474
  let offsetAfterSignature = offset;
4455
- if (offset + 6 <= directoryArray.length && getUint32$1(directoryView, offset) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
4456
- const signatureDataLength = getUint16$1(directoryView, offset + 4);
4457
- if (offset + 6 + signatureDataLength <= directoryArray.length) {
4458
- zipReader.digitalSignature = directoryArray.subarray(offset + 6, offset + 6 + signatureDataLength);
4459
- offsetAfterSignature = offset + 6 + signatureDataLength;
4475
+ let digitalSignature = readDigitalSignature(directoryArray.subarray(offset)) ||
4476
+ (decryptedDirectory ? readDigitalSignature(dataAfterEncryptedDirectory) : UNDEFINED_VALUE);
4477
+ if (!digitalSignature && !decryptedDirectory) {
4478
+ const signatureRecordOffset = directoryDataOffset + offset;
4479
+ const signatureRecordLength = Math.min(centralDirectoryEndOffset - signatureRecordOffset, 6 + MAX_16_BITS);
4480
+ if (signatureRecordLength >= 6) {
4481
+ digitalSignature = readDigitalSignature(await readUint8Array(reader, signatureRecordOffset, signatureRecordLength));
4460
4482
  }
4461
4483
  }
4484
+ if (digitalSignature) {
4485
+ zipReader.digitalSignature = digitalSignature;
4486
+ offsetAfterSignature = offset + 6 + digitalSignature.length;
4487
+ }
4462
4488
  if (checkAmbiguity && offset != declaredDirectoryDataLength && offsetAfterSignature != declaredDirectoryDataLength) {
4463
4489
  throwAmbiguousArchive("trailing central directory data");
4464
4490
  }
@@ -4726,6 +4752,27 @@
4726
4752
  return false;
4727
4753
  }
4728
4754
 
4755
+ function readDigitalSignature(signatureRecordArray) {
4756
+ if (signatureRecordArray.length >= 6) {
4757
+ const signatureRecordView = getDataView(signatureRecordArray);
4758
+ if (getUint32$1(signatureRecordView, 0) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
4759
+ const signatureDataLength = getUint16$1(signatureRecordView, 4);
4760
+ if (6 + signatureDataLength <= signatureRecordArray.length) {
4761
+ return signatureRecordArray.subarray(6, 6 + signatureDataLength);
4762
+ }
4763
+ }
4764
+ }
4765
+ }
4766
+
4767
+ function getEncryptedDirectoryDataLength(directoryEncryptionInfo, declaredDirectoryDataLength, directoryDataLength) {
4768
+ const encryptedDirectoryDataLength = directoryEncryptionInfo && directoryEncryptionInfo.compressedSize ?
4769
+ directoryEncryptionInfo.compressedSize :
4770
+ declaredDirectoryDataLength;
4771
+ return encryptedDirectoryDataLength > 0 && encryptedDirectoryDataLength <= directoryDataLength ?
4772
+ encryptedDirectoryDataLength :
4773
+ directoryDataLength;
4774
+ }
4775
+
4729
4776
  function getDirectoryEncryptionInfo(rawExtensibleData) {
4730
4777
  const directoryEncryptionInfo = { rawExtensibleData };
4731
4778
  if (rawExtensibleData.length >= 28) {
@@ -5310,7 +5357,9 @@
5310
5357
 
5311
5358
  function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename) {
5312
5359
  const { rawFilename } = zipEntry;
5313
- if (checkLocalFilename &&
5360
+ const maskedLocalDirectory = zipEntry.decryptedDirectory &&
5361
+ (localDirectory.rawBitFlag & BITFLAG_MASKED_LOCAL_HEADERS) == BITFLAG_MASKED_LOCAL_HEADERS;
5362
+ if (checkLocalFilename && !maskedLocalDirectory &&
5314
5363
  (rawLocalFilename.length != rawFilename.length ||
5315
5364
  rawLocalFilename.some((byteValue, indexByte) => byteValue != rawFilename[indexByte]))) {
5316
5365
  throwAmbiguousArchive("mismatched local file header (filename)");
@@ -5321,7 +5370,7 @@
5321
5370
  if (localDirectory.compressionMethod != zipEntry.compressionMethod) {
5322
5371
  throwAmbiguousArchive("mismatched local file header (compression method)");
5323
5372
  }
5324
- if (!localDirectory.bitFlag.dataDescriptor &&
5373
+ if (!localDirectory.bitFlag.dataDescriptor && !maskedLocalDirectory &&
5325
5374
  (localDirectory.crc32 || localDirectory.compressedSize || localDirectory.uncompressedSize) &&
5326
5375
  (localDirectory.crc32 != zipEntry.crc32 ||
5327
5376
  localDirectory.compressedSize != zipEntry.compressedSize ||
@@ -5450,6 +5499,7 @@
5450
5499
  const MAX_NTFS_TIME = BigInt("0x7fffffffffffffff");
5451
5500
  const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (set the 'zip64' option to 'true')";
5452
5501
  const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
5502
+ const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
5453
5503
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
5454
5504
  const ERR_UNDEFINED_READER = "Undefined reader";
5455
5505
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
@@ -5465,6 +5515,8 @@
5465
5515
 
5466
5516
  const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
5467
5517
  const EXTRAFIELD_OFFSET_AES_VENDOR_VERSION = 4;
5518
+ const EXTRAFIELD_OFFSET_AES_COMPRESSION_METHOD = 9;
5519
+ const EXTRAFIELD_USDZ_MAX_LENGTH = 67;
5468
5520
  const VENDOR_VERSION_AE_1 = 1;
5469
5521
  const INFOZIP_EXTRA_FIELD_TYPE$1 = "infozip";
5470
5522
  const UNIX_EXTRA_FIELD_TYPE = "unix";
@@ -5511,16 +5563,14 @@
5511
5563
  await zipReader$1.close();
5512
5564
  await initStream(this.writer);
5513
5565
  const { directoryOffset } = zipReader$1;
5514
- let splitZipSignatureLength = 0;
5515
5566
  if (this.addSplitZipSignature) {
5516
5567
  delete this.addSplitZipSignature;
5517
5568
  if (!await startsWithSplitZipSignature(reader)) {
5518
5569
  await writeData(this.writer, getSplitZipSignatureArray());
5519
- splitZipSignatureLength = SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
5520
- this.offset += splitZipSignatureLength;
5570
+ this.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
5521
5571
  }
5522
5572
  }
5523
- const entryPositions = await copyZipData(this, reader, entries, directoryOffset, splitZipSignatureLength);
5573
+ const entryPositions = await copyZipData(this, reader, entries, directoryOffset);
5524
5574
  this.filenames = new Set(entries.map(entry => entry.filename));
5525
5575
  this.fileEntries = new Map(entries.map(entry => {
5526
5576
  const {
@@ -5700,7 +5750,8 @@
5700
5750
  signature: options[PROPERTY_NAME_SIGNATURE],
5701
5751
  crc32: options.crc32 === UNDEFINED_VALUE ? options[PROPERTY_NAME_SIGNATURE] : options.crc32,
5702
5752
  offset: zipWriter.offset - diskOffset,
5703
- diskNumberStart: diskNumber
5753
+ diskNumberStart: diskNumber,
5754
+ [OPTION_USDZ]: zipWriter.options[OPTION_USDZ]
5704
5755
  });
5705
5756
  const headerInfo = getHeaderInfo(options);
5706
5757
  const dataDescriptorInfo = getDataDescriptorInfo(options);
@@ -5732,15 +5783,9 @@
5732
5783
  let setuid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETUID);
5733
5784
  let setgid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETGID);
5734
5785
  let sticky = getOptionValue(zipWriter, options, PROPERTY_NAME_STICKY);
5735
- if (uid !== UNDEFINED_VALUE && (!Number.isInteger(uid) || uid < 0 || uid > MAX_32_BITS)) {
5736
- throw new Error(ERR_INVALID_UID);
5737
- }
5738
- if (gid !== UNDEFINED_VALUE && (!Number.isInteger(gid) || gid < 0 || gid > MAX_32_BITS)) {
5739
- throw new Error(ERR_INVALID_GID);
5740
- }
5741
- if (unixMode !== UNDEFINED_VALUE && (!Number.isInteger(unixMode) || unixMode < 0 || unixMode > MAX_16_BITS)) {
5742
- throw new Error(ERR_INVALID_UNIX_MODE);
5743
- }
5786
+ checkIntegerOption(uid, MAX_32_BITS, ERR_INVALID_UID);
5787
+ checkIntegerOption(gid, MAX_32_BITS, ERR_INVALID_GID);
5788
+ checkIntegerOption(unixMode, MAX_16_BITS, ERR_INVALID_UNIX_MODE);
5744
5789
  if (unixExtraFieldType !== UNDEFINED_VALUE && unixExtraFieldType !== INFOZIP_EXTRA_FIELD_TYPE$1 && unixExtraFieldType !== UNIX_EXTRA_FIELD_TYPE) {
5745
5790
  throw new Error(ERR_INVALID_UNIX_EXTRA_FIELD_TYPE);
5746
5791
  }
@@ -5762,9 +5807,7 @@
5762
5807
  msDosCompatible = true;
5763
5808
  versionMadeBy = (versionMadeBy & MAX_8_BITS);
5764
5809
  }
5765
- if (msdosAttributesRaw !== UNDEFINED_VALUE && (!Number.isInteger(msdosAttributesRaw) || msdosAttributesRaw < 0 || msdosAttributesRaw > MAX_8_BITS)) {
5766
- throw new Error(ERR_INVALID_MSDOS_ATTRIBUTES);
5767
- }
5810
+ checkIntegerOption(msdosAttributesRaw, MAX_8_BITS, ERR_INVALID_MSDOS_ATTRIBUTES);
5768
5811
  if (msdosAttributes && (typeof msdosAttributes !== OBJECT_TYPE || Array.isArray(msdosAttributes))) {
5769
5812
  throw new Error(ERR_INVALID_MSDOS_DATA);
5770
5813
  }
@@ -5904,9 +5947,7 @@
5904
5947
  throw new Error(ERR_UNSUPPORTED_COMPRESSION);
5905
5948
  }
5906
5949
  let level = getNumberOptionValue(zipWriter, options, OPTION_LEVEL);
5907
- if (level !== UNDEFINED_VALUE && (!Number.isInteger(level) || level < 0 || level > MAX_LEVEL)) {
5908
- throw new Error(ERR_INVALID_LEVEL);
5909
- }
5950
+ checkIntegerOption(level, MAX_LEVEL, ERR_INVALID_LEVEL);
5910
5951
  if (zipWriter.options[OPTION_USDZ]) {
5911
5952
  if (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) {
5912
5953
  throw new Error(ERR_UNSUPPORTED_ENCRYPTION_USDZ);
@@ -5915,6 +5956,9 @@
5915
5956
  level = 0;
5916
5957
  }
5917
5958
  }
5959
+ if (passThrough) {
5960
+ level = UNDEFINED_VALUE;
5961
+ }
5918
5962
  let useCompressionStream = getOptionValue(zipWriter, options, OPTION_USE_COMPRESSION_STREAM);
5919
5963
  let dataDescriptor = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR);
5920
5964
  if (bufferedWrite && dataDescriptor === UNDEFINED_VALUE) {
@@ -5981,9 +6025,7 @@
5981
6025
  let extraFieldSize = 0;
5982
6026
  let offset = 0;
5983
6027
  extraField.forEach((data, type) => {
5984
- if (!Number.isInteger(type) || type < 0 || type > MAX_16_BITS) {
5985
- throw new Error(ERR_INVALID_EXTRAFIELD_TYPE);
5986
- }
6028
+ checkInteger(type, MAX_16_BITS, ERR_INVALID_EXTRAFIELD_TYPE);
5987
6029
  if (!(data instanceof Uint8Array)) {
5988
6030
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA_TYPE);
5989
6031
  }
@@ -6026,6 +6068,9 @@
6026
6068
  if (uncompressedSize === UNDEFINED_VALUE) {
6027
6069
  throw new Error(ERR_UNDEFINED_UNCOMPRESSED_SIZE);
6028
6070
  }
6071
+ if (compressionMethod === UNDEFINED_VALUE) {
6072
+ throw new Error(ERR_UNDEFINED_COMPRESSION_METHOD);
6073
+ }
6029
6074
  }
6030
6075
  const zip64Enabled = zip64 === true;
6031
6076
  const encrypted = getOptionValue(zipWriter, options, PROPERTY_NAME_ENCRYPTED);
@@ -6095,7 +6140,9 @@
6095
6140
  const usdz = writerOptions[OPTION_USDZ];
6096
6141
  const files = new Map();
6097
6142
  let layoutDependsOnWriteOrder = Boolean(usdz);
6098
- let offset = 0;
6143
+ const initialOffset = writerOptions[OPTION_OFFSET] === UNDEFINED_VALUE ? 0 : writerOptions[OPTION_OFFSET];
6144
+ let offset = initialOffset;
6145
+ let minimumEntrySize = INFINITY_VALUE;
6099
6146
  for (const entry of entries) {
6100
6147
  let { name } = entry;
6101
6148
  const { size } = entry;
@@ -6119,7 +6166,7 @@
6119
6166
  if (hasContent && !metadata.passThrough && isCompressed(sizes.compressionMethod, sizes.level)) {
6120
6167
  throw new Error(ERR_UNDETERMINED_SIZE);
6121
6168
  }
6122
- const entryOptions = Object.assign({}, options, attributesInfo.resolvedOptions, metadata, sizes);
6169
+ const entryOptions = Object.assign({}, options, attributesInfo.resolvedOptions, metadata, sizes, { [OPTION_USDZ]: usdz });
6123
6170
  const headerInfo = getHeaderInfo(entryOptions);
6124
6171
  const dataDescriptorInfo = getDataDescriptorInfo(entryOptions);
6125
6172
  const entryInfo = {
@@ -6130,15 +6177,17 @@
6130
6177
  appendExtraFieldUSDZ(entryInfo, offset);
6131
6178
  }
6132
6179
  const compressedSize = hasContent ? maximumCompressedSize : 0;
6133
- if (offset >= MAX_32_BITS) {
6134
- layoutDependsOnWriteOrder = true;
6135
- }
6136
6180
  files.set(name, Object.assign({}, entryOptions, headerInfo, {
6137
6181
  offset,
6138
6182
  diskNumberStart: 0,
6139
6183
  compressedSize
6140
6184
  }));
6141
- offset += entryInfo.metadataSize + compressedSize;
6185
+ const entrySize = entryInfo.metadataSize + compressedSize;
6186
+ minimumEntrySize = Math.min(minimumEntrySize, entrySize);
6187
+ offset += entrySize;
6188
+ }
6189
+ if (files.size && offset - minimumEntrySize >= MAX_32_BITS) {
6190
+ layoutDependsOnWriteOrder = true;
6142
6191
  }
6143
6192
  if (layoutDependsOnWriteOrder && !writeOrderGuaranteed) {
6144
6193
  throw new Error(ERR_UNDETERMINED_SIZE);
@@ -6152,7 +6201,7 @@
6152
6201
  zip64 = true;
6153
6202
  }
6154
6203
  }
6155
- return offset + directoryDataLength + commentLength + (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
6204
+ return offset - initialOffset + directoryDataLength + commentLength + (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
6156
6205
  }
6157
6206
 
6158
6207
  async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
@@ -6649,12 +6698,13 @@
6649
6698
  if (passThrough && crc32 !== UNDEFINED_VALUE) {
6650
6699
  rawExtraFieldAES[EXTRAFIELD_OFFSET_AES_VENDOR_VERSION] = VENDOR_VERSION_AE_1;
6651
6700
  }
6652
- rawExtraFieldAES[9] = compressionMethod;
6701
+ setUint16(getDataView(rawExtraFieldAES), EXTRAFIELD_OFFSET_AES_COMPRESSION_METHOD, compressionMethod);
6653
6702
  compressionMethod = COMPRESSION_METHOD_AES;
6654
6703
  }
6655
6704
  const localExtraFieldZip64Length = writeLocalExtraFieldZip64 ? getLength(rawLocalExtraFieldZip64) : 0;
6656
6705
  const extraFieldLength = localExtraFieldZip64Length + getLength(rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField, rawLocalExtraField);
6657
- if (extraFieldLength > MAX_16_BITS) {
6706
+ const maximumUsdzExtraFieldLength = options[OPTION_USDZ] ? EXTRAFIELD_USDZ_MAX_LENGTH : 0;
6707
+ if (extraFieldLength + maximumUsdzExtraFieldLength > MAX_16_BITS) {
6658
6708
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
6659
6709
  }
6660
6710
  const dosLastModDate = new Date(Math.ceil(Math.floor(lastModDate.getTime() / 1000) / 2) * 2000);
@@ -7055,7 +7105,11 @@
7055
7105
  signatureRecord.writeUint32(DIGITAL_SIGNATURE_RECORD_SIGNATURE);
7056
7106
  signatureRecord.writeUint16(signatureDataLength);
7057
7107
  signatureRecord.writeBytes(signatureData);
7058
- await writeData(zipWriter.writer, signatureRecord.array);
7108
+ const { writer } = zipWriter;
7109
+ if (exceedsAvailableSize(writer, getLength(signatureRecord.array))) {
7110
+ await writer.closeDisk();
7111
+ }
7112
+ await writeData(writer, signatureRecord.array);
7059
7113
  return 6 + signatureDataLength;
7060
7114
  }
7061
7115
  return 0;
@@ -7166,7 +7220,7 @@
7166
7220
  return getUint32(getDataView(signatureArray), 0) == SPLIT_ZIP_FILE_SIGNATURE;
7167
7221
  }
7168
7222
 
7169
- async function copyZipData(zipWriter, reader, entries, directoryOffset, splitZipSignatureLength) {
7223
+ async function copyZipData(zipWriter, reader, entries, directoryOffset) {
7170
7224
  const { writer } = zipWriter;
7171
7225
  const entryPositions = new Map();
7172
7226
  if (writer.closeDisk) {
@@ -7187,9 +7241,10 @@
7187
7241
  }
7188
7242
  await copyData(zipWriter, reader, copiedLength, directoryOffset - copiedLength);
7189
7243
  } else {
7244
+ const baseOffset = zipWriter.offset;
7190
7245
  await copyData(zipWriter, reader, 0, directoryOffset);
7191
7246
  entries.forEach(entry => entryPositions.set(entry, {
7192
- offset: splitZipSignatureLength + getSourceOffset(reader, entry),
7247
+ offset: baseOffset + getSourceOffset(reader, entry),
7193
7248
  diskNumberStart: 0
7194
7249
  }));
7195
7250
  }
@@ -8358,10 +8413,7 @@
8358
8413
  });
8359
8414
  }
8360
8415
  if (isPassThrough(child, options)) {
8361
- let level, encryptionStrength;
8362
- if (compressionMethod === 0) {
8363
- level = 0;
8364
- }
8416
+ let encryptionStrength;
8365
8417
  if (extraFieldAES) {
8366
8418
  encryptionStrength = extraFieldAES.strength;
8367
8419
  }
@@ -8371,7 +8423,6 @@
8371
8423
  zipCrypto,
8372
8424
  crc32,
8373
8425
  uncompressedSize,
8374
- level,
8375
8426
  encryptionStrength,
8376
8427
  compressionMethod
8377
8428
  };