@zip.js/zip.js 2.6.42 → 2.6.44

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-fs.js CHANGED
@@ -2883,7 +2883,7 @@
2883
2883
  }
2884
2884
  }
2885
2885
 
2886
- class SplitZipReader extends Reader {
2886
+ class SplitDataReader extends Reader {
2887
2887
 
2888
2888
  constructor(readers) {
2889
2889
  super();
@@ -2929,7 +2929,7 @@
2929
2929
  }
2930
2930
  }
2931
2931
 
2932
- class SplitZipWriter extends Stream {
2932
+ class SplitDataWriter extends Stream {
2933
2933
 
2934
2934
  constructor(writerGenerator, maxSize = 4294967296) {
2935
2935
  super();
@@ -2950,6 +2950,7 @@
2950
2950
  } else {
2951
2951
  diskSourceWriter = value;
2952
2952
  diskSourceWriter.size = 0;
2953
+ await initStream(diskSourceWriter);
2953
2954
  diskWritable = value.writable;
2954
2955
  diskWriter = diskWritable.getWriter();
2955
2956
  }
@@ -3010,6 +3011,9 @@
3010
3011
  return reader.readUint8Array(offset, size, diskNumber);
3011
3012
  }
3012
3013
 
3014
+ const SplitZipReader = SplitDataReader;
3015
+ const SplitZipWriter = SplitDataWriter;
3016
+
3013
3017
  /*
3014
3018
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
3015
3019
 
@@ -3236,7 +3240,7 @@
3236
3240
  await initStream(reader);
3237
3241
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
3238
3242
  if (Array.isArray(reader)) {
3239
- reader = new SplitZipReader(reader);
3243
+ reader = new SplitDataReader(reader);
3240
3244
  } else {
3241
3245
  reader = new BlobReader(await new Response(reader.readable).blob());
3242
3246
  }
@@ -3814,7 +3818,7 @@
3814
3818
 
3815
3819
  constructor(writer, options = {}) {
3816
3820
  if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE$1) {
3817
- writer = new SplitZipWriter(writer);
3821
+ writer = new SplitDataWriter(writer);
3818
3822
  }
3819
3823
  if (writer instanceof WritableStream) {
3820
3824
  writer = { writable: writer };
@@ -3822,7 +3826,7 @@
3822
3826
  if (writer.writable.size === UNDEFINED_VALUE) {
3823
3827
  writer.writable.size = 0;
3824
3828
  }
3825
- const splitZipFile = writer instanceof SplitZipWriter;
3829
+ const splitZipFile = writer instanceof SplitDataWriter;
3826
3830
  if (!splitZipFile) {
3827
3831
  Object.assign(writer, {
3828
3832
  diskNumber: 0,
@@ -3879,13 +3883,15 @@
3879
3883
  }
3880
3884
 
3881
3885
  async close(comment = new Uint8Array(), options = {}) {
3886
+ const zipWriter = this;
3882
3887
  const { pendingAddFileCalls, writer } = this;
3883
3888
  const { writable } = writer;
3884
3889
  while (pendingAddFileCalls.size) {
3885
3890
  await Promise.all(Array.from(pendingAddFileCalls));
3886
3891
  }
3887
3892
  await closeFile(this, comment, options);
3888
- if (!writer.preventClose && !options.preventClose) {
3893
+ const preventClose = getOptionValue(zipWriter, options, "preventClose");
3894
+ if (!preventClose) {
3889
3895
  await writable.close();
3890
3896
  }
3891
3897
  return writer.getData ? writer.getData() : writable;
@@ -3908,20 +3914,33 @@
3908
3914
  if (getLength(rawComment) > MAX_16_BITS) {
3909
3915
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
3910
3916
  }
3911
- const version = zipWriter.options.version || options.version || 0;
3917
+ const version = getOptionValue(zipWriter, options, "version", VERSION_DEFLATE);
3912
3918
  if (version > MAX_16_BITS) {
3913
3919
  throw new Error(ERR_INVALID_VERSION);
3914
3920
  }
3915
- const versionMadeBy = zipWriter.options.versionMadeBy || options.versionMadeBy || 20;
3921
+ const versionMadeBy = getOptionValue(zipWriter, options, "versionMadeBy", 20);
3916
3922
  if (versionMadeBy > MAX_16_BITS) {
3917
3923
  throw new Error(ERR_INVALID_VERSION);
3918
3924
  }
3919
- const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE) || new Date();
3925
+ const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
3920
3926
  const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
3921
3927
  const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
3928
+ const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
3929
+ const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
3930
+ const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
3922
3931
  const password = getOptionValue(zipWriter, options, "password");
3923
- const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
3932
+ const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
3924
3933
  const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
3934
+ const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
3935
+ const keepOrder = getOptionValue(zipWriter, options, "keepOrder", true);
3936
+ const level = getOptionValue(zipWriter, options, "level");
3937
+ const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
3938
+ const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
3939
+ const dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature", false);
3940
+ const signal = getOptionValue(zipWriter, options, "signal");
3941
+ const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
3942
+ let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
3943
+ let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
3925
3944
  if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
3926
3945
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
3927
3946
  }
@@ -3945,24 +3964,9 @@
3945
3964
  offset += 4 + getLength(data);
3946
3965
  });
3947
3966
  }
3948
- let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
3949
- if (extendedTimestamp === UNDEFINED_VALUE) {
3950
- extendedTimestamp = true;
3951
- }
3952
3967
  let maximumCompressedSize = 0;
3953
3968
  let maximumEntrySize = 0;
3954
- let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
3955
- if (keepOrder === UNDEFINED_VALUE) {
3956
- keepOrder = true;
3957
- }
3958
3969
  let uncompressedSize = 0;
3959
- let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
3960
- if (msDosCompatible === UNDEFINED_VALUE) {
3961
- msDosCompatible = true;
3962
- }
3963
- const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE) || 0;
3964
- const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE) || 0;
3965
- let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
3966
3970
  if (reader) {
3967
3971
  if (reader instanceof ReadableStream) {
3968
3972
  reader = {
@@ -3971,7 +3975,7 @@
3971
3975
  }
3972
3976
  await initStream(reader);
3973
3977
  if (reader.size === UNDEFINED_VALUE) {
3974
- options.dataDescriptor = true;
3978
+ dataDescriptor = true;
3975
3979
  if (zip64 || zip64 === UNDEFINED_VALUE) {
3976
3980
  zip64 = true;
3977
3981
  maximumCompressedSize = MAX_32_BITS;
@@ -3981,10 +3985,11 @@
3981
3985
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
3982
3986
  }
3983
3987
  }
3984
- const { diskOffset } = zipWriter.writer;
3988
+ const { diskOffset, diskNumber } = zipWriter.writer;
3985
3989
  if (zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS ||
3986
3990
  uncompressedSize >= MAX_32_BITS ||
3987
- maximumCompressedSize >= MAX_32_BITS) {
3991
+ maximumCompressedSize >= MAX_32_BITS ||
3992
+ diskNumber >= MAX_16_BITS) {
3988
3993
  if (zip64 === false || !keepOrder) {
3989
3994
  throw new Error(ERR_UNSUPPORTED_FORMAT);
3990
3995
  } else {
@@ -3992,19 +3997,6 @@
3992
3997
  }
3993
3998
  }
3994
3999
  zip64 = zip64 || false;
3995
- const level = getOptionValue(zipWriter, options, "level");
3996
- const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
3997
- const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
3998
- let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor");
3999
- let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
4000
- const signal = getOptionValue(zipWriter, options, "signal");
4001
- const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
4002
- if (dataDescriptor === UNDEFINED_VALUE) {
4003
- dataDescriptor = true;
4004
- }
4005
- if (dataDescriptor && dataDescriptorSignature === UNDEFINED_VALUE) {
4006
- dataDescriptorSignature = false;
4007
- }
4008
4000
  options = Object.assign({}, options, {
4009
4001
  rawFilename,
4010
4002
  rawComment,
@@ -4038,12 +4030,8 @@
4038
4030
  let fileEntry;
4039
4031
  try {
4040
4032
  fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo }, options);
4033
+ } finally {
4041
4034
  zipWriter.pendingEntriesSize -= maximumEntrySize;
4042
- } catch (error) {
4043
- if (!error.corruptedEntry) {
4044
- zipWriter.pendingEntriesSize -= maximumEntrySize;
4045
- }
4046
- throw error;
4047
4035
  }
4048
4036
  Object.assign(fileEntry, { name, comment, extraField });
4049
4037
  return new Entry(fileEntry);
@@ -4081,8 +4069,7 @@
4081
4069
  await initStream(writer);
4082
4070
  } else {
4083
4071
  fileWriter = writer;
4084
- zipWriter.lockWriter = Promise.resolve();
4085
- releaseLockWriter = () => delete zipWriter.lockWriter;
4072
+ initLockWriter();
4086
4073
  }
4087
4074
  await initStream(fileWriter);
4088
4075
  const { writable, diskNumber } = writer;
@@ -4111,7 +4098,7 @@
4111
4098
  await requestLockWriter();
4112
4099
  writingBufferedEntryData = true;
4113
4100
  if (!dataDescriptor) {
4114
- blob = await setMissingInfo(fileEntry, blob, writable, options);
4101
+ blob = await writeMissingHeaderInfo(fileEntry, blob, writable, options);
4115
4102
  }
4116
4103
  fileEntry.diskNumberStart = writer.diskNumber;
4117
4104
  diskOffset = writer.diskOffset;
@@ -4121,7 +4108,7 @@
4121
4108
  }
4122
4109
  fileEntry.offset = zipWriter.offset - diskOffset;
4123
4110
  if (fileEntry.zip64) {
4124
- setZip64Info(fileEntry);
4111
+ setZip64OffsetInfo(fileEntry);
4125
4112
  } else if (fileEntry.offset >= MAX_32_BITS) {
4126
4113
  throw new Error(ERR_UNSUPPORTED_FORMAT);
4127
4114
  }
@@ -4154,6 +4141,11 @@
4154
4141
  fileEntry.lock = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
4155
4142
  }
4156
4143
 
4144
+ function initLockWriter() {
4145
+ zipWriter.lockWriter = Promise.resolve();
4146
+ releaseLockWriter = () => delete zipWriter.lockWriter;
4147
+ }
4148
+
4157
4149
  async function requestLockWriter() {
4158
4150
  const { lockWriter } = zipWriter;
4159
4151
  if (lockWriter) {
@@ -4312,6 +4304,7 @@
4312
4304
  } = options;
4313
4305
  const compressed = level !== 0 && !directory;
4314
4306
  const encrypted = Boolean(password && getLength(password));
4307
+ let version = options.version;
4315
4308
  let rawExtraFieldAES;
4316
4309
  if (encrypted && !zipCrypto) {
4317
4310
  rawExtraFieldAES = new Uint8Array(getLength(EXTRAFIELD_DATA_AES) + 2);
@@ -4363,7 +4356,6 @@
4363
4356
  if (compressed) {
4364
4357
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
4365
4358
  }
4366
- let version = options.version || VERSION_DEFLATE;
4367
4359
  if (zip64) {
4368
4360
  version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
4369
4361
  }
@@ -4497,7 +4489,7 @@
4497
4489
  }
4498
4490
  }
4499
4491
 
4500
- async function setMissingInfo(fileEntry, entryData, writable, { zipCrypto }) {
4492
+ async function writeMissingHeaderInfo(fileEntry, entryData, writable, { zipCrypto }) {
4501
4493
  const arrayBuffer = await sliceAsArrayBuffer(entryData, 0, 26);
4502
4494
  const arrayBufferView = new DataView(arrayBuffer);
4503
4495
  if (!fileEntry.encrypted || zipCrypto) {
@@ -4514,7 +4506,7 @@
4514
4506
  return entryData.slice(arrayBuffer.byteLength);
4515
4507
  }
4516
4508
 
4517
- function setZip64Info(fileEntry) {
4509
+ function setZip64OffsetInfo(fileEntry) {
4518
4510
  const { rawExtraFieldZip64, offset, diskNumberStart } = fileEntry;
4519
4511
  const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
4520
4512
  setBigUint64(rawExtraFieldZip64View, 20, BigInt(offset));
@@ -4523,10 +4515,10 @@
4523
4515
 
4524
4516
  async function closeFile(zipWriter, comment, options) {
4525
4517
  const { files, writer } = zipWriter;
4526
- let offset = 0;
4527
- let directoryDataLength = 0;
4528
4518
  const { diskOffset, writable } = writer;
4529
4519
  let { diskNumber } = writer;
4520
+ let offset = 0;
4521
+ let directoryDataLength = 0;
4530
4522
  let directoryOffset = zipWriter.offset - diskOffset;
4531
4523
  let filesLength = files.size;
4532
4524
  for (const [, {
@@ -4548,14 +4540,6 @@
4548
4540
  rawExtraFieldNTFS,
4549
4541
  rawExtraField);
4550
4542
  }
4551
- let zip64 = options.zip64 || zipWriter.options.zip64 || false;
4552
- if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) {
4553
- if (options.zip64 === false || zipWriter.options.zip64 === false) {
4554
- throw new Error(ERR_UNSUPPORTED_FORMAT);
4555
- } else {
4556
- zip64 = true;
4557
- }
4558
- }
4559
4543
  const directoryArray = new Uint8Array(directoryDataLength);
4560
4544
  const directoryView = getDataView(directoryArray);
4561
4545
  for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
@@ -4621,13 +4605,21 @@
4621
4605
  }
4622
4606
  await initStream(writer);
4623
4607
  await writeData(writable, directoryArray);
4624
- const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
4625
- const endOfdirectoryView = getDataView(endOfdirectoryArray);
4626
4608
  let lastDiskNumber = writer.diskNumber;
4627
4609
  const { availableSize } = writer;
4628
- if (availableSize < getLength(endOfdirectoryArray)) {
4610
+ if (availableSize < END_OF_CENTRAL_DIR_LENGTH) {
4629
4611
  lastDiskNumber++;
4630
4612
  }
4613
+ let zip64 = getOptionValue(zipWriter, options, "zip64");
4614
+ if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
4615
+ if (zip64 === false) {
4616
+ throw new Error(ERR_UNSUPPORTED_FORMAT);
4617
+ } else {
4618
+ zip64 = true;
4619
+ }
4620
+ }
4621
+ const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
4622
+ const endOfdirectoryView = getDataView(endOfdirectoryArray);
4631
4623
  offset = 0;
4632
4624
  if (zip64) {
4633
4625
  setUint32(endOfdirectoryView, 0, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
@@ -4692,8 +4684,9 @@
4692
4684
  }
4693
4685
  }
4694
4686
 
4695
- function getOptionValue(zipWriter, options, name) {
4696
- return options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
4687
+ function getOptionValue(zipWriter, options, name, defaultValue) {
4688
+ const result = options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
4689
+ return result === UNDEFINED_VALUE ? defaultValue : result;
4697
4690
  }
4698
4691
 
4699
4692
  function getMaximumCompressedSize(uncompressedSize) {
@@ -5410,6 +5403,8 @@
5410
5403
  exports.HttpRangeReader = HttpRangeReader;
5411
5404
  exports.HttpReader = HttpReader;
5412
5405
  exports.Reader = Reader;
5406
+ exports.SplitDataReader = SplitDataReader;
5407
+ exports.SplitDataWriter = SplitDataWriter;
5413
5408
  exports.SplitZipReader = SplitZipReader;
5414
5409
  exports.SplitZipWriter = SplitZipWriter;
5415
5410
  exports.TextReader = TextReader;