@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.
@@ -8107,7 +8107,7 @@
8107
8107
  }
8108
8108
  }
8109
8109
 
8110
- class SplitZipReader extends Reader {
8110
+ class SplitDataReader extends Reader {
8111
8111
 
8112
8112
  constructor(readers) {
8113
8113
  super();
@@ -8153,7 +8153,7 @@
8153
8153
  }
8154
8154
  }
8155
8155
 
8156
- class SplitZipWriter extends Stream {
8156
+ class SplitDataWriter extends Stream {
8157
8157
 
8158
8158
  constructor(writerGenerator, maxSize = 4294967296) {
8159
8159
  super();
@@ -8162,6 +8162,7 @@
8162
8162
  diskNumber: 0,
8163
8163
  diskOffset: 0,
8164
8164
  size: 0,
8165
+ maxSize,
8165
8166
  availableSize: maxSize
8166
8167
  });
8167
8168
  let diskSourceWriter, diskWritable, diskWriter;
@@ -8174,6 +8175,7 @@
8174
8175
  } else {
8175
8176
  diskSourceWriter = value;
8176
8177
  diskSourceWriter.size = 0;
8178
+ await initStream(diskSourceWriter);
8177
8179
  diskWritable = value.writable;
8178
8180
  diskWriter = diskWritable.getWriter();
8179
8181
  }
@@ -8234,6 +8236,9 @@
8234
8236
  return reader.readUint8Array(offset, size, diskNumber);
8235
8237
  }
8236
8238
 
8239
+ const SplitZipReader = SplitDataReader;
8240
+ const SplitZipWriter = SplitDataWriter;
8241
+
8237
8242
  /*
8238
8243
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
8239
8244
 
@@ -8460,7 +8465,7 @@
8460
8465
  await initStream(reader);
8461
8466
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
8462
8467
  if (Array.isArray(reader)) {
8463
- reader = new SplitZipReader(reader);
8468
+ reader = new SplitDataReader(reader);
8464
8469
  } else {
8465
8470
  reader = new BlobReader(await new Response(reader.readable).blob());
8466
8471
  }
@@ -9038,7 +9043,7 @@
9038
9043
 
9039
9044
  constructor(writer, options = {}) {
9040
9045
  if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE$1) {
9041
- writer = new SplitZipWriter(writer);
9046
+ writer = new SplitDataWriter(writer);
9042
9047
  }
9043
9048
  if (writer instanceof WritableStream) {
9044
9049
  writer = { writable: writer };
@@ -9046,12 +9051,13 @@
9046
9051
  if (writer.writable.size === UNDEFINED_VALUE) {
9047
9052
  writer.writable.size = 0;
9048
9053
  }
9049
- const splitZipFile = writer instanceof SplitZipWriter;
9054
+ const splitZipFile = writer instanceof SplitDataWriter;
9050
9055
  if (!splitZipFile) {
9051
9056
  Object.assign(writer, {
9052
9057
  diskNumber: 0,
9053
9058
  diskOffset: 0,
9054
- availableSize: Infinity
9059
+ availableSize: Infinity,
9060
+ maxSize: Infinity
9055
9061
  });
9056
9062
  }
9057
9063
  Object.assign(this, {
@@ -9103,13 +9109,15 @@
9103
9109
  }
9104
9110
 
9105
9111
  async close(comment = new Uint8Array(), options = {}) {
9112
+ const zipWriter = this;
9106
9113
  const { pendingAddFileCalls, writer } = this;
9107
9114
  const { writable } = writer;
9108
9115
  while (pendingAddFileCalls.size) {
9109
9116
  await Promise.all(Array.from(pendingAddFileCalls));
9110
9117
  }
9111
9118
  await closeFile(this, comment, options);
9112
- if (!writer.preventClose && !options.preventClose) {
9119
+ const preventClose = getOptionValue(zipWriter, options, "preventClose");
9120
+ if (!preventClose) {
9113
9121
  await writable.close();
9114
9122
  }
9115
9123
  return writer.getData ? writer.getData() : writable;
@@ -9132,20 +9140,33 @@
9132
9140
  if (getLength(rawComment) > MAX_16_BITS) {
9133
9141
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
9134
9142
  }
9135
- const version = zipWriter.options.version || options.version || 0;
9143
+ const version = getOptionValue(zipWriter, options, "version", VERSION_DEFLATE);
9136
9144
  if (version > MAX_16_BITS) {
9137
9145
  throw new Error(ERR_INVALID_VERSION);
9138
9146
  }
9139
- const versionMadeBy = zipWriter.options.versionMadeBy || options.versionMadeBy || 20;
9147
+ const versionMadeBy = getOptionValue(zipWriter, options, "versionMadeBy", 20);
9140
9148
  if (versionMadeBy > MAX_16_BITS) {
9141
9149
  throw new Error(ERR_INVALID_VERSION);
9142
9150
  }
9143
- const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE) || new Date();
9151
+ const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
9144
9152
  const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
9145
9153
  const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
9154
+ const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
9155
+ const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
9156
+ const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
9146
9157
  const password = getOptionValue(zipWriter, options, "password");
9147
- const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
9158
+ const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
9148
9159
  const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
9160
+ const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
9161
+ const keepOrder = getOptionValue(zipWriter, options, "keepOrder", true);
9162
+ const level = getOptionValue(zipWriter, options, "level");
9163
+ const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
9164
+ const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
9165
+ const dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature", false);
9166
+ const signal = getOptionValue(zipWriter, options, "signal");
9167
+ const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
9168
+ let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
9169
+ let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
9149
9170
  if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
9150
9171
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
9151
9172
  }
@@ -9169,24 +9190,9 @@
9169
9190
  offset += 4 + getLength(data);
9170
9191
  });
9171
9192
  }
9172
- let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
9173
- if (extendedTimestamp === UNDEFINED_VALUE) {
9174
- extendedTimestamp = true;
9175
- }
9176
9193
  let maximumCompressedSize = 0;
9177
9194
  let maximumEntrySize = 0;
9178
- let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
9179
- if (keepOrder === UNDEFINED_VALUE) {
9180
- keepOrder = true;
9181
- }
9182
9195
  let uncompressedSize = 0;
9183
- let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
9184
- if (msDosCompatible === UNDEFINED_VALUE) {
9185
- msDosCompatible = true;
9186
- }
9187
- const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE) || 0;
9188
- const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE) || 0;
9189
- let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
9190
9196
  if (reader) {
9191
9197
  if (reader instanceof ReadableStream) {
9192
9198
  reader = {
@@ -9195,7 +9201,7 @@
9195
9201
  }
9196
9202
  await initStream(reader);
9197
9203
  if (reader.size === UNDEFINED_VALUE) {
9198
- options.dataDescriptor = true;
9204
+ dataDescriptor = true;
9199
9205
  if (zip64 || zip64 === UNDEFINED_VALUE) {
9200
9206
  zip64 = true;
9201
9207
  maximumCompressedSize = MAX_32_BITS;
@@ -9205,10 +9211,11 @@
9205
9211
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
9206
9212
  }
9207
9213
  }
9208
- const { diskOffset } = zipWriter.writer;
9214
+ const { diskOffset, diskNumber, maxSize } = zipWriter.writer;
9209
9215
  if (zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS ||
9210
9216
  uncompressedSize >= MAX_32_BITS ||
9211
- maximumCompressedSize >= MAX_32_BITS) {
9217
+ maximumCompressedSize >= MAX_32_BITS ||
9218
+ diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) >= MAX_16_BITS) {
9212
9219
  if (zip64 === false || !keepOrder) {
9213
9220
  throw new Error(ERR_UNSUPPORTED_FORMAT);
9214
9221
  } else {
@@ -9216,19 +9223,6 @@
9216
9223
  }
9217
9224
  }
9218
9225
  zip64 = zip64 || false;
9219
- const level = getOptionValue(zipWriter, options, "level");
9220
- const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
9221
- const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
9222
- let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor");
9223
- let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
9224
- const signal = getOptionValue(zipWriter, options, "signal");
9225
- const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
9226
- if (dataDescriptor === UNDEFINED_VALUE) {
9227
- dataDescriptor = true;
9228
- }
9229
- if (dataDescriptor && dataDescriptorSignature === UNDEFINED_VALUE) {
9230
- dataDescriptorSignature = false;
9231
- }
9232
9226
  options = Object.assign({}, options, {
9233
9227
  rawFilename,
9234
9228
  rawComment,
@@ -9301,8 +9295,7 @@
9301
9295
  await initStream(writer);
9302
9296
  } else {
9303
9297
  fileWriter = writer;
9304
- zipWriter.lockWriter = Promise.resolve();
9305
- releaseLockWriter = () => delete zipWriter.lockWriter;
9298
+ initLockWriter();
9306
9299
  }
9307
9300
  await initStream(fileWriter);
9308
9301
  const { writable, diskNumber } = writer;
@@ -9331,7 +9324,7 @@
9331
9324
  await requestLockWriter();
9332
9325
  writingBufferedEntryData = true;
9333
9326
  if (!dataDescriptor) {
9334
- blob = await setMissingInfo(fileEntry, blob, writable, options);
9327
+ blob = await writeMissingHeaderInfo(fileEntry, blob, writable, options);
9335
9328
  }
9336
9329
  fileEntry.diskNumberStart = writer.diskNumber;
9337
9330
  diskOffset = writer.diskOffset;
@@ -9341,7 +9334,7 @@
9341
9334
  }
9342
9335
  fileEntry.offset = zipWriter.offset - diskOffset;
9343
9336
  if (fileEntry.zip64) {
9344
- setZip64Info(fileEntry);
9337
+ setZip64OffsetInfo(fileEntry);
9345
9338
  } else if (fileEntry.offset >= MAX_32_BITS) {
9346
9339
  throw new Error(ERR_UNSUPPORTED_FORMAT);
9347
9340
  }
@@ -9374,6 +9367,11 @@
9374
9367
  fileEntry.lock = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
9375
9368
  }
9376
9369
 
9370
+ function initLockWriter() {
9371
+ zipWriter.lockWriter = Promise.resolve();
9372
+ releaseLockWriter = () => delete zipWriter.lockWriter;
9373
+ }
9374
+
9377
9375
  async function requestLockWriter() {
9378
9376
  const { lockWriter } = zipWriter;
9379
9377
  if (lockWriter) {
@@ -9532,6 +9530,7 @@
9532
9530
  } = options;
9533
9531
  const compressed = level !== 0 && !directory;
9534
9532
  const encrypted = Boolean(password && getLength(password));
9533
+ let version = options.version;
9535
9534
  let rawExtraFieldAES;
9536
9535
  if (encrypted && !zipCrypto) {
9537
9536
  rawExtraFieldAES = new Uint8Array(getLength(EXTRAFIELD_DATA_AES) + 2);
@@ -9583,7 +9582,6 @@
9583
9582
  if (compressed) {
9584
9583
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
9585
9584
  }
9586
- let version = options.version || VERSION_DEFLATE;
9587
9585
  if (zip64) {
9588
9586
  version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
9589
9587
  }
@@ -9717,7 +9715,7 @@
9717
9715
  }
9718
9716
  }
9719
9717
 
9720
- async function setMissingInfo(fileEntry, entryData, writable, { zipCrypto }) {
9718
+ async function writeMissingHeaderInfo(fileEntry, entryData, writable, { zipCrypto }) {
9721
9719
  const arrayBuffer = await sliceAsArrayBuffer(entryData, 0, 26);
9722
9720
  const arrayBufferView = new DataView(arrayBuffer);
9723
9721
  if (!fileEntry.encrypted || zipCrypto) {
@@ -9734,7 +9732,7 @@
9734
9732
  return entryData.slice(arrayBuffer.byteLength);
9735
9733
  }
9736
9734
 
9737
- function setZip64Info(fileEntry) {
9735
+ function setZip64OffsetInfo(fileEntry) {
9738
9736
  const { rawExtraFieldZip64, offset, diskNumberStart } = fileEntry;
9739
9737
  const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
9740
9738
  setBigUint64(rawExtraFieldZip64View, 20, BigInt(offset));
@@ -9743,10 +9741,10 @@
9743
9741
 
9744
9742
  async function closeFile(zipWriter, comment, options) {
9745
9743
  const { files, writer } = zipWriter;
9746
- let offset = 0;
9747
- let directoryDataLength = 0;
9748
9744
  const { diskOffset, writable } = writer;
9749
9745
  let { diskNumber } = writer;
9746
+ let offset = 0;
9747
+ let directoryDataLength = 0;
9750
9748
  let directoryOffset = zipWriter.offset - diskOffset;
9751
9749
  let filesLength = files.size;
9752
9750
  for (const [, {
@@ -9768,14 +9766,6 @@
9768
9766
  rawExtraFieldNTFS,
9769
9767
  rawExtraField);
9770
9768
  }
9771
- let zip64 = options.zip64 || zipWriter.options.zip64 || false;
9772
- if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) {
9773
- if (options.zip64 === false || zipWriter.options.zip64 === false) {
9774
- throw new Error(ERR_UNSUPPORTED_FORMAT);
9775
- } else {
9776
- zip64 = true;
9777
- }
9778
- }
9779
9769
  const directoryArray = new Uint8Array(directoryDataLength);
9780
9770
  const directoryView = getDataView(directoryArray);
9781
9771
  for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
@@ -9841,13 +9831,21 @@
9841
9831
  }
9842
9832
  await initStream(writer);
9843
9833
  await writeData(writable, directoryArray);
9844
- const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
9845
- const endOfdirectoryView = getDataView(endOfdirectoryArray);
9846
9834
  let lastDiskNumber = writer.diskNumber;
9847
9835
  const { availableSize } = writer;
9848
- if (availableSize < getLength(endOfdirectoryArray)) {
9836
+ if (availableSize < END_OF_CENTRAL_DIR_LENGTH) {
9849
9837
  lastDiskNumber++;
9850
9838
  }
9839
+ let zip64 = getOptionValue(zipWriter, options, "zip64");
9840
+ if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
9841
+ if (zip64 === false) {
9842
+ throw new Error(ERR_UNSUPPORTED_FORMAT);
9843
+ } else {
9844
+ zip64 = true;
9845
+ }
9846
+ }
9847
+ const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
9848
+ const endOfdirectoryView = getDataView(endOfdirectoryArray);
9851
9849
  offset = 0;
9852
9850
  if (zip64) {
9853
9851
  setUint32(endOfdirectoryView, 0, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
@@ -9912,8 +9910,9 @@
9912
9910
  }
9913
9911
  }
9914
9912
 
9915
- function getOptionValue(zipWriter, options, name) {
9916
- return options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
9913
+ function getOptionValue(zipWriter, options, name, defaultValue) {
9914
+ const result = options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
9915
+ return result === UNDEFINED_VALUE ? defaultValue : result;
9917
9916
  }
9918
9917
 
9919
9918
  function getMaximumCompressedSize(uncompressedSize) {
@@ -10599,7 +10598,7 @@
10599
10598
  configure({ baseURL });
10600
10599
  e(configure);
10601
10600
 
10602
- /// <reference types="./index" />
10601
+ /// <reference types="./index.d.ts" />
10603
10602
 
10604
10603
  configure({ Deflate: ZipDeflate, Inflate: ZipInflate });
10605
10604
 
@@ -10634,6 +10633,8 @@
10634
10633
  exports.HttpRangeReader = HttpRangeReader;
10635
10634
  exports.HttpReader = HttpReader;
10636
10635
  exports.Reader = Reader;
10636
+ exports.SplitDataReader = SplitDataReader;
10637
+ exports.SplitDataWriter = SplitDataWriter;
10637
10638
  exports.SplitZipReader = SplitZipReader;
10638
10639
  exports.SplitZipWriter = SplitZipWriter;
10639
10640
  exports.TextReader = TextReader;