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