@zip.js/zip.js 2.6.43 → 2.6.45

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();
@@ -2938,6 +2938,7 @@
2938
2938
  diskNumber: 0,
2939
2939
  diskOffset: 0,
2940
2940
  size: 0,
2941
+ maxSize,
2941
2942
  availableSize: maxSize
2942
2943
  });
2943
2944
  let diskSourceWriter, diskWritable, diskWriter;
@@ -2950,6 +2951,7 @@
2950
2951
  } else {
2951
2952
  diskSourceWriter = value;
2952
2953
  diskSourceWriter.size = 0;
2954
+ await initStream(diskSourceWriter);
2953
2955
  diskWritable = value.writable;
2954
2956
  diskWriter = diskWritable.getWriter();
2955
2957
  }
@@ -3010,6 +3012,9 @@
3010
3012
  return reader.readUint8Array(offset, size, diskNumber);
3011
3013
  }
3012
3014
 
3015
+ const SplitZipReader = SplitDataReader;
3016
+ const SplitZipWriter = SplitDataWriter;
3017
+
3013
3018
  /*
3014
3019
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
3015
3020
 
@@ -3236,7 +3241,7 @@
3236
3241
  await initStream(reader);
3237
3242
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
3238
3243
  if (Array.isArray(reader)) {
3239
- reader = new SplitZipReader(reader);
3244
+ reader = new SplitDataReader(reader);
3240
3245
  } else {
3241
3246
  reader = new BlobReader(await new Response(reader.readable).blob());
3242
3247
  }
@@ -3814,7 +3819,7 @@
3814
3819
 
3815
3820
  constructor(writer, options = {}) {
3816
3821
  if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE$1) {
3817
- writer = new SplitZipWriter(writer);
3822
+ writer = new SplitDataWriter(writer);
3818
3823
  }
3819
3824
  if (writer instanceof WritableStream) {
3820
3825
  writer = { writable: writer };
@@ -3822,12 +3827,13 @@
3822
3827
  if (writer.writable.size === UNDEFINED_VALUE) {
3823
3828
  writer.writable.size = 0;
3824
3829
  }
3825
- const splitZipFile = writer instanceof SplitZipWriter;
3830
+ const splitZipFile = writer instanceof SplitDataWriter;
3826
3831
  if (!splitZipFile) {
3827
3832
  Object.assign(writer, {
3828
3833
  diskNumber: 0,
3829
3834
  diskOffset: 0,
3830
- availableSize: Infinity
3835
+ availableSize: Infinity,
3836
+ maxSize: Infinity
3831
3837
  });
3832
3838
  }
3833
3839
  Object.assign(this, {
@@ -3879,13 +3885,15 @@
3879
3885
  }
3880
3886
 
3881
3887
  async close(comment = new Uint8Array(), options = {}) {
3888
+ const zipWriter = this;
3882
3889
  const { pendingAddFileCalls, writer } = this;
3883
3890
  const { writable } = writer;
3884
3891
  while (pendingAddFileCalls.size) {
3885
3892
  await Promise.all(Array.from(pendingAddFileCalls));
3886
3893
  }
3887
3894
  await closeFile(this, comment, options);
3888
- if (!writer.preventClose && !options.preventClose) {
3895
+ const preventClose = getOptionValue(zipWriter, options, "preventClose");
3896
+ if (!preventClose) {
3889
3897
  await writable.close();
3890
3898
  }
3891
3899
  return writer.getData ? writer.getData() : writable;
@@ -3908,20 +3916,33 @@
3908
3916
  if (getLength(rawComment) > MAX_16_BITS) {
3909
3917
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
3910
3918
  }
3911
- const version = zipWriter.options.version || options.version || 0;
3919
+ const version = getOptionValue(zipWriter, options, "version", VERSION_DEFLATE);
3912
3920
  if (version > MAX_16_BITS) {
3913
3921
  throw new Error(ERR_INVALID_VERSION);
3914
3922
  }
3915
- const versionMadeBy = zipWriter.options.versionMadeBy || options.versionMadeBy || 20;
3923
+ const versionMadeBy = getOptionValue(zipWriter, options, "versionMadeBy", 20);
3916
3924
  if (versionMadeBy > MAX_16_BITS) {
3917
3925
  throw new Error(ERR_INVALID_VERSION);
3918
3926
  }
3919
- const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE) || new Date();
3927
+ const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
3920
3928
  const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
3921
3929
  const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
3930
+ const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
3931
+ const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
3932
+ const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
3922
3933
  const password = getOptionValue(zipWriter, options, "password");
3923
- const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
3934
+ const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
3924
3935
  const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
3936
+ const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
3937
+ const keepOrder = getOptionValue(zipWriter, options, "keepOrder", true);
3938
+ const level = getOptionValue(zipWriter, options, "level");
3939
+ const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
3940
+ const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
3941
+ const dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature", false);
3942
+ const signal = getOptionValue(zipWriter, options, "signal");
3943
+ const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
3944
+ let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
3945
+ let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
3925
3946
  if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
3926
3947
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
3927
3948
  }
@@ -3945,24 +3966,9 @@
3945
3966
  offset += 4 + getLength(data);
3946
3967
  });
3947
3968
  }
3948
- let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
3949
- if (extendedTimestamp === UNDEFINED_VALUE) {
3950
- extendedTimestamp = true;
3951
- }
3952
3969
  let maximumCompressedSize = 0;
3953
3970
  let maximumEntrySize = 0;
3954
- let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
3955
- if (keepOrder === UNDEFINED_VALUE) {
3956
- keepOrder = true;
3957
- }
3958
3971
  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
3972
  if (reader) {
3967
3973
  if (reader instanceof ReadableStream) {
3968
3974
  reader = {
@@ -3971,7 +3977,7 @@
3971
3977
  }
3972
3978
  await initStream(reader);
3973
3979
  if (reader.size === UNDEFINED_VALUE) {
3974
- options.dataDescriptor = true;
3980
+ dataDescriptor = true;
3975
3981
  if (zip64 || zip64 === UNDEFINED_VALUE) {
3976
3982
  zip64 = true;
3977
3983
  maximumCompressedSize = MAX_32_BITS;
@@ -3981,10 +3987,11 @@
3981
3987
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
3982
3988
  }
3983
3989
  }
3984
- const { diskOffset } = zipWriter.writer;
3990
+ const { diskOffset, diskNumber, maxSize } = zipWriter.writer;
3985
3991
  if (zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS ||
3986
3992
  uncompressedSize >= MAX_32_BITS ||
3987
- maximumCompressedSize >= MAX_32_BITS) {
3993
+ maximumCompressedSize >= MAX_32_BITS ||
3994
+ diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) >= MAX_16_BITS) {
3988
3995
  if (zip64 === false || !keepOrder) {
3989
3996
  throw new Error(ERR_UNSUPPORTED_FORMAT);
3990
3997
  } else {
@@ -3992,19 +3999,6 @@
3992
3999
  }
3993
4000
  }
3994
4001
  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
4002
  options = Object.assign({}, options, {
4009
4003
  rawFilename,
4010
4004
  rawComment,
@@ -4077,8 +4071,7 @@
4077
4071
  await initStream(writer);
4078
4072
  } else {
4079
4073
  fileWriter = writer;
4080
- zipWriter.lockWriter = Promise.resolve();
4081
- releaseLockWriter = () => delete zipWriter.lockWriter;
4074
+ initLockWriter();
4082
4075
  }
4083
4076
  await initStream(fileWriter);
4084
4077
  const { writable, diskNumber } = writer;
@@ -4107,7 +4100,7 @@
4107
4100
  await requestLockWriter();
4108
4101
  writingBufferedEntryData = true;
4109
4102
  if (!dataDescriptor) {
4110
- blob = await setMissingInfo(fileEntry, blob, writable, options);
4103
+ blob = await writeMissingHeaderInfo(fileEntry, blob, writable, options);
4111
4104
  }
4112
4105
  fileEntry.diskNumberStart = writer.diskNumber;
4113
4106
  diskOffset = writer.diskOffset;
@@ -4117,7 +4110,7 @@
4117
4110
  }
4118
4111
  fileEntry.offset = zipWriter.offset - diskOffset;
4119
4112
  if (fileEntry.zip64) {
4120
- setZip64Info(fileEntry);
4113
+ setZip64OffsetInfo(fileEntry);
4121
4114
  } else if (fileEntry.offset >= MAX_32_BITS) {
4122
4115
  throw new Error(ERR_UNSUPPORTED_FORMAT);
4123
4116
  }
@@ -4150,6 +4143,11 @@
4150
4143
  fileEntry.lock = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
4151
4144
  }
4152
4145
 
4146
+ function initLockWriter() {
4147
+ zipWriter.lockWriter = Promise.resolve();
4148
+ releaseLockWriter = () => delete zipWriter.lockWriter;
4149
+ }
4150
+
4153
4151
  async function requestLockWriter() {
4154
4152
  const { lockWriter } = zipWriter;
4155
4153
  if (lockWriter) {
@@ -4308,6 +4306,7 @@
4308
4306
  } = options;
4309
4307
  const compressed = level !== 0 && !directory;
4310
4308
  const encrypted = Boolean(password && getLength(password));
4309
+ let version = options.version;
4311
4310
  let rawExtraFieldAES;
4312
4311
  if (encrypted && !zipCrypto) {
4313
4312
  rawExtraFieldAES = new Uint8Array(getLength(EXTRAFIELD_DATA_AES) + 2);
@@ -4359,7 +4358,6 @@
4359
4358
  if (compressed) {
4360
4359
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
4361
4360
  }
4362
- let version = options.version || VERSION_DEFLATE;
4363
4361
  if (zip64) {
4364
4362
  version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
4365
4363
  }
@@ -4493,7 +4491,7 @@
4493
4491
  }
4494
4492
  }
4495
4493
 
4496
- async function setMissingInfo(fileEntry, entryData, writable, { zipCrypto }) {
4494
+ async function writeMissingHeaderInfo(fileEntry, entryData, writable, { zipCrypto }) {
4497
4495
  const arrayBuffer = await sliceAsArrayBuffer(entryData, 0, 26);
4498
4496
  const arrayBufferView = new DataView(arrayBuffer);
4499
4497
  if (!fileEntry.encrypted || zipCrypto) {
@@ -4510,7 +4508,7 @@
4510
4508
  return entryData.slice(arrayBuffer.byteLength);
4511
4509
  }
4512
4510
 
4513
- function setZip64Info(fileEntry) {
4511
+ function setZip64OffsetInfo(fileEntry) {
4514
4512
  const { rawExtraFieldZip64, offset, diskNumberStart } = fileEntry;
4515
4513
  const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
4516
4514
  setBigUint64(rawExtraFieldZip64View, 20, BigInt(offset));
@@ -4519,10 +4517,10 @@
4519
4517
 
4520
4518
  async function closeFile(zipWriter, comment, options) {
4521
4519
  const { files, writer } = zipWriter;
4522
- let offset = 0;
4523
- let directoryDataLength = 0;
4524
4520
  const { diskOffset, writable } = writer;
4525
4521
  let { diskNumber } = writer;
4522
+ let offset = 0;
4523
+ let directoryDataLength = 0;
4526
4524
  let directoryOffset = zipWriter.offset - diskOffset;
4527
4525
  let filesLength = files.size;
4528
4526
  for (const [, {
@@ -4544,14 +4542,6 @@
4544
4542
  rawExtraFieldNTFS,
4545
4543
  rawExtraField);
4546
4544
  }
4547
- let zip64 = options.zip64 || zipWriter.options.zip64 || false;
4548
- if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) {
4549
- if (options.zip64 === false || zipWriter.options.zip64 === false) {
4550
- throw new Error(ERR_UNSUPPORTED_FORMAT);
4551
- } else {
4552
- zip64 = true;
4553
- }
4554
- }
4555
4545
  const directoryArray = new Uint8Array(directoryDataLength);
4556
4546
  const directoryView = getDataView(directoryArray);
4557
4547
  for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
@@ -4617,13 +4607,21 @@
4617
4607
  }
4618
4608
  await initStream(writer);
4619
4609
  await writeData(writable, directoryArray);
4620
- const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
4621
- const endOfdirectoryView = getDataView(endOfdirectoryArray);
4622
4610
  let lastDiskNumber = writer.diskNumber;
4623
4611
  const { availableSize } = writer;
4624
- if (availableSize < getLength(endOfdirectoryArray)) {
4612
+ if (availableSize < END_OF_CENTRAL_DIR_LENGTH) {
4625
4613
  lastDiskNumber++;
4626
4614
  }
4615
+ let zip64 = getOptionValue(zipWriter, options, "zip64");
4616
+ if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
4617
+ if (zip64 === false) {
4618
+ throw new Error(ERR_UNSUPPORTED_FORMAT);
4619
+ } else {
4620
+ zip64 = true;
4621
+ }
4622
+ }
4623
+ const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
4624
+ const endOfdirectoryView = getDataView(endOfdirectoryArray);
4627
4625
  offset = 0;
4628
4626
  if (zip64) {
4629
4627
  setUint32(endOfdirectoryView, 0, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
@@ -4688,8 +4686,9 @@
4688
4686
  }
4689
4687
  }
4690
4688
 
4691
- function getOptionValue(zipWriter, options, name) {
4692
- return options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
4689
+ function getOptionValue(zipWriter, options, name, defaultValue) {
4690
+ const result = options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
4691
+ return result === UNDEFINED_VALUE ? defaultValue : result;
4693
4692
  }
4694
4693
 
4695
4694
  function getMaximumCompressedSize(uncompressedSize) {
@@ -5406,6 +5405,8 @@
5406
5405
  exports.HttpRangeReader = HttpRangeReader;
5407
5406
  exports.HttpReader = HttpReader;
5408
5407
  exports.Reader = Reader;
5408
+ exports.SplitDataReader = SplitDataReader;
5409
+ exports.SplitDataWriter = SplitDataWriter;
5409
5410
  exports.SplitZipReader = SplitZipReader;
5410
5411
  exports.SplitZipWriter = SplitZipWriter;
5411
5412
  exports.TextReader = TextReader;