@zip.js/zip.js 2.6.18 → 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.
Files changed (140) hide show
  1. package/.eslintrc.json +0 -0
  2. package/README.md +0 -0
  3. package/cli-deno/mc-zip.js +0 -0
  4. package/dist/README.md +0 -0
  5. package/dist/z-worker-fflate.js +1 -1
  6. package/dist/z-worker-pako.js +1 -1
  7. package/dist/z-worker.js +1 -1
  8. package/dist/zip-fs-full.js +264 -153
  9. package/dist/zip-fs-full.min.js +1 -1
  10. package/dist/zip-fs.js +264 -153
  11. package/dist/zip-fs.min.js +1 -1
  12. package/dist/zip-full.js +259 -153
  13. package/dist/zip-full.min.js +1 -1
  14. package/dist/zip-no-worker-deflate.min.js +1 -1
  15. package/dist/zip-no-worker-inflate.min.js +1 -1
  16. package/dist/zip-no-worker.min.js +1 -1
  17. package/dist/zip.js +259 -153
  18. package/dist/zip.min.js +1 -1
  19. package/index-fflate.js +0 -0
  20. package/index.d.ts +11 -18
  21. package/index.js +0 -0
  22. package/lib/core/codec-interface.js +14 -1
  23. package/lib/core/codec-pool-worker.js +3 -0
  24. package/lib/core/codec-pool.js +0 -0
  25. package/lib/core/configuration.js +0 -0
  26. package/lib/core/constants.js +0 -0
  27. package/lib/core/io.js +11 -19
  28. package/lib/core/streams/aes-crypto-stream.js +0 -0
  29. package/lib/core/streams/codec-stream.js +0 -0
  30. package/lib/core/streams/codecs/crc32.js +0 -0
  31. package/lib/core/streams/codecs/deflate.js +0 -0
  32. package/lib/core/streams/codecs/inflate.js +0 -0
  33. package/lib/core/streams/codecs/sjcl.js +0 -0
  34. package/lib/core/streams/common-crypto.js +0 -0
  35. package/lib/core/streams/crc32-stream.js +0 -0
  36. package/lib/core/streams/zip-crypto-stream.js +0 -0
  37. package/lib/core/streams/zip-entry-stream.js +1 -9
  38. package/lib/core/util/cp437-decode.js +0 -0
  39. package/lib/core/util/decode-text.js +0 -0
  40. package/lib/core/util/default-mime-type.js +0 -0
  41. package/lib/core/util/encode-text.js +0 -0
  42. package/lib/core/util/mime-type.js +0 -0
  43. package/lib/core/util/stream-codec-shim.js +0 -0
  44. package/lib/core/z-worker-core.js +18 -7
  45. package/lib/core/zip-entry.js +0 -0
  46. package/lib/core/zip-fs-core.js +5 -0
  47. package/lib/core/zip-reader.js +1 -0
  48. package/lib/core/zip-writer.js +231 -123
  49. package/lib/z-worker-bootstrap-fflate.js +0 -0
  50. package/lib/z-worker-bootstrap-pako.js +0 -0
  51. package/lib/z-worker-fflate.js +0 -0
  52. package/lib/z-worker-inline-template-base64.js +0 -0
  53. package/lib/z-worker-inline-template.js +0 -0
  54. package/lib/z-worker-inline.js +1 -1
  55. package/lib/z-worker.js +0 -0
  56. package/lib/zip-fflate-shim.js +0 -0
  57. package/lib/zip-fs.js +0 -0
  58. package/lib/zip-full-fflate.js +0 -0
  59. package/lib/zip-full.js +0 -0
  60. package/lib/zip-no-worker-deflate.js +0 -0
  61. package/lib/zip-no-worker-fflate-deflate.js +0 -0
  62. package/lib/zip-no-worker-fflate-inflate.js +0 -0
  63. package/lib/zip-no-worker-fflate.js +0 -0
  64. package/lib/zip-no-worker-inflate.js +0 -0
  65. package/lib/zip-no-worker.js +0 -0
  66. package/lib/zip.js +0 -0
  67. package/package.json +1 -1
  68. package/rollup-fflate.config.dev.js +0 -0
  69. package/rollup-fflate.config.js +0 -0
  70. package/rollup.config.dev.js +0 -0
  71. package/rollup.config.js +0 -0
  72. package/tests/all/loader.html +0 -0
  73. package/tests/all/test-abort-signal-read.js +0 -0
  74. package/tests/all/test-abort-signal-write.js +0 -0
  75. package/tests/all/test-array.js +0 -0
  76. package/tests/all/test-base64.js +0 -0
  77. package/tests/all/test-blob.js +0 -0
  78. package/tests/all/test-codecs-interoperability.js +0 -0
  79. package/tests/all/test-crc.js +0 -0
  80. package/tests/all/test-crypto.js +0 -0
  81. package/tests/all/test-custom-io.js +0 -1
  82. package/tests/all/test-data-descriptor-signature.js +0 -0
  83. package/tests/all/test-data-descriptor.js +0 -0
  84. package/tests/all/test-duplicated-filename.js +0 -0
  85. package/tests/all/test-empty.js +0 -0
  86. package/tests/all/test-extended-timestamp.js +0 -0
  87. package/tests/all/test-extra-field.js +0 -0
  88. package/tests/all/test-fflate-no-worker.js +0 -0
  89. package/tests/all/test-fflate.js +0 -0
  90. package/tests/all/test-fs-base64.js +0 -0
  91. package/tests/all/test-fs-export-options.js +0 -0
  92. package/tests/all/test-fs-http-import.js +0 -0
  93. package/tests/all/test-fs-http-reader.js +0 -0
  94. package/tests/all/test-fs-replace.js +0 -0
  95. package/tests/all/test-fs-streams.js +0 -0
  96. package/tests/all/test-fs-text.js +0 -0
  97. package/tests/all/test-fs-unzip-store.js +0 -0
  98. package/tests/all/test-fs.js +0 -0
  99. package/tests/all/test-http-crypto.js +0 -0
  100. package/tests/all/test-http-range.js +0 -0
  101. package/tests/all/test-http-zip64.js +0 -0
  102. package/tests/all/test-invalid-crc.js +0 -0
  103. package/tests/all/test-multiple-writers.js +0 -0
  104. package/tests/all/test-no-worker.js +0 -0
  105. package/tests/all/test-pako-no-worker.js +0 -0
  106. package/tests/all/test-pako.js +0 -0
  107. package/tests/all/test-parallel-reads.js +0 -0
  108. package/tests/all/test-parallel-writes-auto-buffered.js +0 -0
  109. package/tests/all/test-parallel-writes-ordered.js +0 -0
  110. package/tests/all/test-parallel-writes.js +0 -0
  111. package/tests/all/test-readable-stream.js +0 -0
  112. package/tests/all/test-readable-zip-stream.js +0 -0
  113. package/tests/all/test-safe-closing.js +0 -0
  114. package/tests/all/test-store.js +0 -0
  115. package/tests/all/test-sw-worker.js +0 -0
  116. package/tests/all/test-sw.js +0 -0
  117. package/tests/all/test-worker-timeout.js +0 -0
  118. package/tests/all/test-wrapped.js +2 -2
  119. package/tests/all/test-writable-stream.js +0 -0
  120. package/tests/all/test-zip64-auto.js +3 -2
  121. package/tests/all/test-zip64-crypto.js +0 -0
  122. package/tests/all/test-zip64.js +0 -0
  123. package/tests/all/test-zipcrypto.js +0 -0
  124. package/tests/data/lorem-encrypted.zip +0 -0
  125. package/tests/data/lorem-invalid-crc.zip +0 -0
  126. package/tests/data/lorem-store.zip +0 -0
  127. package/tests/data/lorem-zip64.zip +0 -0
  128. package/tests/data/lorem.txt +0 -0
  129. package/tests/data/lorem.zip +0 -0
  130. package/tests/deno-runner.js +0 -0
  131. package/tests/index.html +0 -0
  132. package/tests/node-runner.js +0 -0
  133. package/tests/tests-data.js +0 -0
  134. package/tests/vendor/fflate-es2019.min.js +0 -0
  135. package/tests/vendor/fflate.min.js +0 -0
  136. package/tests/vendor/pako.min.js +0 -0
  137. package/tests/vendor/pako_deflate.min.js +0 -0
  138. package/tests/vendor/pako_inflate.min.js +0 -0
  139. package/tests/web-runner.js +0 -0
  140. package/tsconfig.json +0 -0
@@ -93,14 +93,17 @@ const pendingEntries = [];
93
93
  class ZipWriter {
94
94
 
95
95
  constructor(writer, options = {}) {
96
+ if (writer.writable.size == undefined) {
97
+ writer.writable.size = 0;
98
+ }
96
99
  Object.assign(this, {
97
100
  writer,
98
101
  options,
99
102
  config: getConfiguration(),
100
103
  files: new Map(),
101
104
  filenames: new Set(),
102
- offset: writer.size || 0,
103
- pendingCompressedSize: 0,
105
+ offset: writer.writable.size,
106
+ pendingEntriesSize: 0,
104
107
  pendingAddFileCalls: new Set()
105
108
  });
106
109
  }
@@ -225,6 +228,7 @@ async function addFile(zipWriter, name, reader, options) {
225
228
  extendedTimestamp = true;
226
229
  }
227
230
  let maximumCompressedSize = 0;
231
+ let maximumEntrySize = 0;
228
232
  let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
229
233
  if (keepOrder === undefined) {
230
234
  keepOrder = true;
@@ -246,7 +250,7 @@ async function addFile(zipWriter, name, reader, options) {
246
250
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
247
251
  }
248
252
  let zip64 = options.zip64 || zipWriter.options.zip64 || false;
249
- if (zipWriter.offset + zipWriter.pendingCompressedSize >= MAX_32_BITS ||
253
+ if (zipWriter.offset + zipWriter.pendingEntriesSize >= MAX_32_BITS ||
250
254
  uncompressedSize >= MAX_32_BITS ||
251
255
  maximumCompressedSize >= MAX_32_BITS) {
252
256
  if (options.zip64 === false || zipWriter.options.zip64 === false || !keepOrder) {
@@ -255,8 +259,6 @@ async function addFile(zipWriter, name, reader, options) {
255
259
  zip64 = true;
256
260
  }
257
261
  }
258
- zipWriter.pendingCompressedSize += maximumCompressedSize;
259
- await Promise.resolve();
260
262
  const level = getOptionValue(zipWriter, options, "level");
261
263
  const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
262
264
  const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
@@ -270,7 +272,7 @@ async function addFile(zipWriter, name, reader, options) {
270
272
  if (dataDescriptor && dataDescriptorSignature === undefined) {
271
273
  dataDescriptorSignature = false;
272
274
  }
273
- const fileEntry = await getFileEntry(zipWriter, name, reader, Object.assign({}, options, {
275
+ options = Object.assign({}, options, {
274
276
  rawFilename,
275
277
  rawComment,
276
278
  version,
@@ -295,15 +297,20 @@ async function addFile(zipWriter, name, reader, options) {
295
297
  internalFileAttribute,
296
298
  externalFileAttribute,
297
299
  useCompressionStream
298
- }));
299
- if (maximumCompressedSize) {
300
- zipWriter.pendingCompressedSize -= maximumCompressedSize;
300
+ });
301
+ const localHeaderInfo = getLocalHeaderInfo(options);
302
+ const dataDescriptorInfo = getDataDescriptorInfo(options);
303
+ maximumEntrySize = localHeaderInfo.localHeaderArray.length + maximumCompressedSize + dataDescriptorInfo.dataDescriptorArray.length;
304
+ zipWriter.pendingEntriesSize += maximumEntrySize;
305
+ const fileEntry = await getFileEntry(zipWriter, name, reader, { localHeaderInfo, dataDescriptorInfo }, options);
306
+ if (maximumEntrySize) {
307
+ zipWriter.pendingEntriesSize -= maximumEntrySize;
301
308
  }
302
309
  Object.assign(fileEntry, { name, comment, extraField });
303
310
  return new Entry(fileEntry);
304
311
  }
305
312
 
306
- async function getFileEntry(zipWriter, name, reader, options) {
313
+ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
307
314
  const {
308
315
  files,
309
316
  writer
@@ -321,7 +328,6 @@ async function getFileEntry(zipWriter, name, reader, options) {
321
328
  let releaseLockCurrentFileEntry;
322
329
  let writingBufferedData;
323
330
  let fileWriter;
324
- let fileWriterSize;
325
331
  files.set(name, fileEntry);
326
332
  try {
327
333
  let lockPreviousFileEntry;
@@ -331,15 +337,20 @@ async function getFileEntry(zipWriter, name, reader, options) {
331
337
  }
332
338
  if (options.bufferedWrite || zipWriter.lockWriter || !dataDescriptor) {
333
339
  fileWriter = new BlobWriter();
340
+ fileWriter.writable.size = 0;
334
341
  bufferedWrite = true;
335
342
  await initStream(writer);
336
343
  } else {
337
344
  fileWriter = writer;
338
345
  zipWriter.lockWriter = Promise.resolve();
346
+ releaseLockWriter = () => delete zipWriter.lockWriter;
339
347
  }
340
348
  await initStream(fileWriter);
341
- fileWriterSize = fileWriter.size;
342
- fileEntry = await createFileEntry(reader, fileEntry, fileWriter.writable, zipWriter.config, options);
349
+ if (!bufferedWrite) {
350
+ await lockPreviousFileEntry;
351
+ }
352
+ fileEntry.writingData = true;
353
+ fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
343
354
  files.set(name, fileEntry);
344
355
  fileEntry.filename = name;
345
356
  if (bufferedWrite) {
@@ -350,8 +361,7 @@ async function getFileEntry(zipWriter, name, reader, options) {
350
361
  writingBufferedData = true;
351
362
  const { writable } = writer;
352
363
  if (!dataDescriptor) {
353
- const headerLength = 26;
354
- const arrayBuffer = await sliceAsArrayBuffer(blob, 0, headerLength);
364
+ const arrayBuffer = await sliceAsArrayBuffer(blob, 0, 26);
355
365
  const arrayBufferView = new DataView(arrayBuffer);
356
366
  if (!fileEntry.encrypted || zipCrypto) {
357
367
  setUint32(arrayBufferView, 14, fileEntry.signature);
@@ -364,7 +374,7 @@ async function getFileEntry(zipWriter, name, reader, options) {
364
374
  setUint32(arrayBufferView, 22, fileEntry.uncompressedSize);
365
375
  }
366
376
  await writeData(writable, new Uint8Array(arrayBuffer));
367
- blob = blob.slice(headerLength);
377
+ blob = blob.slice(arrayBuffer.byteLength);
368
378
  }
369
379
  await blob.stream().pipeTo(writable, { preventClose: true, signal });
370
380
  writingBufferedData = false;
@@ -384,7 +394,11 @@ async function getFileEntry(zipWriter, name, reader, options) {
384
394
  if (error) {
385
395
  error.corruptedEntry = true;
386
396
  }
387
- zipWriter.offset += fileWriter.size - fileWriterSize;
397
+ if (bufferedWrite) {
398
+ zipWriter.offset += fileWriter.writable.size;
399
+ } else {
400
+ zipWriter.offset = fileWriter.writable.size;
401
+ }
388
402
  }
389
403
  files.delete(name);
390
404
  throw error;
@@ -412,7 +426,25 @@ async function getFileEntry(zipWriter, name, reader, options) {
412
426
  }
413
427
  }
414
428
 
415
- async function createFileEntry(reader, pendingFileEntry, writable, config, options) {
429
+ async function createFileEntry(reader, writer, pendingFileEntry, entryInfo, config, options) {
430
+ const {
431
+ localHeaderInfo,
432
+ dataDescriptorInfo
433
+ } = entryInfo;
434
+ const {
435
+ localHeaderArray,
436
+ headerArray,
437
+ lastModDate,
438
+ rawLastModDate,
439
+ encrypted,
440
+ compressed,
441
+ version,
442
+ compressionMethod,
443
+ rawExtraFieldExtendedTimestamp,
444
+ rawExtraFieldNTFS,
445
+ rawExtraFieldAES
446
+ } = localHeaderInfo;
447
+ const { dataDescriptorArray } = dataDescriptorInfo;
416
448
  const {
417
449
  rawFilename,
418
450
  lastAccessDate,
@@ -422,9 +454,7 @@ async function createFileEntry(reader, pendingFileEntry, writable, config, optio
422
454
  zip64,
423
455
  zipCrypto,
424
456
  dataDescriptor,
425
- dataDescriptorSignature,
426
457
  directory,
427
- version,
428
458
  versionMadeBy,
429
459
  rawComment,
430
460
  rawExtraField,
@@ -440,8 +470,108 @@ async function createFileEntry(reader, pendingFileEntry, writable, config, optio
440
470
  externalFileAttribute,
441
471
  useCompressionStream
442
472
  } = options;
443
- const encrypted = Boolean(password && password.length);
473
+ const fileEntry = {
474
+ lock: pendingFileEntry.lock,
475
+ versionMadeBy,
476
+ zip64,
477
+ directory: Boolean(directory),
478
+ filenameUTF8: true,
479
+ rawFilename,
480
+ commentUTF8: true,
481
+ rawComment,
482
+ rawExtraFieldExtendedTimestamp,
483
+ rawExtraFieldNTFS,
484
+ rawExtraFieldAES,
485
+ rawExtraField,
486
+ extendedTimestamp,
487
+ msDosCompatible,
488
+ internalFileAttribute,
489
+ externalFileAttribute
490
+ };
491
+ let uncompressedSize = 0;
492
+ let signature;
493
+ let compressedSize = 0;
494
+ const { writable } = writer;
495
+ if (reader) {
496
+ reader.chunkSize = getChunkSize(config);
497
+ await writeData(writable, localHeaderArray);
498
+ const size = () => reader.size;
499
+ const readable = reader.readable;
500
+ readable.size = size;
501
+ const workerOptions = {
502
+ options: {
503
+ codecType: CODEC_DEFLATE,
504
+ level,
505
+ password,
506
+ encryptionStrength,
507
+ zipCrypto: encrypted && zipCrypto,
508
+ passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
509
+ signed: true,
510
+ compressed,
511
+ encrypted,
512
+ useWebWorkers,
513
+ useCompressionStream
514
+ },
515
+ config,
516
+ streamOptions: { signal, size, onstart, onprogress, onend },
517
+ codecConstructor: config.Deflate
518
+ };
519
+ const previousSize = writable.size;
520
+ signature = (await runWorker({ readable, writable }, workerOptions)).signature;
521
+ uncompressedSize = reader.size = readable.size();
522
+ compressedSize = writable.size - previousSize;
523
+ } else {
524
+ await writeData(writable, localHeaderArray);
525
+ }
526
+ const rawExtraFieldZip64 = zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array();
527
+ if (reader) {
528
+ setEntryInfo({
529
+ signature,
530
+ rawExtraFieldZip64,
531
+ compressedSize,
532
+ uncompressedSize,
533
+ localHeaderInfo,
534
+ dataDescriptorInfo
535
+ }, options);
536
+ }
537
+ if (dataDescriptor) {
538
+ await writeData(writable, dataDescriptorArray);
539
+ }
540
+ Object.assign(fileEntry, {
541
+ compressedSize,
542
+ lastModDate,
543
+ rawLastModDate,
544
+ creationDate,
545
+ lastAccessDate,
546
+ encrypted,
547
+ length: localHeaderArray.length + compressedSize + dataDescriptorArray.length,
548
+ compressionMethod,
549
+ version,
550
+ headerArray,
551
+ signature,
552
+ rawExtraFieldZip64
553
+ });
554
+ return fileEntry;
555
+ }
556
+
557
+ function getLocalHeaderInfo(options) {
558
+ const {
559
+ rawFilename,
560
+ lastAccessDate,
561
+ creationDate,
562
+ password,
563
+ level,
564
+ zip64,
565
+ zipCrypto,
566
+ dataDescriptor,
567
+ directory,
568
+ rawExtraField,
569
+ encryptionStrength,
570
+ extendedTimestamp,
571
+ } = options;
572
+ let version = options.version || VERSION_DEFLATE;
444
573
  const compressed = level !== 0 && !directory;
574
+ const encrypted = Boolean(password && password.length);
445
575
  let rawExtraFieldAES;
446
576
  if (encrypted && !zipCrypto) {
447
577
  rawExtraFieldAES = new Uint8Array(EXTRAFIELD_DATA_AES.length + 2);
@@ -485,27 +615,6 @@ async function createFileEntry(reader, pendingFileEntry, writable, config, optio
485
615
  } else {
486
616
  rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array();
487
617
  }
488
- const fileEntry = {
489
- lock: pendingFileEntry.lock,
490
- version: version || VERSION_DEFLATE,
491
- versionMadeBy,
492
- zip64,
493
- directory: Boolean(directory),
494
- filenameUTF8: true,
495
- rawFilename,
496
- commentUTF8: true,
497
- rawComment,
498
- rawExtraFieldZip64: zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array(),
499
- rawExtraFieldExtendedTimestamp,
500
- rawExtraFieldNTFS,
501
- rawExtraFieldAES,
502
- rawExtraField,
503
- extendedTimestamp,
504
- msDosCompatible,
505
- internalFileAttribute,
506
- externalFileAttribute
507
- };
508
- let uncompressedSize = fileEntry.uncompressedSize = 0;
509
618
  let bitFlag = BITFLAG_LANG_ENCODING_FLAG;
510
619
  if (dataDescriptor) {
511
620
  bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
@@ -515,22 +624,21 @@ async function createFileEntry(reader, pendingFileEntry, writable, config, optio
515
624
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
516
625
  }
517
626
  if (zip64) {
518
- fileEntry.version = fileEntry.version > VERSION_ZIP64 ? fileEntry.version : VERSION_ZIP64;
627
+ version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
519
628
  }
520
629
  if (encrypted) {
521
630
  bitFlag = bitFlag | BITFLAG_ENCRYPTED;
522
631
  if (!zipCrypto) {
523
- fileEntry.version = fileEntry.version > VERSION_AES ? fileEntry.version : VERSION_AES;
632
+ version = version > VERSION_AES ? version : VERSION_AES;
524
633
  compressionMethod = COMPRESSION_METHOD_AES;
525
634
  if (compressed) {
526
- fileEntry.rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
635
+ rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
527
636
  }
528
637
  }
529
638
  }
530
- fileEntry.compressionMethod = compressionMethod;
531
- const headerArray = fileEntry.headerArray = new Uint8Array(26);
639
+ const headerArray = new Uint8Array(26);
532
640
  const headerView = getDataView(headerArray);
533
- setUint16(headerView, 0, fileEntry.version);
641
+ setUint16(headerView, 0, version);
534
642
  setUint16(headerView, 2, bitFlag);
535
643
  setUint16(headerView, 4, compressionMethod);
536
644
  const dateArray = new Uint32Array(1);
@@ -559,39 +667,28 @@ async function createFileEntry(reader, pendingFileEntry, writable, config, optio
559
667
  arraySet(localHeaderArray, rawExtraFieldExtendedTimestamp, 30 + rawFilename.length + rawExtraFieldAES.length);
560
668
  arraySet(localHeaderArray, rawExtraFieldNTFS, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length);
561
669
  arraySet(localHeaderArray, rawExtraField, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length);
562
- let result;
563
- let compressedSize = 0;
564
- fileEntry.writingData = pendingFileEntry.writingData = true;
565
- if (reader) {
566
- reader.chunkSize = getChunkSize(config);
567
- await writeData(writable, localHeaderArray);
568
- const size = () => reader.size;
569
- const readable = reader.readable;
570
- readable.size = size;
571
- const workerOptions = {
572
- options: {
573
- codecType: CODEC_DEFLATE,
574
- level,
575
- password,
576
- encryptionStrength,
577
- zipCrypto: encrypted && zipCrypto,
578
- passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
579
- signed: true,
580
- compressed,
581
- encrypted,
582
- useWebWorkers,
583
- useCompressionStream
584
- },
585
- config,
586
- streamOptions: { signal, size, onstart, onprogress, onend },
587
- codecConstructor: config.Deflate
588
- };
589
- result = await runWorker({ readable, writable }, workerOptions);
590
- uncompressedSize = fileEntry.uncompressedSize = reader.size = readable.size();
591
- compressedSize = result.size;
592
- } else {
593
- await writeData(writable, localHeaderArray);
594
- }
670
+ return {
671
+ localHeaderArray,
672
+ headerArray,
673
+ headerView,
674
+ lastModDate,
675
+ rawLastModDate,
676
+ encrypted,
677
+ compressed,
678
+ version,
679
+ compressionMethod,
680
+ rawExtraFieldExtendedTimestamp,
681
+ rawExtraFieldNTFS,
682
+ rawExtraFieldAES
683
+ };
684
+ }
685
+
686
+ function getDataDescriptorInfo(options) {
687
+ const {
688
+ zip64,
689
+ dataDescriptor,
690
+ dataDescriptorSignature
691
+ } = options;
595
692
  let dataDescriptorArray = new Uint8Array();
596
693
  let dataDescriptorView, dataDescriptorOffset = 0;
597
694
  if (dataDescriptor) {
@@ -602,51 +699,61 @@ async function createFileEntry(reader, pendingFileEntry, writable, config, optio
602
699
  setUint32(dataDescriptorView, 0, DATA_DESCRIPTOR_RECORD_SIGNATURE);
603
700
  }
604
701
  }
605
- if (reader) {
606
- const { signature } = result;
607
- if ((!encrypted || zipCrypto) && signature !== undefined) {
608
- setUint32(headerView, 10, signature);
609
- fileEntry.signature = signature;
610
- if (dataDescriptor) {
611
- setUint32(dataDescriptorView, dataDescriptorOffset, signature);
612
- }
613
- }
614
- if (zip64) {
615
- const rawExtraFieldZip64View = getDataView(fileEntry.rawExtraFieldZip64);
616
- setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
617
- setUint16(rawExtraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64);
618
- setUint32(headerView, 14, MAX_32_BITS);
619
- setBigUint64(rawExtraFieldZip64View, 12, BigInt(compressedSize));
620
- setUint32(headerView, 18, MAX_32_BITS);
621
- setBigUint64(rawExtraFieldZip64View, 4, BigInt(uncompressedSize));
622
- if (dataDescriptor) {
623
- setBigUint64(dataDescriptorView, dataDescriptorOffset + 4, BigInt(compressedSize));
624
- setBigUint64(dataDescriptorView, dataDescriptorOffset + 12, BigInt(uncompressedSize));
625
- }
626
- } else {
627
- setUint32(headerView, 14, compressedSize);
628
- setUint32(headerView, 18, uncompressedSize);
629
- if (dataDescriptor) {
630
- setUint32(dataDescriptorView, dataDescriptorOffset + 4, compressedSize);
631
- setUint32(dataDescriptorView, dataDescriptorOffset + 8, uncompressedSize);
632
- }
702
+ return {
703
+ dataDescriptorArray,
704
+ dataDescriptorView,
705
+ dataDescriptorOffset
706
+ };
707
+ }
708
+
709
+ function setEntryInfo(entryInfo, options) {
710
+ const {
711
+ signature,
712
+ rawExtraFieldZip64,
713
+ compressedSize,
714
+ uncompressedSize,
715
+ localHeaderInfo,
716
+ dataDescriptorInfo
717
+ } = entryInfo;
718
+ const {
719
+ headerView,
720
+ encrypted
721
+ } = localHeaderInfo;
722
+ const {
723
+ dataDescriptorView,
724
+ dataDescriptorOffset
725
+ } = dataDescriptorInfo;
726
+ const {
727
+ zip64,
728
+ zipCrypto,
729
+ dataDescriptor
730
+ } = options;
731
+ if ((!encrypted || zipCrypto) && signature !== undefined) {
732
+ setUint32(headerView, 10, signature);
733
+ if (dataDescriptor) {
734
+ setUint32(dataDescriptorView, dataDescriptorOffset, signature);
633
735
  }
634
736
  }
635
- if (dataDescriptor) {
636
- await writeData(writable, dataDescriptorArray);
737
+ if (zip64) {
738
+ const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
739
+ setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
740
+ setUint16(rawExtraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64);
741
+ setUint32(headerView, 14, MAX_32_BITS);
742
+ setBigUint64(rawExtraFieldZip64View, 12, BigInt(compressedSize));
743
+ setUint32(headerView, 18, MAX_32_BITS);
744
+ setBigUint64(rawExtraFieldZip64View, 4, BigInt(uncompressedSize));
745
+ if (dataDescriptor) {
746
+ setBigUint64(dataDescriptorView, dataDescriptorOffset + 4, BigInt(compressedSize));
747
+ setBigUint64(dataDescriptorView, dataDescriptorOffset + 12, BigInt(uncompressedSize));
748
+ }
749
+ } else {
750
+ setUint32(headerView, 14, compressedSize);
751
+ setUint32(headerView, 18, uncompressedSize);
752
+ if (dataDescriptor) {
753
+ setUint32(dataDescriptorView, dataDescriptorOffset + 4, compressedSize);
754
+ setUint32(dataDescriptorView, dataDescriptorOffset + 8, uncompressedSize);
755
+ }
637
756
  }
638
- const length = localHeaderArray.length + compressedSize + dataDescriptorArray.length;
639
- Object.assign(fileEntry, {
640
- compressedSize,
641
- lastModDate,
642
- rawLastModDate,
643
- creationDate,
644
- lastAccessDate,
645
- encrypted,
646
- length,
647
- writingData: false
648
- });
649
- return fileEntry;
650
757
  }
651
758
 
652
759
  async function closeFile(zipWriter, comment, options) {
@@ -784,6 +891,7 @@ function sliceAsArrayBuffer(blob, start, end) {
784
891
  async function writeData(writable, array) {
785
892
  const streamWriter = writable.getWriter();
786
893
  await streamWriter.ready;
894
+ writable.size += array.length;
787
895
  await streamWriter.write(array);
788
896
  streamWriter.releaseLock();
789
897
  }
File without changes
File without changes
File without changes
File without changes
File without changes