@zip.js/zip.js 2.6.20 → 2.6.23

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
@@ -6687,7 +6687,7 @@
6687
6687
  const writer = this;
6688
6688
  writer.contentType = contentType;
6689
6689
  writer.transformStream = new TransformStream();
6690
- Object.defineProperty(this, "writable", {
6690
+ Object.defineProperty(writer, "writable", {
6691
6691
  get() {
6692
6692
  return writer.transformStream.writable;
6693
6693
  }
@@ -6701,7 +6701,11 @@
6701
6701
  transformStream,
6702
6702
  contentType
6703
6703
  } = writer;
6704
- writer.blob = new Response(transformStream.readable).blob({ type: contentType });
6704
+ const headers = [];
6705
+ if (contentType) {
6706
+ headers.push(["content-type", contentType]);
6707
+ }
6708
+ writer.blob = new Response(transformStream.readable, { headers }).blob();
6705
6709
  }
6706
6710
 
6707
6711
  getData() {
@@ -7773,7 +7777,7 @@
7773
7777
  files: new Map(),
7774
7778
  filenames: new Set(),
7775
7779
  offset: writer.writable.size,
7776
- pendingCompressedSize: 0,
7780
+ pendingEntriesSize: 0,
7777
7781
  pendingAddFileCalls: new Set()
7778
7782
  });
7779
7783
  }
@@ -7885,6 +7889,7 @@
7885
7889
  extendedTimestamp = true;
7886
7890
  }
7887
7891
  let maximumCompressedSize = 0;
7892
+ let maximumEntrySize = 0;
7888
7893
  let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
7889
7894
  if (keepOrder === undefined) {
7890
7895
  keepOrder = true;
@@ -7906,7 +7911,7 @@
7906
7911
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
7907
7912
  }
7908
7913
  let zip64 = options.zip64 || zipWriter.options.zip64 || false;
7909
- if (zipWriter.offset + zipWriter.pendingCompressedSize >= MAX_32_BITS ||
7914
+ if (zipWriter.offset + zipWriter.pendingEntriesSize >= MAX_32_BITS ||
7910
7915
  uncompressedSize >= MAX_32_BITS ||
7911
7916
  maximumCompressedSize >= MAX_32_BITS) {
7912
7917
  if (options.zip64 === false || zipWriter.options.zip64 === false || !keepOrder) {
@@ -7915,8 +7920,6 @@
7915
7920
  zip64 = true;
7916
7921
  }
7917
7922
  }
7918
- zipWriter.pendingCompressedSize += maximumCompressedSize;
7919
- await Promise.resolve();
7920
7923
  const level = getOptionValue(zipWriter, options, "level");
7921
7924
  const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
7922
7925
  const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
@@ -7930,7 +7933,7 @@
7930
7933
  if (dataDescriptor && dataDescriptorSignature === undefined) {
7931
7934
  dataDescriptorSignature = false;
7932
7935
  }
7933
- const fileEntry = await getFileEntry(zipWriter, name, reader, Object.assign({}, options, {
7936
+ options = Object.assign({}, options, {
7934
7937
  rawFilename,
7935
7938
  rawComment,
7936
7939
  version,
@@ -7955,15 +7958,20 @@
7955
7958
  internalFileAttribute,
7956
7959
  externalFileAttribute,
7957
7960
  useCompressionStream
7958
- }));
7959
- if (maximumCompressedSize) {
7960
- zipWriter.pendingCompressedSize -= maximumCompressedSize;
7961
+ });
7962
+ const headerInfo = getHeaderInfo(options);
7963
+ const dataDescriptorInfo = getDataDescriptorInfo(options);
7964
+ maximumEntrySize = headerInfo.localHeaderArray.length + maximumCompressedSize + dataDescriptorInfo.dataDescriptorArray.length;
7965
+ zipWriter.pendingEntriesSize += maximumEntrySize;
7966
+ const fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo }, options);
7967
+ if (maximumEntrySize) {
7968
+ zipWriter.pendingEntriesSize -= maximumEntrySize;
7961
7969
  }
7962
7970
  Object.assign(fileEntry, { name, comment, extraField });
7963
7971
  return new Entry(fileEntry);
7964
7972
  }
7965
7973
 
7966
- async function getFileEntry(zipWriter, name, reader, options) {
7974
+ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
7967
7975
  const {
7968
7976
  files,
7969
7977
  writer
@@ -8002,7 +8010,8 @@
8002
8010
  if (!bufferedWrite) {
8003
8011
  await lockPreviousFileEntry;
8004
8012
  }
8005
- fileEntry = await createFileEntry(reader, fileWriter, fileEntry, zipWriter.config, options);
8013
+ fileEntry.writingData = true;
8014
+ fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
8006
8015
  files.set(name, fileEntry);
8007
8016
  fileEntry.filename = name;
8008
8017
  if (bufferedWrite) {
@@ -8078,7 +8087,25 @@
8078
8087
  }
8079
8088
  }
8080
8089
 
8081
- async function createFileEntry(reader, writer, pendingFileEntry, config, options) {
8090
+ async function createFileEntry(reader, writer, pendingFileEntry, entryInfo, config, options) {
8091
+ const {
8092
+ headerInfo,
8093
+ dataDescriptorInfo
8094
+ } = entryInfo;
8095
+ const {
8096
+ localHeaderArray,
8097
+ headerArray,
8098
+ lastModDate,
8099
+ rawLastModDate,
8100
+ encrypted,
8101
+ compressed,
8102
+ version,
8103
+ compressionMethod,
8104
+ rawExtraFieldExtendedTimestamp,
8105
+ rawExtraFieldNTFS,
8106
+ rawExtraFieldAES
8107
+ } = headerInfo;
8108
+ const { dataDescriptorArray } = dataDescriptorInfo;
8082
8109
  const {
8083
8110
  rawFilename,
8084
8111
  lastAccessDate,
@@ -8088,9 +8115,7 @@
8088
8115
  zip64,
8089
8116
  zipCrypto,
8090
8117
  dataDescriptor,
8091
- dataDescriptorSignature,
8092
8118
  directory,
8093
- version,
8094
8119
  versionMadeBy,
8095
8120
  rawComment,
8096
8121
  rawExtraField,
@@ -8106,8 +8131,108 @@
8106
8131
  externalFileAttribute,
8107
8132
  useCompressionStream
8108
8133
  } = options;
8109
- const encrypted = Boolean(password && password.length);
8134
+ const fileEntry = {
8135
+ lock: pendingFileEntry.lock,
8136
+ versionMadeBy,
8137
+ zip64,
8138
+ directory: Boolean(directory),
8139
+ filenameUTF8: true,
8140
+ rawFilename,
8141
+ commentUTF8: true,
8142
+ rawComment,
8143
+ rawExtraFieldExtendedTimestamp,
8144
+ rawExtraFieldNTFS,
8145
+ rawExtraFieldAES,
8146
+ rawExtraField,
8147
+ extendedTimestamp,
8148
+ msDosCompatible,
8149
+ internalFileAttribute,
8150
+ externalFileAttribute
8151
+ };
8152
+ let uncompressedSize = 0;
8153
+ let signature;
8154
+ let compressedSize = 0;
8155
+ const { writable } = writer;
8156
+ if (reader) {
8157
+ reader.chunkSize = getChunkSize(config);
8158
+ await writeData(writable, localHeaderArray);
8159
+ const size = () => reader.size;
8160
+ const readable = reader.readable;
8161
+ readable.size = size;
8162
+ const workerOptions = {
8163
+ options: {
8164
+ codecType: CODEC_DEFLATE,
8165
+ level,
8166
+ password,
8167
+ encryptionStrength,
8168
+ zipCrypto: encrypted && zipCrypto,
8169
+ passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
8170
+ signed: true,
8171
+ compressed,
8172
+ encrypted,
8173
+ useWebWorkers,
8174
+ useCompressionStream
8175
+ },
8176
+ config,
8177
+ streamOptions: { signal, size, onstart, onprogress, onend },
8178
+ codecConstructor: config.Deflate
8179
+ };
8180
+ const previousSize = writable.size;
8181
+ signature = (await runWorker({ readable, writable }, workerOptions)).signature;
8182
+ uncompressedSize = reader.size = readable.size();
8183
+ compressedSize = writable.size - previousSize;
8184
+ } else {
8185
+ await writeData(writable, localHeaderArray);
8186
+ }
8187
+ const rawExtraFieldZip64 = zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array();
8188
+ if (reader) {
8189
+ setEntryInfo({
8190
+ signature,
8191
+ rawExtraFieldZip64,
8192
+ compressedSize,
8193
+ uncompressedSize,
8194
+ headerInfo,
8195
+ dataDescriptorInfo
8196
+ }, options);
8197
+ }
8198
+ if (dataDescriptor) {
8199
+ await writeData(writable, dataDescriptorArray);
8200
+ }
8201
+ Object.assign(fileEntry, {
8202
+ compressedSize,
8203
+ lastModDate,
8204
+ rawLastModDate,
8205
+ creationDate,
8206
+ lastAccessDate,
8207
+ encrypted,
8208
+ length: localHeaderArray.length + compressedSize + dataDescriptorArray.length,
8209
+ compressionMethod,
8210
+ version,
8211
+ headerArray,
8212
+ signature,
8213
+ rawExtraFieldZip64
8214
+ });
8215
+ return fileEntry;
8216
+ }
8217
+
8218
+ function getHeaderInfo(options) {
8219
+ const {
8220
+ rawFilename,
8221
+ lastAccessDate,
8222
+ creationDate,
8223
+ password,
8224
+ level,
8225
+ zip64,
8226
+ zipCrypto,
8227
+ dataDescriptor,
8228
+ directory,
8229
+ rawExtraField,
8230
+ encryptionStrength,
8231
+ extendedTimestamp,
8232
+ } = options;
8233
+ let version = options.version || VERSION_DEFLATE;
8110
8234
  const compressed = level !== 0 && !directory;
8235
+ const encrypted = Boolean(password && password.length);
8111
8236
  let rawExtraFieldAES;
8112
8237
  if (encrypted && !zipCrypto) {
8113
8238
  rawExtraFieldAES = new Uint8Array(EXTRAFIELD_DATA_AES.length + 2);
@@ -8151,27 +8276,6 @@
8151
8276
  } else {
8152
8277
  rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array();
8153
8278
  }
8154
- const fileEntry = {
8155
- lock: pendingFileEntry.lock,
8156
- version: version || VERSION_DEFLATE,
8157
- versionMadeBy,
8158
- zip64,
8159
- directory: Boolean(directory),
8160
- filenameUTF8: true,
8161
- rawFilename,
8162
- commentUTF8: true,
8163
- rawComment,
8164
- rawExtraFieldZip64: zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array(),
8165
- rawExtraFieldExtendedTimestamp,
8166
- rawExtraFieldNTFS,
8167
- rawExtraFieldAES,
8168
- rawExtraField,
8169
- extendedTimestamp,
8170
- msDosCompatible,
8171
- internalFileAttribute,
8172
- externalFileAttribute
8173
- };
8174
- let uncompressedSize = 0;
8175
8279
  let bitFlag = BITFLAG_LANG_ENCODING_FLAG;
8176
8280
  if (dataDescriptor) {
8177
8281
  bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
@@ -8181,22 +8285,21 @@
8181
8285
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
8182
8286
  }
8183
8287
  if (zip64) {
8184
- fileEntry.version = fileEntry.version > VERSION_ZIP64 ? fileEntry.version : VERSION_ZIP64;
8288
+ version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
8185
8289
  }
8186
8290
  if (encrypted) {
8187
8291
  bitFlag = bitFlag | BITFLAG_ENCRYPTED;
8188
8292
  if (!zipCrypto) {
8189
- fileEntry.version = fileEntry.version > VERSION_AES ? fileEntry.version : VERSION_AES;
8293
+ version = version > VERSION_AES ? version : VERSION_AES;
8190
8294
  compressionMethod = COMPRESSION_METHOD_AES;
8191
8295
  if (compressed) {
8192
- fileEntry.rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
8296
+ rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
8193
8297
  }
8194
8298
  }
8195
8299
  }
8196
- fileEntry.compressionMethod = compressionMethod;
8197
- const headerArray = fileEntry.headerArray = new Uint8Array(26);
8300
+ const headerArray = new Uint8Array(26);
8198
8301
  const headerView = getDataView(headerArray);
8199
- setUint16(headerView, 0, fileEntry.version);
8302
+ setUint16(headerView, 0, version);
8200
8303
  setUint16(headerView, 2, bitFlag);
8201
8304
  setUint16(headerView, 4, compressionMethod);
8202
8305
  const dateArray = new Uint32Array(1);
@@ -8225,41 +8328,28 @@
8225
8328
  arraySet(localHeaderArray, rawExtraFieldExtendedTimestamp, 30 + rawFilename.length + rawExtraFieldAES.length);
8226
8329
  arraySet(localHeaderArray, rawExtraFieldNTFS, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length);
8227
8330
  arraySet(localHeaderArray, rawExtraField, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length);
8228
- let result;
8229
- let compressedSize = 0;
8230
- const { writable } = writer;
8231
- fileEntry.writingData = pendingFileEntry.writingData = true;
8232
- if (reader) {
8233
- reader.chunkSize = getChunkSize(config);
8234
- await writeData(writable, localHeaderArray);
8235
- const size = () => reader.size;
8236
- const readable = reader.readable;
8237
- readable.size = size;
8238
- const workerOptions = {
8239
- options: {
8240
- codecType: CODEC_DEFLATE,
8241
- level,
8242
- password,
8243
- encryptionStrength,
8244
- zipCrypto: encrypted && zipCrypto,
8245
- passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
8246
- signed: true,
8247
- compressed,
8248
- encrypted,
8249
- useWebWorkers,
8250
- useCompressionStream
8251
- },
8252
- config,
8253
- streamOptions: { signal, size, onstart, onprogress, onend },
8254
- codecConstructor: config.Deflate
8255
- };
8256
- const previousSize = writable.size;
8257
- result = await runWorker({ readable, writable }, workerOptions);
8258
- uncompressedSize = reader.size = readable.size();
8259
- compressedSize = writable.size - previousSize;
8260
- } else {
8261
- await writeData(writable, localHeaderArray);
8262
- }
8331
+ return {
8332
+ localHeaderArray,
8333
+ headerArray,
8334
+ headerView,
8335
+ lastModDate,
8336
+ rawLastModDate,
8337
+ encrypted,
8338
+ compressed,
8339
+ version,
8340
+ compressionMethod,
8341
+ rawExtraFieldExtendedTimestamp,
8342
+ rawExtraFieldNTFS,
8343
+ rawExtraFieldAES
8344
+ };
8345
+ }
8346
+
8347
+ function getDataDescriptorInfo(options) {
8348
+ const {
8349
+ zip64,
8350
+ dataDescriptor,
8351
+ dataDescriptorSignature
8352
+ } = options;
8263
8353
  let dataDescriptorArray = new Uint8Array();
8264
8354
  let dataDescriptorView, dataDescriptorOffset = 0;
8265
8355
  if (dataDescriptor) {
@@ -8270,51 +8360,61 @@
8270
8360
  setUint32(dataDescriptorView, 0, DATA_DESCRIPTOR_RECORD_SIGNATURE);
8271
8361
  }
8272
8362
  }
8273
- if (reader) {
8274
- const { signature } = result;
8275
- if ((!encrypted || zipCrypto) && signature !== undefined) {
8276
- setUint32(headerView, 10, signature);
8277
- fileEntry.signature = signature;
8278
- if (dataDescriptor) {
8279
- setUint32(dataDescriptorView, dataDescriptorOffset, signature);
8280
- }
8281
- }
8282
- if (zip64) {
8283
- const rawExtraFieldZip64View = getDataView(fileEntry.rawExtraFieldZip64);
8284
- setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
8285
- setUint16(rawExtraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64);
8286
- setUint32(headerView, 14, MAX_32_BITS);
8287
- setBigUint64(rawExtraFieldZip64View, 12, BigInt(compressedSize));
8288
- setUint32(headerView, 18, MAX_32_BITS);
8289
- setBigUint64(rawExtraFieldZip64View, 4, BigInt(uncompressedSize));
8290
- if (dataDescriptor) {
8291
- setBigUint64(dataDescriptorView, dataDescriptorOffset + 4, BigInt(compressedSize));
8292
- setBigUint64(dataDescriptorView, dataDescriptorOffset + 12, BigInt(uncompressedSize));
8293
- }
8294
- } else {
8295
- setUint32(headerView, 14, compressedSize);
8296
- setUint32(headerView, 18, uncompressedSize);
8297
- if (dataDescriptor) {
8298
- setUint32(dataDescriptorView, dataDescriptorOffset + 4, compressedSize);
8299
- setUint32(dataDescriptorView, dataDescriptorOffset + 8, uncompressedSize);
8300
- }
8363
+ return {
8364
+ dataDescriptorArray,
8365
+ dataDescriptorView,
8366
+ dataDescriptorOffset
8367
+ };
8368
+ }
8369
+
8370
+ function setEntryInfo(entryInfo, options) {
8371
+ const {
8372
+ signature,
8373
+ rawExtraFieldZip64,
8374
+ compressedSize,
8375
+ uncompressedSize,
8376
+ headerInfo,
8377
+ dataDescriptorInfo
8378
+ } = entryInfo;
8379
+ const {
8380
+ headerView,
8381
+ encrypted
8382
+ } = headerInfo;
8383
+ const {
8384
+ dataDescriptorView,
8385
+ dataDescriptorOffset
8386
+ } = dataDescriptorInfo;
8387
+ const {
8388
+ zip64,
8389
+ zipCrypto,
8390
+ dataDescriptor
8391
+ } = options;
8392
+ if ((!encrypted || zipCrypto) && signature !== undefined) {
8393
+ setUint32(headerView, 10, signature);
8394
+ if (dataDescriptor) {
8395
+ setUint32(dataDescriptorView, dataDescriptorOffset, signature);
8301
8396
  }
8302
8397
  }
8303
- if (dataDescriptor) {
8304
- await writeData(writable, dataDescriptorArray);
8398
+ if (zip64) {
8399
+ const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
8400
+ setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
8401
+ setUint16(rawExtraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64);
8402
+ setUint32(headerView, 14, MAX_32_BITS);
8403
+ setBigUint64(rawExtraFieldZip64View, 12, BigInt(compressedSize));
8404
+ setUint32(headerView, 18, MAX_32_BITS);
8405
+ setBigUint64(rawExtraFieldZip64View, 4, BigInt(uncompressedSize));
8406
+ if (dataDescriptor) {
8407
+ setBigUint64(dataDescriptorView, dataDescriptorOffset + 4, BigInt(compressedSize));
8408
+ setBigUint64(dataDescriptorView, dataDescriptorOffset + 12, BigInt(uncompressedSize));
8409
+ }
8410
+ } else {
8411
+ setUint32(headerView, 14, compressedSize);
8412
+ setUint32(headerView, 18, uncompressedSize);
8413
+ if (dataDescriptor) {
8414
+ setUint32(dataDescriptorView, dataDescriptorOffset + 4, compressedSize);
8415
+ setUint32(dataDescriptorView, dataDescriptorOffset + 8, uncompressedSize);
8416
+ }
8305
8417
  }
8306
- const length = localHeaderArray.length + compressedSize + dataDescriptorArray.length;
8307
- Object.assign(fileEntry, {
8308
- compressedSize,
8309
- lastModDate,
8310
- rawLastModDate,
8311
- creationDate,
8312
- lastAccessDate,
8313
- encrypted,
8314
- length,
8315
- writingData: false
8316
- });
8317
- return fileEntry;
8318
8418
  }
8319
8419
 
8320
8420
  async function closeFile(zipWriter, comment, options) {