@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-full.js CHANGED
@@ -7106,7 +7106,7 @@
7106
7106
  }
7107
7107
  }
7108
7108
 
7109
- class SplitZipReader extends Reader {
7109
+ class SplitDataReader extends Reader {
7110
7110
 
7111
7111
  constructor(readers) {
7112
7112
  super();
@@ -7152,7 +7152,7 @@
7152
7152
  }
7153
7153
  }
7154
7154
 
7155
- class SplitZipWriter extends Stream {
7155
+ class SplitDataWriter extends Stream {
7156
7156
 
7157
7157
  constructor(writerGenerator, maxSize = 4294967296) {
7158
7158
  super();
@@ -7161,6 +7161,7 @@
7161
7161
  diskNumber: 0,
7162
7162
  diskOffset: 0,
7163
7163
  size: 0,
7164
+ maxSize,
7164
7165
  availableSize: maxSize
7165
7166
  });
7166
7167
  let diskSourceWriter, diskWritable, diskWriter;
@@ -7173,6 +7174,7 @@
7173
7174
  } else {
7174
7175
  diskSourceWriter = value;
7175
7176
  diskSourceWriter.size = 0;
7177
+ await initStream(diskSourceWriter);
7176
7178
  diskWritable = value.writable;
7177
7179
  diskWriter = diskWritable.getWriter();
7178
7180
  }
@@ -7233,6 +7235,9 @@
7233
7235
  return reader.readUint8Array(offset, size, diskNumber);
7234
7236
  }
7235
7237
 
7238
+ const SplitZipReader = SplitDataReader;
7239
+ const SplitZipWriter = SplitDataWriter;
7240
+
7236
7241
  /*
7237
7242
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
7238
7243
 
@@ -7459,7 +7464,7 @@
7459
7464
  await initStream(reader);
7460
7465
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
7461
7466
  if (Array.isArray(reader)) {
7462
- reader = new SplitZipReader(reader);
7467
+ reader = new SplitDataReader(reader);
7463
7468
  } else {
7464
7469
  reader = new BlobReader(await new Response(reader.readable).blob());
7465
7470
  }
@@ -8037,7 +8042,7 @@
8037
8042
 
8038
8043
  constructor(writer, options = {}) {
8039
8044
  if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE$1) {
8040
- writer = new SplitZipWriter(writer);
8045
+ writer = new SplitDataWriter(writer);
8041
8046
  }
8042
8047
  if (writer instanceof WritableStream) {
8043
8048
  writer = { writable: writer };
@@ -8045,12 +8050,13 @@
8045
8050
  if (writer.writable.size === UNDEFINED_VALUE) {
8046
8051
  writer.writable.size = 0;
8047
8052
  }
8048
- const splitZipFile = writer instanceof SplitZipWriter;
8053
+ const splitZipFile = writer instanceof SplitDataWriter;
8049
8054
  if (!splitZipFile) {
8050
8055
  Object.assign(writer, {
8051
8056
  diskNumber: 0,
8052
8057
  diskOffset: 0,
8053
- availableSize: Infinity
8058
+ availableSize: Infinity,
8059
+ maxSize: Infinity
8054
8060
  });
8055
8061
  }
8056
8062
  Object.assign(this, {
@@ -8102,13 +8108,15 @@
8102
8108
  }
8103
8109
 
8104
8110
  async close(comment = new Uint8Array(), options = {}) {
8111
+ const zipWriter = this;
8105
8112
  const { pendingAddFileCalls, writer } = this;
8106
8113
  const { writable } = writer;
8107
8114
  while (pendingAddFileCalls.size) {
8108
8115
  await Promise.all(Array.from(pendingAddFileCalls));
8109
8116
  }
8110
8117
  await closeFile(this, comment, options);
8111
- if (!writer.preventClose && !options.preventClose) {
8118
+ const preventClose = getOptionValue(zipWriter, options, "preventClose");
8119
+ if (!preventClose) {
8112
8120
  await writable.close();
8113
8121
  }
8114
8122
  return writer.getData ? writer.getData() : writable;
@@ -8131,20 +8139,33 @@
8131
8139
  if (getLength(rawComment) > MAX_16_BITS) {
8132
8140
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
8133
8141
  }
8134
- const version = zipWriter.options.version || options.version || 0;
8142
+ const version = getOptionValue(zipWriter, options, "version", VERSION_DEFLATE);
8135
8143
  if (version > MAX_16_BITS) {
8136
8144
  throw new Error(ERR_INVALID_VERSION);
8137
8145
  }
8138
- const versionMadeBy = zipWriter.options.versionMadeBy || options.versionMadeBy || 20;
8146
+ const versionMadeBy = getOptionValue(zipWriter, options, "versionMadeBy", 20);
8139
8147
  if (versionMadeBy > MAX_16_BITS) {
8140
8148
  throw new Error(ERR_INVALID_VERSION);
8141
8149
  }
8142
- const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE) || new Date();
8150
+ const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
8143
8151
  const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
8144
8152
  const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
8153
+ const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
8154
+ const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
8155
+ const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
8145
8156
  const password = getOptionValue(zipWriter, options, "password");
8146
- const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
8157
+ const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
8147
8158
  const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
8159
+ const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
8160
+ const keepOrder = getOptionValue(zipWriter, options, "keepOrder", true);
8161
+ const level = getOptionValue(zipWriter, options, "level");
8162
+ const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
8163
+ const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
8164
+ const dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature", false);
8165
+ const signal = getOptionValue(zipWriter, options, "signal");
8166
+ const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
8167
+ let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
8168
+ let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
8148
8169
  if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
8149
8170
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
8150
8171
  }
@@ -8168,24 +8189,9 @@
8168
8189
  offset += 4 + getLength(data);
8169
8190
  });
8170
8191
  }
8171
- let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
8172
- if (extendedTimestamp === UNDEFINED_VALUE) {
8173
- extendedTimestamp = true;
8174
- }
8175
8192
  let maximumCompressedSize = 0;
8176
8193
  let maximumEntrySize = 0;
8177
- let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
8178
- if (keepOrder === UNDEFINED_VALUE) {
8179
- keepOrder = true;
8180
- }
8181
8194
  let uncompressedSize = 0;
8182
- let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
8183
- if (msDosCompatible === UNDEFINED_VALUE) {
8184
- msDosCompatible = true;
8185
- }
8186
- const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE) || 0;
8187
- const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE) || 0;
8188
- let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
8189
8195
  if (reader) {
8190
8196
  if (reader instanceof ReadableStream) {
8191
8197
  reader = {
@@ -8194,7 +8200,7 @@
8194
8200
  }
8195
8201
  await initStream(reader);
8196
8202
  if (reader.size === UNDEFINED_VALUE) {
8197
- options.dataDescriptor = true;
8203
+ dataDescriptor = true;
8198
8204
  if (zip64 || zip64 === UNDEFINED_VALUE) {
8199
8205
  zip64 = true;
8200
8206
  maximumCompressedSize = MAX_32_BITS;
@@ -8204,10 +8210,11 @@
8204
8210
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
8205
8211
  }
8206
8212
  }
8207
- const { diskOffset } = zipWriter.writer;
8213
+ const { diskOffset, diskNumber, maxSize } = zipWriter.writer;
8208
8214
  if (zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS ||
8209
8215
  uncompressedSize >= MAX_32_BITS ||
8210
- maximumCompressedSize >= MAX_32_BITS) {
8216
+ maximumCompressedSize >= MAX_32_BITS ||
8217
+ diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) >= MAX_16_BITS) {
8211
8218
  if (zip64 === false || !keepOrder) {
8212
8219
  throw new Error(ERR_UNSUPPORTED_FORMAT);
8213
8220
  } else {
@@ -8215,19 +8222,6 @@
8215
8222
  }
8216
8223
  }
8217
8224
  zip64 = zip64 || false;
8218
- const level = getOptionValue(zipWriter, options, "level");
8219
- const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
8220
- const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
8221
- let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor");
8222
- let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
8223
- const signal = getOptionValue(zipWriter, options, "signal");
8224
- const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
8225
- if (dataDescriptor === UNDEFINED_VALUE) {
8226
- dataDescriptor = true;
8227
- }
8228
- if (dataDescriptor && dataDescriptorSignature === UNDEFINED_VALUE) {
8229
- dataDescriptorSignature = false;
8230
- }
8231
8225
  options = Object.assign({}, options, {
8232
8226
  rawFilename,
8233
8227
  rawComment,
@@ -8300,8 +8294,7 @@
8300
8294
  await initStream(writer);
8301
8295
  } else {
8302
8296
  fileWriter = writer;
8303
- zipWriter.lockWriter = Promise.resolve();
8304
- releaseLockWriter = () => delete zipWriter.lockWriter;
8297
+ initLockWriter();
8305
8298
  }
8306
8299
  await initStream(fileWriter);
8307
8300
  const { writable, diskNumber } = writer;
@@ -8330,7 +8323,7 @@
8330
8323
  await requestLockWriter();
8331
8324
  writingBufferedEntryData = true;
8332
8325
  if (!dataDescriptor) {
8333
- blob = await setMissingInfo(fileEntry, blob, writable, options);
8326
+ blob = await writeMissingHeaderInfo(fileEntry, blob, writable, options);
8334
8327
  }
8335
8328
  fileEntry.diskNumberStart = writer.diskNumber;
8336
8329
  diskOffset = writer.diskOffset;
@@ -8340,7 +8333,7 @@
8340
8333
  }
8341
8334
  fileEntry.offset = zipWriter.offset - diskOffset;
8342
8335
  if (fileEntry.zip64) {
8343
- setZip64Info(fileEntry);
8336
+ setZip64OffsetInfo(fileEntry);
8344
8337
  } else if (fileEntry.offset >= MAX_32_BITS) {
8345
8338
  throw new Error(ERR_UNSUPPORTED_FORMAT);
8346
8339
  }
@@ -8373,6 +8366,11 @@
8373
8366
  fileEntry.lock = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
8374
8367
  }
8375
8368
 
8369
+ function initLockWriter() {
8370
+ zipWriter.lockWriter = Promise.resolve();
8371
+ releaseLockWriter = () => delete zipWriter.lockWriter;
8372
+ }
8373
+
8376
8374
  async function requestLockWriter() {
8377
8375
  const { lockWriter } = zipWriter;
8378
8376
  if (lockWriter) {
@@ -8531,6 +8529,7 @@
8531
8529
  } = options;
8532
8530
  const compressed = level !== 0 && !directory;
8533
8531
  const encrypted = Boolean(password && getLength(password));
8532
+ let version = options.version;
8534
8533
  let rawExtraFieldAES;
8535
8534
  if (encrypted && !zipCrypto) {
8536
8535
  rawExtraFieldAES = new Uint8Array(getLength(EXTRAFIELD_DATA_AES) + 2);
@@ -8582,7 +8581,6 @@
8582
8581
  if (compressed) {
8583
8582
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
8584
8583
  }
8585
- let version = options.version || VERSION_DEFLATE;
8586
8584
  if (zip64) {
8587
8585
  version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
8588
8586
  }
@@ -8716,7 +8714,7 @@
8716
8714
  }
8717
8715
  }
8718
8716
 
8719
- async function setMissingInfo(fileEntry, entryData, writable, { zipCrypto }) {
8717
+ async function writeMissingHeaderInfo(fileEntry, entryData, writable, { zipCrypto }) {
8720
8718
  const arrayBuffer = await sliceAsArrayBuffer(entryData, 0, 26);
8721
8719
  const arrayBufferView = new DataView(arrayBuffer);
8722
8720
  if (!fileEntry.encrypted || zipCrypto) {
@@ -8733,7 +8731,7 @@
8733
8731
  return entryData.slice(arrayBuffer.byteLength);
8734
8732
  }
8735
8733
 
8736
- function setZip64Info(fileEntry) {
8734
+ function setZip64OffsetInfo(fileEntry) {
8737
8735
  const { rawExtraFieldZip64, offset, diskNumberStart } = fileEntry;
8738
8736
  const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
8739
8737
  setBigUint64(rawExtraFieldZip64View, 20, BigInt(offset));
@@ -8742,10 +8740,10 @@
8742
8740
 
8743
8741
  async function closeFile(zipWriter, comment, options) {
8744
8742
  const { files, writer } = zipWriter;
8745
- let offset = 0;
8746
- let directoryDataLength = 0;
8747
8743
  const { diskOffset, writable } = writer;
8748
8744
  let { diskNumber } = writer;
8745
+ let offset = 0;
8746
+ let directoryDataLength = 0;
8749
8747
  let directoryOffset = zipWriter.offset - diskOffset;
8750
8748
  let filesLength = files.size;
8751
8749
  for (const [, {
@@ -8767,14 +8765,6 @@
8767
8765
  rawExtraFieldNTFS,
8768
8766
  rawExtraField);
8769
8767
  }
8770
- let zip64 = options.zip64 || zipWriter.options.zip64 || false;
8771
- if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) {
8772
- if (options.zip64 === false || zipWriter.options.zip64 === false) {
8773
- throw new Error(ERR_UNSUPPORTED_FORMAT);
8774
- } else {
8775
- zip64 = true;
8776
- }
8777
- }
8778
8768
  const directoryArray = new Uint8Array(directoryDataLength);
8779
8769
  const directoryView = getDataView(directoryArray);
8780
8770
  for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
@@ -8840,13 +8830,21 @@
8840
8830
  }
8841
8831
  await initStream(writer);
8842
8832
  await writeData(writable, directoryArray);
8843
- const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8844
- const endOfdirectoryView = getDataView(endOfdirectoryArray);
8845
8833
  let lastDiskNumber = writer.diskNumber;
8846
8834
  const { availableSize } = writer;
8847
- if (availableSize < getLength(endOfdirectoryArray)) {
8835
+ if (availableSize < END_OF_CENTRAL_DIR_LENGTH) {
8848
8836
  lastDiskNumber++;
8849
8837
  }
8838
+ let zip64 = getOptionValue(zipWriter, options, "zip64");
8839
+ if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
8840
+ if (zip64 === false) {
8841
+ throw new Error(ERR_UNSUPPORTED_FORMAT);
8842
+ } else {
8843
+ zip64 = true;
8844
+ }
8845
+ }
8846
+ const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8847
+ const endOfdirectoryView = getDataView(endOfdirectoryArray);
8850
8848
  offset = 0;
8851
8849
  if (zip64) {
8852
8850
  setUint32(endOfdirectoryView, 0, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
@@ -8911,8 +8909,9 @@
8911
8909
  }
8912
8910
  }
8913
8911
 
8914
- function getOptionValue(zipWriter, options, name) {
8915
- return options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
8912
+ function getOptionValue(zipWriter, options, name, defaultValue) {
8913
+ const result = options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
8914
+ return result === UNDEFINED_VALUE ? defaultValue : result;
8916
8915
  }
8917
8916
 
8918
8917
  function getMaximumCompressedSize(uncompressedSize) {
@@ -9017,6 +9016,8 @@
9017
9016
  exports.HttpRangeReader = HttpRangeReader;
9018
9017
  exports.HttpReader = HttpReader;
9019
9018
  exports.Reader = Reader;
9019
+ exports.SplitDataReader = SplitDataReader;
9020
+ exports.SplitDataWriter = SplitDataWriter;
9020
9021
  exports.SplitZipReader = SplitZipReader;
9021
9022
  exports.SplitZipWriter = SplitZipWriter;
9022
9023
  exports.TextReader = TextReader;