@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.
@@ -7688,7 +7688,7 @@
7688
7688
  const writer = this;
7689
7689
  writer.contentType = contentType;
7690
7690
  writer.transformStream = new TransformStream();
7691
- Object.defineProperty(this, "writable", {
7691
+ Object.defineProperty(writer, "writable", {
7692
7692
  get() {
7693
7693
  return writer.transformStream.writable;
7694
7694
  }
@@ -7702,7 +7702,11 @@
7702
7702
  transformStream,
7703
7703
  contentType
7704
7704
  } = writer;
7705
- writer.blob = new Response(transformStream.readable).blob({ type: contentType });
7705
+ const headers = [];
7706
+ if (contentType) {
7707
+ headers.push(["content-type", contentType]);
7708
+ }
7709
+ writer.blob = new Response(transformStream.readable, { headers }).blob();
7706
7710
  }
7707
7711
 
7708
7712
  getData() {
@@ -8774,7 +8778,7 @@
8774
8778
  files: new Map(),
8775
8779
  filenames: new Set(),
8776
8780
  offset: writer.writable.size,
8777
- pendingCompressedSize: 0,
8781
+ pendingEntriesSize: 0,
8778
8782
  pendingAddFileCalls: new Set()
8779
8783
  });
8780
8784
  }
@@ -8886,6 +8890,7 @@
8886
8890
  extendedTimestamp = true;
8887
8891
  }
8888
8892
  let maximumCompressedSize = 0;
8893
+ let maximumEntrySize = 0;
8889
8894
  let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
8890
8895
  if (keepOrder === undefined) {
8891
8896
  keepOrder = true;
@@ -8907,7 +8912,7 @@
8907
8912
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
8908
8913
  }
8909
8914
  let zip64 = options.zip64 || zipWriter.options.zip64 || false;
8910
- if (zipWriter.offset + zipWriter.pendingCompressedSize >= MAX_32_BITS ||
8915
+ if (zipWriter.offset + zipWriter.pendingEntriesSize >= MAX_32_BITS ||
8911
8916
  uncompressedSize >= MAX_32_BITS ||
8912
8917
  maximumCompressedSize >= MAX_32_BITS) {
8913
8918
  if (options.zip64 === false || zipWriter.options.zip64 === false || !keepOrder) {
@@ -8916,8 +8921,6 @@
8916
8921
  zip64 = true;
8917
8922
  }
8918
8923
  }
8919
- zipWriter.pendingCompressedSize += maximumCompressedSize;
8920
- await Promise.resolve();
8921
8924
  const level = getOptionValue(zipWriter, options, "level");
8922
8925
  const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
8923
8926
  const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
@@ -8931,7 +8934,7 @@
8931
8934
  if (dataDescriptor && dataDescriptorSignature === undefined) {
8932
8935
  dataDescriptorSignature = false;
8933
8936
  }
8934
- const fileEntry = await getFileEntry(zipWriter, name, reader, Object.assign({}, options, {
8937
+ options = Object.assign({}, options, {
8935
8938
  rawFilename,
8936
8939
  rawComment,
8937
8940
  version,
@@ -8956,15 +8959,20 @@
8956
8959
  internalFileAttribute,
8957
8960
  externalFileAttribute,
8958
8961
  useCompressionStream
8959
- }));
8960
- if (maximumCompressedSize) {
8961
- zipWriter.pendingCompressedSize -= maximumCompressedSize;
8962
+ });
8963
+ const headerInfo = getHeaderInfo(options);
8964
+ const dataDescriptorInfo = getDataDescriptorInfo(options);
8965
+ maximumEntrySize = headerInfo.localHeaderArray.length + maximumCompressedSize + dataDescriptorInfo.dataDescriptorArray.length;
8966
+ zipWriter.pendingEntriesSize += maximumEntrySize;
8967
+ const fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo }, options);
8968
+ if (maximumEntrySize) {
8969
+ zipWriter.pendingEntriesSize -= maximumEntrySize;
8962
8970
  }
8963
8971
  Object.assign(fileEntry, { name, comment, extraField });
8964
8972
  return new Entry(fileEntry);
8965
8973
  }
8966
8974
 
8967
- async function getFileEntry(zipWriter, name, reader, options) {
8975
+ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
8968
8976
  const {
8969
8977
  files,
8970
8978
  writer
@@ -9003,7 +9011,8 @@
9003
9011
  if (!bufferedWrite) {
9004
9012
  await lockPreviousFileEntry;
9005
9013
  }
9006
- fileEntry = await createFileEntry(reader, fileWriter, fileEntry, zipWriter.config, options);
9014
+ fileEntry.writingData = true;
9015
+ fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
9007
9016
  files.set(name, fileEntry);
9008
9017
  fileEntry.filename = name;
9009
9018
  if (bufferedWrite) {
@@ -9079,7 +9088,25 @@
9079
9088
  }
9080
9089
  }
9081
9090
 
9082
- async function createFileEntry(reader, writer, pendingFileEntry, config, options) {
9091
+ async function createFileEntry(reader, writer, pendingFileEntry, entryInfo, config, options) {
9092
+ const {
9093
+ headerInfo,
9094
+ dataDescriptorInfo
9095
+ } = entryInfo;
9096
+ const {
9097
+ localHeaderArray,
9098
+ headerArray,
9099
+ lastModDate,
9100
+ rawLastModDate,
9101
+ encrypted,
9102
+ compressed,
9103
+ version,
9104
+ compressionMethod,
9105
+ rawExtraFieldExtendedTimestamp,
9106
+ rawExtraFieldNTFS,
9107
+ rawExtraFieldAES
9108
+ } = headerInfo;
9109
+ const { dataDescriptorArray } = dataDescriptorInfo;
9083
9110
  const {
9084
9111
  rawFilename,
9085
9112
  lastAccessDate,
@@ -9089,9 +9116,7 @@
9089
9116
  zip64,
9090
9117
  zipCrypto,
9091
9118
  dataDescriptor,
9092
- dataDescriptorSignature,
9093
9119
  directory,
9094
- version,
9095
9120
  versionMadeBy,
9096
9121
  rawComment,
9097
9122
  rawExtraField,
@@ -9107,8 +9132,108 @@
9107
9132
  externalFileAttribute,
9108
9133
  useCompressionStream
9109
9134
  } = options;
9110
- const encrypted = Boolean(password && password.length);
9135
+ const fileEntry = {
9136
+ lock: pendingFileEntry.lock,
9137
+ versionMadeBy,
9138
+ zip64,
9139
+ directory: Boolean(directory),
9140
+ filenameUTF8: true,
9141
+ rawFilename,
9142
+ commentUTF8: true,
9143
+ rawComment,
9144
+ rawExtraFieldExtendedTimestamp,
9145
+ rawExtraFieldNTFS,
9146
+ rawExtraFieldAES,
9147
+ rawExtraField,
9148
+ extendedTimestamp,
9149
+ msDosCompatible,
9150
+ internalFileAttribute,
9151
+ externalFileAttribute
9152
+ };
9153
+ let uncompressedSize = 0;
9154
+ let signature;
9155
+ let compressedSize = 0;
9156
+ const { writable } = writer;
9157
+ if (reader) {
9158
+ reader.chunkSize = getChunkSize(config);
9159
+ await writeData(writable, localHeaderArray);
9160
+ const size = () => reader.size;
9161
+ const readable = reader.readable;
9162
+ readable.size = size;
9163
+ const workerOptions = {
9164
+ options: {
9165
+ codecType: CODEC_DEFLATE,
9166
+ level,
9167
+ password,
9168
+ encryptionStrength,
9169
+ zipCrypto: encrypted && zipCrypto,
9170
+ passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
9171
+ signed: true,
9172
+ compressed,
9173
+ encrypted,
9174
+ useWebWorkers,
9175
+ useCompressionStream
9176
+ },
9177
+ config,
9178
+ streamOptions: { signal, size, onstart, onprogress, onend },
9179
+ codecConstructor: config.Deflate
9180
+ };
9181
+ const previousSize = writable.size;
9182
+ signature = (await runWorker({ readable, writable }, workerOptions)).signature;
9183
+ uncompressedSize = reader.size = readable.size();
9184
+ compressedSize = writable.size - previousSize;
9185
+ } else {
9186
+ await writeData(writable, localHeaderArray);
9187
+ }
9188
+ const rawExtraFieldZip64 = zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array();
9189
+ if (reader) {
9190
+ setEntryInfo({
9191
+ signature,
9192
+ rawExtraFieldZip64,
9193
+ compressedSize,
9194
+ uncompressedSize,
9195
+ headerInfo,
9196
+ dataDescriptorInfo
9197
+ }, options);
9198
+ }
9199
+ if (dataDescriptor) {
9200
+ await writeData(writable, dataDescriptorArray);
9201
+ }
9202
+ Object.assign(fileEntry, {
9203
+ compressedSize,
9204
+ lastModDate,
9205
+ rawLastModDate,
9206
+ creationDate,
9207
+ lastAccessDate,
9208
+ encrypted,
9209
+ length: localHeaderArray.length + compressedSize + dataDescriptorArray.length,
9210
+ compressionMethod,
9211
+ version,
9212
+ headerArray,
9213
+ signature,
9214
+ rawExtraFieldZip64
9215
+ });
9216
+ return fileEntry;
9217
+ }
9218
+
9219
+ function getHeaderInfo(options) {
9220
+ const {
9221
+ rawFilename,
9222
+ lastAccessDate,
9223
+ creationDate,
9224
+ password,
9225
+ level,
9226
+ zip64,
9227
+ zipCrypto,
9228
+ dataDescriptor,
9229
+ directory,
9230
+ rawExtraField,
9231
+ encryptionStrength,
9232
+ extendedTimestamp,
9233
+ } = options;
9234
+ let version = options.version || VERSION_DEFLATE;
9111
9235
  const compressed = level !== 0 && !directory;
9236
+ const encrypted = Boolean(password && password.length);
9112
9237
  let rawExtraFieldAES;
9113
9238
  if (encrypted && !zipCrypto) {
9114
9239
  rawExtraFieldAES = new Uint8Array(EXTRAFIELD_DATA_AES.length + 2);
@@ -9152,27 +9277,6 @@
9152
9277
  } else {
9153
9278
  rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array();
9154
9279
  }
9155
- const fileEntry = {
9156
- lock: pendingFileEntry.lock,
9157
- version: version || VERSION_DEFLATE,
9158
- versionMadeBy,
9159
- zip64,
9160
- directory: Boolean(directory),
9161
- filenameUTF8: true,
9162
- rawFilename,
9163
- commentUTF8: true,
9164
- rawComment,
9165
- rawExtraFieldZip64: zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array(),
9166
- rawExtraFieldExtendedTimestamp,
9167
- rawExtraFieldNTFS,
9168
- rawExtraFieldAES,
9169
- rawExtraField,
9170
- extendedTimestamp,
9171
- msDosCompatible,
9172
- internalFileAttribute,
9173
- externalFileAttribute
9174
- };
9175
- let uncompressedSize = 0;
9176
9280
  let bitFlag = BITFLAG_LANG_ENCODING_FLAG;
9177
9281
  if (dataDescriptor) {
9178
9282
  bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
@@ -9182,22 +9286,21 @@
9182
9286
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
9183
9287
  }
9184
9288
  if (zip64) {
9185
- fileEntry.version = fileEntry.version > VERSION_ZIP64 ? fileEntry.version : VERSION_ZIP64;
9289
+ version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
9186
9290
  }
9187
9291
  if (encrypted) {
9188
9292
  bitFlag = bitFlag | BITFLAG_ENCRYPTED;
9189
9293
  if (!zipCrypto) {
9190
- fileEntry.version = fileEntry.version > VERSION_AES ? fileEntry.version : VERSION_AES;
9294
+ version = version > VERSION_AES ? version : VERSION_AES;
9191
9295
  compressionMethod = COMPRESSION_METHOD_AES;
9192
9296
  if (compressed) {
9193
- fileEntry.rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
9297
+ rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
9194
9298
  }
9195
9299
  }
9196
9300
  }
9197
- fileEntry.compressionMethod = compressionMethod;
9198
- const headerArray = fileEntry.headerArray = new Uint8Array(26);
9301
+ const headerArray = new Uint8Array(26);
9199
9302
  const headerView = getDataView(headerArray);
9200
- setUint16(headerView, 0, fileEntry.version);
9303
+ setUint16(headerView, 0, version);
9201
9304
  setUint16(headerView, 2, bitFlag);
9202
9305
  setUint16(headerView, 4, compressionMethod);
9203
9306
  const dateArray = new Uint32Array(1);
@@ -9226,41 +9329,28 @@
9226
9329
  arraySet(localHeaderArray, rawExtraFieldExtendedTimestamp, 30 + rawFilename.length + rawExtraFieldAES.length);
9227
9330
  arraySet(localHeaderArray, rawExtraFieldNTFS, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length);
9228
9331
  arraySet(localHeaderArray, rawExtraField, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length);
9229
- let result;
9230
- let compressedSize = 0;
9231
- const { writable } = writer;
9232
- fileEntry.writingData = pendingFileEntry.writingData = true;
9233
- if (reader) {
9234
- reader.chunkSize = getChunkSize(config);
9235
- await writeData(writable, localHeaderArray);
9236
- const size = () => reader.size;
9237
- const readable = reader.readable;
9238
- readable.size = size;
9239
- const workerOptions = {
9240
- options: {
9241
- codecType: CODEC_DEFLATE,
9242
- level,
9243
- password,
9244
- encryptionStrength,
9245
- zipCrypto: encrypted && zipCrypto,
9246
- passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
9247
- signed: true,
9248
- compressed,
9249
- encrypted,
9250
- useWebWorkers,
9251
- useCompressionStream
9252
- },
9253
- config,
9254
- streamOptions: { signal, size, onstart, onprogress, onend },
9255
- codecConstructor: config.Deflate
9256
- };
9257
- const previousSize = writable.size;
9258
- result = await runWorker({ readable, writable }, workerOptions);
9259
- uncompressedSize = reader.size = readable.size();
9260
- compressedSize = writable.size - previousSize;
9261
- } else {
9262
- await writeData(writable, localHeaderArray);
9263
- }
9332
+ return {
9333
+ localHeaderArray,
9334
+ headerArray,
9335
+ headerView,
9336
+ lastModDate,
9337
+ rawLastModDate,
9338
+ encrypted,
9339
+ compressed,
9340
+ version,
9341
+ compressionMethod,
9342
+ rawExtraFieldExtendedTimestamp,
9343
+ rawExtraFieldNTFS,
9344
+ rawExtraFieldAES
9345
+ };
9346
+ }
9347
+
9348
+ function getDataDescriptorInfo(options) {
9349
+ const {
9350
+ zip64,
9351
+ dataDescriptor,
9352
+ dataDescriptorSignature
9353
+ } = options;
9264
9354
  let dataDescriptorArray = new Uint8Array();
9265
9355
  let dataDescriptorView, dataDescriptorOffset = 0;
9266
9356
  if (dataDescriptor) {
@@ -9271,51 +9361,61 @@
9271
9361
  setUint32(dataDescriptorView, 0, DATA_DESCRIPTOR_RECORD_SIGNATURE);
9272
9362
  }
9273
9363
  }
9274
- if (reader) {
9275
- const { signature } = result;
9276
- if ((!encrypted || zipCrypto) && signature !== undefined) {
9277
- setUint32(headerView, 10, signature);
9278
- fileEntry.signature = signature;
9279
- if (dataDescriptor) {
9280
- setUint32(dataDescriptorView, dataDescriptorOffset, signature);
9281
- }
9282
- }
9283
- if (zip64) {
9284
- const rawExtraFieldZip64View = getDataView(fileEntry.rawExtraFieldZip64);
9285
- setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
9286
- setUint16(rawExtraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64);
9287
- setUint32(headerView, 14, MAX_32_BITS);
9288
- setBigUint64(rawExtraFieldZip64View, 12, BigInt(compressedSize));
9289
- setUint32(headerView, 18, MAX_32_BITS);
9290
- setBigUint64(rawExtraFieldZip64View, 4, BigInt(uncompressedSize));
9291
- if (dataDescriptor) {
9292
- setBigUint64(dataDescriptorView, dataDescriptorOffset + 4, BigInt(compressedSize));
9293
- setBigUint64(dataDescriptorView, dataDescriptorOffset + 12, BigInt(uncompressedSize));
9294
- }
9295
- } else {
9296
- setUint32(headerView, 14, compressedSize);
9297
- setUint32(headerView, 18, uncompressedSize);
9298
- if (dataDescriptor) {
9299
- setUint32(dataDescriptorView, dataDescriptorOffset + 4, compressedSize);
9300
- setUint32(dataDescriptorView, dataDescriptorOffset + 8, uncompressedSize);
9301
- }
9364
+ return {
9365
+ dataDescriptorArray,
9366
+ dataDescriptorView,
9367
+ dataDescriptorOffset
9368
+ };
9369
+ }
9370
+
9371
+ function setEntryInfo(entryInfo, options) {
9372
+ const {
9373
+ signature,
9374
+ rawExtraFieldZip64,
9375
+ compressedSize,
9376
+ uncompressedSize,
9377
+ headerInfo,
9378
+ dataDescriptorInfo
9379
+ } = entryInfo;
9380
+ const {
9381
+ headerView,
9382
+ encrypted
9383
+ } = headerInfo;
9384
+ const {
9385
+ dataDescriptorView,
9386
+ dataDescriptorOffset
9387
+ } = dataDescriptorInfo;
9388
+ const {
9389
+ zip64,
9390
+ zipCrypto,
9391
+ dataDescriptor
9392
+ } = options;
9393
+ if ((!encrypted || zipCrypto) && signature !== undefined) {
9394
+ setUint32(headerView, 10, signature);
9395
+ if (dataDescriptor) {
9396
+ setUint32(dataDescriptorView, dataDescriptorOffset, signature);
9302
9397
  }
9303
9398
  }
9304
- if (dataDescriptor) {
9305
- await writeData(writable, dataDescriptorArray);
9399
+ if (zip64) {
9400
+ const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
9401
+ setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
9402
+ setUint16(rawExtraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64);
9403
+ setUint32(headerView, 14, MAX_32_BITS);
9404
+ setBigUint64(rawExtraFieldZip64View, 12, BigInt(compressedSize));
9405
+ setUint32(headerView, 18, MAX_32_BITS);
9406
+ setBigUint64(rawExtraFieldZip64View, 4, BigInt(uncompressedSize));
9407
+ if (dataDescriptor) {
9408
+ setBigUint64(dataDescriptorView, dataDescriptorOffset + 4, BigInt(compressedSize));
9409
+ setBigUint64(dataDescriptorView, dataDescriptorOffset + 12, BigInt(uncompressedSize));
9410
+ }
9411
+ } else {
9412
+ setUint32(headerView, 14, compressedSize);
9413
+ setUint32(headerView, 18, uncompressedSize);
9414
+ if (dataDescriptor) {
9415
+ setUint32(dataDescriptorView, dataDescriptorOffset + 4, compressedSize);
9416
+ setUint32(dataDescriptorView, dataDescriptorOffset + 8, uncompressedSize);
9417
+ }
9306
9418
  }
9307
- const length = localHeaderArray.length + compressedSize + dataDescriptorArray.length;
9308
- Object.assign(fileEntry, {
9309
- compressedSize,
9310
- lastModDate,
9311
- rawLastModDate,
9312
- creationDate,
9313
- lastAccessDate,
9314
- encrypted,
9315
- length,
9316
- writingData: false
9317
- });
9318
- return fileEntry;
9319
9419
  }
9320
9420
 
9321
9421
  async function closeFile(zipWriter, comment, options) {