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