@zip.js/zip.js 2.6.20 → 2.6.21

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
@@ -7773,7 +7773,7 @@
7773
7773
  files: new Map(),
7774
7774
  filenames: new Set(),
7775
7775
  offset: writer.writable.size,
7776
- pendingCompressedSize: 0,
7776
+ pendingEntriesSize: 0,
7777
7777
  pendingAddFileCalls: new Set()
7778
7778
  });
7779
7779
  }
@@ -7885,6 +7885,7 @@
7885
7885
  extendedTimestamp = true;
7886
7886
  }
7887
7887
  let maximumCompressedSize = 0;
7888
+ let maximumEntrySize = 0;
7888
7889
  let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
7889
7890
  if (keepOrder === undefined) {
7890
7891
  keepOrder = true;
@@ -7906,7 +7907,7 @@
7906
7907
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
7907
7908
  }
7908
7909
  let zip64 = options.zip64 || zipWriter.options.zip64 || false;
7909
- if (zipWriter.offset + zipWriter.pendingCompressedSize >= MAX_32_BITS ||
7910
+ if (zipWriter.offset + zipWriter.pendingEntriesSize >= MAX_32_BITS ||
7910
7911
  uncompressedSize >= MAX_32_BITS ||
7911
7912
  maximumCompressedSize >= MAX_32_BITS) {
7912
7913
  if (options.zip64 === false || zipWriter.options.zip64 === false || !keepOrder) {
@@ -7915,8 +7916,6 @@
7915
7916
  zip64 = true;
7916
7917
  }
7917
7918
  }
7918
- zipWriter.pendingCompressedSize += maximumCompressedSize;
7919
- await Promise.resolve();
7920
7919
  const level = getOptionValue(zipWriter, options, "level");
7921
7920
  const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
7922
7921
  const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
@@ -7930,7 +7929,7 @@
7930
7929
  if (dataDescriptor && dataDescriptorSignature === undefined) {
7931
7930
  dataDescriptorSignature = false;
7932
7931
  }
7933
- const fileEntry = await getFileEntry(zipWriter, name, reader, Object.assign({}, options, {
7932
+ options = Object.assign({}, options, {
7934
7933
  rawFilename,
7935
7934
  rawComment,
7936
7935
  version,
@@ -7955,15 +7954,20 @@
7955
7954
  internalFileAttribute,
7956
7955
  externalFileAttribute,
7957
7956
  useCompressionStream
7958
- }));
7959
- if (maximumCompressedSize) {
7960
- zipWriter.pendingCompressedSize -= maximumCompressedSize;
7957
+ });
7958
+ const localHeaderInfo = getLocalHeaderInfo(options);
7959
+ const dataDescriptorInfo = getDataDescriptorInfo(options);
7960
+ maximumEntrySize = localHeaderInfo.localHeaderArray.length + maximumCompressedSize + dataDescriptorInfo.dataDescriptorArray.length;
7961
+ zipWriter.pendingEntriesSize += maximumEntrySize;
7962
+ const fileEntry = await getFileEntry(zipWriter, name, reader, { localHeaderInfo, dataDescriptorInfo }, options);
7963
+ if (maximumEntrySize) {
7964
+ zipWriter.pendingEntriesSize -= maximumEntrySize;
7961
7965
  }
7962
7966
  Object.assign(fileEntry, { name, comment, extraField });
7963
7967
  return new Entry(fileEntry);
7964
7968
  }
7965
7969
 
7966
- async function getFileEntry(zipWriter, name, reader, options) {
7970
+ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
7967
7971
  const {
7968
7972
  files,
7969
7973
  writer
@@ -8002,7 +8006,8 @@
8002
8006
  if (!bufferedWrite) {
8003
8007
  await lockPreviousFileEntry;
8004
8008
  }
8005
- fileEntry = await createFileEntry(reader, fileWriter, fileEntry, zipWriter.config, options);
8009
+ fileEntry.writingData = true;
8010
+ fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
8006
8011
  files.set(name, fileEntry);
8007
8012
  fileEntry.filename = name;
8008
8013
  if (bufferedWrite) {
@@ -8078,7 +8083,25 @@
8078
8083
  }
8079
8084
  }
8080
8085
 
8081
- async function createFileEntry(reader, writer, pendingFileEntry, config, options) {
8086
+ async function createFileEntry(reader, writer, pendingFileEntry, entryInfo, config, options) {
8087
+ const {
8088
+ localHeaderInfo,
8089
+ dataDescriptorInfo
8090
+ } = entryInfo;
8091
+ const {
8092
+ localHeaderArray,
8093
+ headerArray,
8094
+ lastModDate,
8095
+ rawLastModDate,
8096
+ encrypted,
8097
+ compressed,
8098
+ version,
8099
+ compressionMethod,
8100
+ rawExtraFieldExtendedTimestamp,
8101
+ rawExtraFieldNTFS,
8102
+ rawExtraFieldAES
8103
+ } = localHeaderInfo;
8104
+ const { dataDescriptorArray } = dataDescriptorInfo;
8082
8105
  const {
8083
8106
  rawFilename,
8084
8107
  lastAccessDate,
@@ -8088,9 +8111,7 @@
8088
8111
  zip64,
8089
8112
  zipCrypto,
8090
8113
  dataDescriptor,
8091
- dataDescriptorSignature,
8092
8114
  directory,
8093
- version,
8094
8115
  versionMadeBy,
8095
8116
  rawComment,
8096
8117
  rawExtraField,
@@ -8106,8 +8127,108 @@
8106
8127
  externalFileAttribute,
8107
8128
  useCompressionStream
8108
8129
  } = options;
8109
- const encrypted = Boolean(password && password.length);
8130
+ const fileEntry = {
8131
+ lock: pendingFileEntry.lock,
8132
+ versionMadeBy,
8133
+ zip64,
8134
+ directory: Boolean(directory),
8135
+ filenameUTF8: true,
8136
+ rawFilename,
8137
+ commentUTF8: true,
8138
+ rawComment,
8139
+ rawExtraFieldExtendedTimestamp,
8140
+ rawExtraFieldNTFS,
8141
+ rawExtraFieldAES,
8142
+ rawExtraField,
8143
+ extendedTimestamp,
8144
+ msDosCompatible,
8145
+ internalFileAttribute,
8146
+ externalFileAttribute
8147
+ };
8148
+ let uncompressedSize = 0;
8149
+ let signature;
8150
+ let compressedSize = 0;
8151
+ const { writable } = writer;
8152
+ if (reader) {
8153
+ reader.chunkSize = getChunkSize(config);
8154
+ await writeData(writable, localHeaderArray);
8155
+ const size = () => reader.size;
8156
+ const readable = reader.readable;
8157
+ readable.size = size;
8158
+ const workerOptions = {
8159
+ options: {
8160
+ codecType: CODEC_DEFLATE,
8161
+ level,
8162
+ password,
8163
+ encryptionStrength,
8164
+ zipCrypto: encrypted && zipCrypto,
8165
+ passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
8166
+ signed: true,
8167
+ compressed,
8168
+ encrypted,
8169
+ useWebWorkers,
8170
+ useCompressionStream
8171
+ },
8172
+ config,
8173
+ streamOptions: { signal, size, onstart, onprogress, onend },
8174
+ codecConstructor: config.Deflate
8175
+ };
8176
+ const previousSize = writable.size;
8177
+ signature = (await runWorker({ readable, writable }, workerOptions)).signature;
8178
+ uncompressedSize = reader.size = readable.size();
8179
+ compressedSize = writable.size - previousSize;
8180
+ } else {
8181
+ await writeData(writable, localHeaderArray);
8182
+ }
8183
+ const rawExtraFieldZip64 = zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array();
8184
+ if (reader) {
8185
+ setEntryInfo({
8186
+ signature,
8187
+ rawExtraFieldZip64,
8188
+ compressedSize,
8189
+ uncompressedSize,
8190
+ localHeaderInfo,
8191
+ dataDescriptorInfo
8192
+ }, options);
8193
+ }
8194
+ if (dataDescriptor) {
8195
+ await writeData(writable, dataDescriptorArray);
8196
+ }
8197
+ Object.assign(fileEntry, {
8198
+ compressedSize,
8199
+ lastModDate,
8200
+ rawLastModDate,
8201
+ creationDate,
8202
+ lastAccessDate,
8203
+ encrypted,
8204
+ length: localHeaderArray.length + compressedSize + dataDescriptorArray.length,
8205
+ compressionMethod,
8206
+ version,
8207
+ headerArray,
8208
+ signature,
8209
+ rawExtraFieldZip64
8210
+ });
8211
+ return fileEntry;
8212
+ }
8213
+
8214
+ function getLocalHeaderInfo(options) {
8215
+ const {
8216
+ rawFilename,
8217
+ lastAccessDate,
8218
+ creationDate,
8219
+ password,
8220
+ level,
8221
+ zip64,
8222
+ zipCrypto,
8223
+ dataDescriptor,
8224
+ directory,
8225
+ rawExtraField,
8226
+ encryptionStrength,
8227
+ extendedTimestamp,
8228
+ } = options;
8229
+ let version = options.version || VERSION_DEFLATE;
8110
8230
  const compressed = level !== 0 && !directory;
8231
+ const encrypted = Boolean(password && password.length);
8111
8232
  let rawExtraFieldAES;
8112
8233
  if (encrypted && !zipCrypto) {
8113
8234
  rawExtraFieldAES = new Uint8Array(EXTRAFIELD_DATA_AES.length + 2);
@@ -8151,27 +8272,6 @@
8151
8272
  } else {
8152
8273
  rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array();
8153
8274
  }
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
8275
  let bitFlag = BITFLAG_LANG_ENCODING_FLAG;
8176
8276
  if (dataDescriptor) {
8177
8277
  bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
@@ -8181,22 +8281,21 @@
8181
8281
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
8182
8282
  }
8183
8283
  if (zip64) {
8184
- fileEntry.version = fileEntry.version > VERSION_ZIP64 ? fileEntry.version : VERSION_ZIP64;
8284
+ version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
8185
8285
  }
8186
8286
  if (encrypted) {
8187
8287
  bitFlag = bitFlag | BITFLAG_ENCRYPTED;
8188
8288
  if (!zipCrypto) {
8189
- fileEntry.version = fileEntry.version > VERSION_AES ? fileEntry.version : VERSION_AES;
8289
+ version = version > VERSION_AES ? version : VERSION_AES;
8190
8290
  compressionMethod = COMPRESSION_METHOD_AES;
8191
8291
  if (compressed) {
8192
- fileEntry.rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
8292
+ rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
8193
8293
  }
8194
8294
  }
8195
8295
  }
8196
- fileEntry.compressionMethod = compressionMethod;
8197
- const headerArray = fileEntry.headerArray = new Uint8Array(26);
8296
+ const headerArray = new Uint8Array(26);
8198
8297
  const headerView = getDataView(headerArray);
8199
- setUint16(headerView, 0, fileEntry.version);
8298
+ setUint16(headerView, 0, version);
8200
8299
  setUint16(headerView, 2, bitFlag);
8201
8300
  setUint16(headerView, 4, compressionMethod);
8202
8301
  const dateArray = new Uint32Array(1);
@@ -8225,41 +8324,28 @@
8225
8324
  arraySet(localHeaderArray, rawExtraFieldExtendedTimestamp, 30 + rawFilename.length + rawExtraFieldAES.length);
8226
8325
  arraySet(localHeaderArray, rawExtraFieldNTFS, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length);
8227
8326
  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
- }
8327
+ return {
8328
+ localHeaderArray,
8329
+ headerArray,
8330
+ headerView,
8331
+ lastModDate,
8332
+ rawLastModDate,
8333
+ encrypted,
8334
+ compressed,
8335
+ version,
8336
+ compressionMethod,
8337
+ rawExtraFieldExtendedTimestamp,
8338
+ rawExtraFieldNTFS,
8339
+ rawExtraFieldAES
8340
+ };
8341
+ }
8342
+
8343
+ function getDataDescriptorInfo(options) {
8344
+ const {
8345
+ zip64,
8346
+ dataDescriptor,
8347
+ dataDescriptorSignature
8348
+ } = options;
8263
8349
  let dataDescriptorArray = new Uint8Array();
8264
8350
  let dataDescriptorView, dataDescriptorOffset = 0;
8265
8351
  if (dataDescriptor) {
@@ -8270,51 +8356,61 @@
8270
8356
  setUint32(dataDescriptorView, 0, DATA_DESCRIPTOR_RECORD_SIGNATURE);
8271
8357
  }
8272
8358
  }
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
- }
8359
+ return {
8360
+ dataDescriptorArray,
8361
+ dataDescriptorView,
8362
+ dataDescriptorOffset
8363
+ };
8364
+ }
8365
+
8366
+ function setEntryInfo(entryInfo, options) {
8367
+ const {
8368
+ signature,
8369
+ rawExtraFieldZip64,
8370
+ compressedSize,
8371
+ uncompressedSize,
8372
+ localHeaderInfo,
8373
+ dataDescriptorInfo
8374
+ } = entryInfo;
8375
+ const {
8376
+ headerView,
8377
+ encrypted
8378
+ } = localHeaderInfo;
8379
+ const {
8380
+ dataDescriptorView,
8381
+ dataDescriptorOffset
8382
+ } = dataDescriptorInfo;
8383
+ const {
8384
+ zip64,
8385
+ zipCrypto,
8386
+ dataDescriptor
8387
+ } = options;
8388
+ if ((!encrypted || zipCrypto) && signature !== undefined) {
8389
+ setUint32(headerView, 10, signature);
8390
+ if (dataDescriptor) {
8391
+ setUint32(dataDescriptorView, dataDescriptorOffset, signature);
8301
8392
  }
8302
8393
  }
8303
- if (dataDescriptor) {
8304
- await writeData(writable, dataDescriptorArray);
8394
+ if (zip64) {
8395
+ const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
8396
+ setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
8397
+ setUint16(rawExtraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64);
8398
+ setUint32(headerView, 14, MAX_32_BITS);
8399
+ setBigUint64(rawExtraFieldZip64View, 12, BigInt(compressedSize));
8400
+ setUint32(headerView, 18, MAX_32_BITS);
8401
+ setBigUint64(rawExtraFieldZip64View, 4, BigInt(uncompressedSize));
8402
+ if (dataDescriptor) {
8403
+ setBigUint64(dataDescriptorView, dataDescriptorOffset + 4, BigInt(compressedSize));
8404
+ setBigUint64(dataDescriptorView, dataDescriptorOffset + 12, BigInt(uncompressedSize));
8405
+ }
8406
+ } else {
8407
+ setUint32(headerView, 14, compressedSize);
8408
+ setUint32(headerView, 18, uncompressedSize);
8409
+ if (dataDescriptor) {
8410
+ setUint32(dataDescriptorView, dataDescriptorOffset + 4, compressedSize);
8411
+ setUint32(dataDescriptorView, dataDescriptorOffset + 8, uncompressedSize);
8412
+ }
8305
8413
  }
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
8414
  }
8319
8415
 
8320
8416
  async function closeFile(zipWriter, comment, options) {