@zip.js/zip.js 2.8.46 → 2.8.48

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 (50) hide show
  1. package/deno.json +1 -1
  2. package/dist/zip-core-external.js +130 -35
  3. package/dist/zip-core-external.min.js +1 -1
  4. package/dist/zip-core.js +140 -34
  5. package/dist/zip-core.min.js +1 -1
  6. package/dist/zip-fs-core-external.js +131 -36
  7. package/dist/zip-fs-core-external.min.js +1 -1
  8. package/dist/zip-fs-core.js +115 -32
  9. package/dist/zip-fs-core.min.js +1 -1
  10. package/dist/zip-fs-external.js +131 -36
  11. package/dist/zip-fs-external.min.js +1 -1
  12. package/dist/zip-fs-native.js +145 -37
  13. package/dist/zip-fs-native.min.js +1 -1
  14. package/dist/zip-fs.js +144 -36
  15. package/dist/zip-fs.min.js +1 -1
  16. package/dist/zip-legacy.js +142 -36
  17. package/dist/zip-legacy.min.js +1 -1
  18. package/dist/zip-native.js +142 -36
  19. package/dist/zip-native.min.js +1 -1
  20. package/dist/zip-web-worker-native.js +1 -1
  21. package/dist/zip-web-worker.js +1 -1
  22. package/dist/zip.js +141 -35
  23. package/dist/zip.min.js +1 -1
  24. package/index-native.cjs +145 -37
  25. package/index-native.min.js +1 -1
  26. package/index.cjs +144 -36
  27. package/index.d.cts +141 -0
  28. package/index.d.ts +141 -0
  29. package/index.min.js +1 -1
  30. package/lib/core/codec-pool.js +6 -3
  31. package/lib/core/codec-worker.js +2 -1
  32. package/lib/core/constants.js +2 -0
  33. package/lib/core/io.js +3 -23
  34. package/lib/core/options.js +4 -0
  35. package/lib/core/streams/codec-stream.js +2 -0
  36. package/lib/core/streams/common-crypto.js +2 -1
  37. package/lib/core/streams/zip-entry-stream.js +4 -2
  38. package/lib/core/util/blob-temp-stream.js +4 -2
  39. package/lib/core/util/compatible-streams.js +30 -2
  40. package/lib/core/util/opfs-temp-stream.js +8 -1
  41. package/lib/core/util/sync-access-handle-temp-stream.js +10 -2
  42. package/lib/core/web-worker-inline-native.js +1 -1
  43. package/lib/core/web-worker-inline-wasm.js +1 -1
  44. package/lib/core/zip-fs.js +3 -2
  45. package/lib/core/zip-reader.js +62 -9
  46. package/lib/core/zip-writer.js +43 -8
  47. package/lib/zip-core-base.js +2 -1
  48. package/lib/zip-core-reader.js +2 -1
  49. package/lib/zip-core-writer.js +10 -1
  50. package/package.json +2 -1
@@ -38,6 +38,7 @@ const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
38
38
  const SPLIT_ZIP_FILE_SIGNATURE = 0x08074b50;
39
39
  const DATA_DESCRIPTOR_RECORD_SIGNATURE = SPLIT_ZIP_FILE_SIGNATURE;
40
40
  const ARCHIVE_EXTRA_DATA_SIGNATURE = 0x08064b50;
41
+ const DIGITAL_SIGNATURE_RECORD_SIGNATURE = 0x05054b50;
41
42
  const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
42
43
  const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
43
44
  const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
@@ -1900,6 +1901,8 @@ function getInt32(number) {
1900
1901
  */
1901
1902
 
1902
1903
 
1904
+ const HTTP_HEADER_CONTENT_TYPE = "Content-Type";
1905
+
1903
1906
  function toCompatibleReadable(readable) {
1904
1907
  if (readable instanceof ReadableStream) {
1905
1908
  return readable;
@@ -1920,6 +1923,29 @@ function toCompatibleReadable(readable) {
1920
1923
  });
1921
1924
  }
1922
1925
 
1926
+ function streamToBlob(readable, contentType) {
1927
+ readable = toCompatibleReadable(readable);
1928
+ if (responseSupportsGlobalReadable()) {
1929
+ const options = {};
1930
+ if (contentType) {
1931
+ options.headers = [[HTTP_HEADER_CONTENT_TYPE, contentType]];
1932
+ }
1933
+ return new Response(readable, options).blob();
1934
+ }
1935
+ const chunks = [];
1936
+ return readable
1937
+ .pipeTo(new WritableStream({
1938
+ write(chunk) {
1939
+ chunks.push(chunk);
1940
+ }
1941
+ }))
1942
+ .then(() => new Blob(chunks, contentType ? { type: contentType } : {}));
1943
+ }
1944
+
1945
+ function responseSupportsGlobalReadable() {
1946
+ return typeof Blob.prototype.stream != FUNCTION_TYPE || new Blob([]).stream() instanceof ReadableStream;
1947
+ }
1948
+
1923
1949
  function toCompatibleWritable(writable) {
1924
1950
  if (writable instanceof WritableStream) {
1925
1951
  return writable;
@@ -3263,7 +3289,6 @@ const HTTP_HEADER_CONTENT_ENCODING = "Content-Encoding";
3263
3289
  const HTTP_HEADER_CONTENT_RANGE = "Content-Range";
3264
3290
  const HTTP_HEADER_ACCEPT_RANGES = "Accept-Ranges";
3265
3291
  const HTTP_HEADER_RANGE = "Range";
3266
- const HTTP_HEADER_CONTENT_TYPE = "Content-Type";
3267
3292
  const HTTP_HEADER_ETAG = "Etag";
3268
3293
  const HTTP_HEADER_LAST_MODIFIED = "Last-Modified";
3269
3294
  const HTTP_METHOD_HEAD = "HEAD";
@@ -3468,10 +3493,6 @@ class BlobReader extends Reader {
3468
3493
  }
3469
3494
  }
3470
3495
 
3471
- function responseSupportsGlobalReadable() {
3472
- return typeof Blob.prototype.stream != FUNCTION_TYPE || new Blob([]).stream() instanceof ReadableStream;
3473
- }
3474
-
3475
3496
  class BlobWriter extends Stream {
3476
3497
 
3477
3498
  constructor(contentType) {
@@ -3483,22 +3504,7 @@ class BlobWriter extends Stream {
3483
3504
  return transformStream.writable;
3484
3505
  }
3485
3506
  });
3486
- if (responseSupportsGlobalReadable()) {
3487
- const headers = [];
3488
- if (contentType) {
3489
- headers.push([HTTP_HEADER_CONTENT_TYPE, contentType]);
3490
- }
3491
- writer.blob = new Response(transformStream.readable, { headers }).blob();
3492
- } else {
3493
- const chunks = [];
3494
- writer.blob = transformStream.readable
3495
- .pipeTo(new WritableStream({
3496
- write(chunk) {
3497
- chunks.push(chunk);
3498
- }
3499
- }))
3500
- .then(() => new Blob(chunks, { type: contentType }));
3501
- }
3507
+ writer.blob = streamToBlob(transformStream.readable, contentType);
3502
3508
  writer.blob.catch(() => { });
3503
3509
  }
3504
3510
 
@@ -4485,6 +4491,8 @@ const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
4485
4491
  const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
4486
4492
  const OPTION_STRICTNESS = "strictness";
4487
4493
  const OPTION_MAX_APPENDED_DATA_SIZE = "maxAppendedDataSize";
4494
+ const OPTION_DECRYPT_CENTRAL_DIRECTORY = "decryptCentralDirectory";
4495
+ const OPTION_SIGN_CENTRAL_DIRECTORY = "signCentralDirectory";
4488
4496
  const STRICTNESS_STRICT = "strict";
4489
4497
  const STRICTNESS_BALANCED = "balanced";
4490
4498
  const STRICTNESS_TOLERANT = "tolerant";
@@ -4570,7 +4578,7 @@ class ZipReader {
4570
4578
  const { config } = zipReader;
4571
4579
  await initStream(reader);
4572
4580
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
4573
- reader = new BlobReader(await new Response(reader.readable).blob());
4581
+ reader = new BlobReader(await streamToBlob(reader.readable));
4574
4582
  await initStream(reader);
4575
4583
  }
4576
4584
  if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
@@ -4610,6 +4618,7 @@ class ZipReader {
4610
4618
  let startOffset;
4611
4619
  let zip64EndOfDirectory;
4612
4620
  let zip64EndOfDirectoryVersion2;
4621
+ let directoryEncryptionInfo;
4613
4622
  const requiresZip64 = directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS || diskNumber == MAX_16_BITS;
4614
4623
  if (directoryDataOffset != MAX_32_BITS && diskNumber != MAX_16_BITS) {
4615
4624
  directoryDataOffset += getDiskOffset$1(reader, diskNumber);
@@ -4640,6 +4649,15 @@ class ZipReader {
4640
4649
  }
4641
4650
  zip64EndOfDirectory = true;
4642
4651
  zip64EndOfDirectoryVersion2 = getBigUint64(endOfDirectoryView, 4) > ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12;
4652
+ if (zip64EndOfDirectoryVersion2) {
4653
+ const extensibleDataLength = Math.min(
4654
+ Number(getBigUint64(endOfDirectoryView, 4)) - (ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12),
4655
+ reader.size - directoryDataOffset - ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4656
+ if (extensibleDataLength > 0) {
4657
+ const rawExtensibleData = await readUint8Array(reader, directoryDataOffset + ZIP64_END_OF_CENTRAL_DIR_LENGTH, extensibleDataLength);
4658
+ directoryEncryptionInfo = getDirectoryEncryptionInfo(rawExtensibleData);
4659
+ }
4660
+ }
4643
4661
  if (lastDiskNumber == MAX_16_BITS) {
4644
4662
  lastDiskNumber = getUint32(endOfDirectoryView, 16);
4645
4663
  } else if (checkAmbiguity && lastDiskNumber != getUint32(endOfDirectoryView, 16)) {
@@ -4663,7 +4681,7 @@ class ZipReader {
4663
4681
  directoryDataOffset = getDiskOffset$1(reader, diskNumber) + getBigUint64(endOfDirectoryView, 48) + prependedDataLength;
4664
4682
  }
4665
4683
  }
4666
- const declaredDirectoryDataLength = directoryDataLength;
4684
+ let declaredDirectoryDataLength = directoryDataLength;
4667
4685
  const centralDirectoryEndOffset = endOfDirectoryInfo.offset -
4668
4686
  (zip64EndOfDirectory ? ZIP64_END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH : 0);
4669
4687
  if (directoryDataOffset >= reader.size) {
@@ -4711,6 +4729,18 @@ class ZipReader {
4711
4729
  if (directoryDataOffset < 0 || directoryDataOffset >= reader.size) {
4712
4730
  throw new Error(ERR_BAD_FORMAT);
4713
4731
  }
4732
+ zipReader.directoryOffset = directoryDataOffset;
4733
+ zipReader.directoryLength = declaredDirectoryDataLength;
4734
+ const decryptCentralDirectory = getOptionValue$1(zipReader, options, OPTION_DECRYPT_CENTRAL_DIRECTORY);
4735
+ let decryptedDirectory;
4736
+ if (decryptCentralDirectory && filesLength && directoryArray.length >= 4 &&
4737
+ getUint32(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
4738
+ (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4739
+ directoryArray = await decryptCentralDirectory(directoryArray, directoryEncryptionInfo);
4740
+ directoryView = getDataView(directoryArray);
4741
+ declaredDirectoryDataLength = directoryArray.length;
4742
+ decryptedDirectory = true;
4743
+ }
4714
4744
  startOffset = directoryDataOffset;
4715
4745
  const filenameEncoding = getOptionValue$1(zipReader, options, OPTION_FILENAME_ENCODING);
4716
4746
  const commentEncoding = getOptionValue$1(zipReader, options, OPTION_COMMENT_ENCODING);
@@ -4719,7 +4749,7 @@ class ZipReader {
4719
4749
  for (let indexFile = 0; indexFile < filesLength; indexFile++) {
4720
4750
  const fileEntry = new ZipEntry$1(reader, config, zipReader.options);
4721
4751
  if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
4722
- if (indexFile == 0 && (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4752
+ if (indexFile == 0 && !decryptedDirectory && (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4723
4753
  throw new Error(ERR_ENCRYPTED_CENTRAL_DIRECTORY);
4724
4754
  }
4725
4755
  throw new Error(ERR_CENTRAL_DIRECTORY_NOT_FOUND);
@@ -4817,7 +4847,7 @@ class ZipReader {
4817
4847
  entry.arrayBuffer = async options => {
4818
4848
  const writer = new TransformStream();
4819
4849
  const [arrayBuffer] = await Promise.all([
4820
- new Response(writer.readable).arrayBuffer(),
4850
+ streamToBlob(writer.readable).then(blob => blob.arrayBuffer()),
4821
4851
  fileEntry.getData(writer, entry, zipReader.readRanges, options)]);
4822
4852
  return arrayBuffer;
4823
4853
  };
@@ -4832,7 +4862,15 @@ class ZipReader {
4832
4862
  }
4833
4863
  yield entry;
4834
4864
  }
4835
- if (checkAmbiguity && offset != declaredDirectoryDataLength) {
4865
+ let offsetAfterSignature = offset;
4866
+ if (offset + 6 <= directoryArray.length && getUint32(directoryView, offset) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
4867
+ const signatureDataLength = getUint16(directoryView, offset + 4);
4868
+ if (offset + 6 + signatureDataLength <= directoryArray.length) {
4869
+ zipReader.digitalSignature = directoryArray.subarray(offset + 6, offset + 6 + signatureDataLength);
4870
+ offsetAfterSignature = offset + 6 + signatureDataLength;
4871
+ }
4872
+ }
4873
+ if (checkAmbiguity && offset != declaredDirectoryDataLength && offsetAfterSignature != declaredDirectoryDataLength) {
4836
4874
  throwAmbiguousArchive("trailing central directory data");
4837
4875
  }
4838
4876
  if (duplicateFilename) {
@@ -5104,6 +5142,25 @@ function detectEncryptedCentralDirectory(directoryView) {
5104
5142
  return false;
5105
5143
  }
5106
5144
 
5145
+ function getDirectoryEncryptionInfo(rawExtensibleData) {
5146
+ const directoryEncryptionInfo = { rawExtensibleData };
5147
+ if (rawExtensibleData.length >= 28) {
5148
+ const extensibleDataView = getDataView(rawExtensibleData);
5149
+ const hashDataLength = getUint16(extensibleDataView, 26);
5150
+ Object.assign(directoryEncryptionInfo, {
5151
+ compressionMethod: getUint16(extensibleDataView, 0),
5152
+ compressedSize: Number(getBigUint64(extensibleDataView, 2)),
5153
+ uncompressedSize: Number(getBigUint64(extensibleDataView, 10)),
5154
+ encryptionAlgorithm: getUint16(extensibleDataView, 18),
5155
+ bitLength: getUint16(extensibleDataView, 20),
5156
+ flags: getUint16(extensibleDataView, 22),
5157
+ hashAlgorithm: getUint16(extensibleDataView, 24),
5158
+ hashData: rawExtensibleData.subarray(28, 28 + hashDataLength)
5159
+ });
5160
+ }
5161
+ return directoryEncryptionInfo;
5162
+ }
5163
+
5107
5164
  function readCommonHeader(directory, dataView, offset) {
5108
5165
  const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);
5109
5166
  const encrypted = (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED;
@@ -5655,6 +5712,7 @@ var zipReader = /*#__PURE__*/Object.freeze({
5655
5712
  ERR_SPLIT_ZIP_FILE: ERR_SPLIT_ZIP_FILE,
5656
5713
  ERR_UNSUPPORTED_COMPRESSION: ERR_UNSUPPORTED_COMPRESSION$1,
5657
5714
  ERR_UNSUPPORTED_ENCRYPTION: ERR_UNSUPPORTED_ENCRYPTION,
5715
+ ERR_WORKER_STARTUP_TIMEOUT: ERR_WORKER_STARTUP_TIMEOUT,
5658
5716
  ZipReader: ZipReader,
5659
5717
  ZipReaderStream: ZipReaderStream
5660
5718
  });
@@ -5713,6 +5771,7 @@ const ERR_INVALID_UNIX_EXTRA_FIELD_TYPE = "Invalid unixExtraFieldType (must be '
5713
5771
  const ERR_INVALID_UNIX_ID_SIZE = "uid/gid must be 0..65535 for unixExtraFieldType 'unix' (use 'infozip' for larger ids)";
5714
5772
  const ERR_INVALID_MSDOS_ATTRIBUTES = "Invalid msdosAttributesRaw (must be integer 0..255)";
5715
5773
  const ERR_INVALID_MSDOS_DATA = "Invalid msdosAttributes (must be an object with boolean flags)";
5774
+ const ERR_INVALID_SIGNATURE_DATA = "Signature data exceeds 64KB";
5716
5775
 
5717
5776
  const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
5718
5777
  const EXTRAFIELD_OFFSET_AES_VENDOR_VERSION = 4;
@@ -7072,8 +7131,9 @@ function updateLocalHeader({
7072
7131
 
7073
7132
  async function closeFile(zipWriter, comment, options) {
7074
7133
  const directoryDataLength = createDirectoryRecords(zipWriter.files);
7075
- const directoryStart = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7076
- await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryDataLength });
7134
+ const { directoryStart, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7135
+ const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7136
+ await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryDataLength, signatureLength });
7077
7137
  }
7078
7138
 
7079
7139
  function createDirectoryRecords(files) {
@@ -7230,12 +7290,33 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
7230
7290
  }
7231
7291
  }
7232
7292
  await writeData(writer, directoryDiskOffset ? directoryArray.slice(directoryDiskOffset) : directoryArray);
7233
- return { diskNumber: directoryStartDiskNumber, diskOffset: directoryStartDiskOffset };
7293
+ return {
7294
+ directoryStart: { diskNumber: directoryStartDiskNumber, diskOffset: directoryStartDiskOffset },
7295
+ directoryArray
7296
+ };
7297
+ }
7298
+
7299
+ async function writeDigitalSignatureRecord(zipWriter, directoryArray, options) {
7300
+ const signCentralDirectory = getOptionValue(zipWriter, options, OPTION_SIGN_CENTRAL_DIRECTORY);
7301
+ if (signCentralDirectory) {
7302
+ const signatureData = await signCentralDirectory(directoryArray);
7303
+ const signatureDataLength = getLength(signatureData);
7304
+ if (signatureDataLength > MAX_16_BITS) {
7305
+ throw new Error(ERR_INVALID_SIGNATURE_DATA);
7306
+ }
7307
+ const signatureRecord = createRecordWriter(6 + signatureDataLength);
7308
+ signatureRecord.uint32(DIGITAL_SIGNATURE_RECORD_SIGNATURE);
7309
+ signatureRecord.uint16(signatureDataLength);
7310
+ signatureRecord.bytes(signatureData);
7311
+ await writeData(zipWriter.writer, signatureRecord.array);
7312
+ return 6 + signatureDataLength;
7313
+ }
7314
+ return 0;
7234
7315
  }
7235
7316
 
7236
7317
  async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7237
7318
  const { writer } = zipWriter;
7238
- const { directoryStart } = cdInfo;
7319
+ const { directoryStart, signatureLength } = cdInfo;
7239
7320
  let { directoryDataLength } = cdInfo;
7240
7321
  let filesLength = zipWriter.files.size;
7241
7322
  let diskNumber = directoryStart.diskNumber;
@@ -7274,7 +7355,7 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7274
7355
  endOfdirectoryRecord.uint64(directoryOffset);
7275
7356
  endOfdirectoryRecord.uint32(ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
7276
7357
  endOfdirectoryRecord.uint32(lastDiskNumber);
7277
- endOfdirectoryRecord.uint64(BigInt(getSegmentOffset(zipWriter, writer)) + BigInt(directoryDataLength));
7358
+ endOfdirectoryRecord.uint64(BigInt(getSegmentOffset(zipWriter, writer)) + BigInt(directoryDataLength) + BigInt(signatureLength));
7278
7359
  endOfdirectoryRecord.uint32(lastDiskNumber + 1);
7279
7360
  const supportZip64SplitFile = getOptionValue(zipWriter, options, OPTION_SUPPORT_ZIP64_SPLIT_FILE, true);
7280
7361
  if (supportZip64SplitFile) {
@@ -7574,7 +7655,7 @@ function createOPFSTempStream(options = {}) {
7574
7655
 
7575
7656
  async function spillToFile() {
7576
7657
  const directoryHandle = await getTempDirectory();
7577
- fileName = crypto.randomUUID();
7658
+ fileName = getRandomFileName$1();
7578
7659
  fileHandle = await directoryHandle.getFileHandle(fileName, { create: true });
7579
7660
  fileWriter = (await fileHandle.createWritable()).getWriter();
7580
7661
  spilled = true;
@@ -7655,6 +7736,13 @@ function createOPFSTempStream(options = {}) {
7655
7736
  };
7656
7737
  }
7657
7738
 
7739
+ function getRandomFileName$1() {
7740
+ if (crypto.randomUUID) {
7741
+ return crypto.randomUUID();
7742
+ }
7743
+ return Array.from(crypto.getRandomValues(new Uint8Array(16)), byteValue => byteValue.toString(16).padStart(2, "0")).join("");
7744
+ }
7745
+
7658
7746
  /*
7659
7747
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
7660
7748
 
@@ -7698,7 +7786,7 @@ function createBlobTempStream(options = {}) {
7698
7786
 
7699
7787
  async function spillToBlob() {
7700
7788
  const transformStream = new TransformStream();
7701
- blobPromise = new Response(transformStream.readable).blob();
7789
+ blobPromise = streamToBlob(transformStream.readable);
7702
7790
  blobWriter = transformStream.writable.getWriter();
7703
7791
  spilled = true;
7704
7792
  for (const chunk of memoryChunks) {
@@ -7838,7 +7926,7 @@ function createSyncAccessHandleTempStream(options = {}) {
7838
7926
 
7839
7927
  async function spillToFile() {
7840
7928
  const directoryHandle = await getTempDirectory();
7841
- fileName = crypto.randomUUID();
7929
+ fileName = getRandomFileName();
7842
7930
  const fileHandle = await directoryHandle.getFileHandle(fileName, { create: true });
7843
7931
  accessHandle = await fileHandle.createSyncAccessHandle();
7844
7932
  spilled = true;
@@ -7918,6 +8006,13 @@ function createSyncAccessHandleTempStream(options = {}) {
7918
8006
  };
7919
8007
  }
7920
8008
 
8009
+ function getRandomFileName() {
8010
+ if (crypto.randomUUID) {
8011
+ return crypto.randomUUID();
8012
+ }
8013
+ return Array.from(crypto.getRandomValues(new Uint8Array(16)), byteValue => byteValue.toString(16).padStart(2, "0")).join("");
8014
+ }
8015
+
7921
8016
  /*
7922
8017
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
7923
8018
 
@@ -8468,7 +8563,7 @@ class ZipFileEntry extends ZipEntry {
8468
8563
  await Promise.all([initStream(reader), initStream(writer, uncompressedSize)]);
8469
8564
  const { readable } = reader;
8470
8565
  zipEntry.uncompressedSize = reader.size;
8471
- await readable.pipeTo(writer.writable);
8566
+ await toCompatibleReadable(readable).pipeTo(toCompatibleWritable(writer.writable));
8472
8567
  return writer.getData ? writer.getData() : writer.writable;
8473
8568
  }
8474
8569
  }
@@ -9388,4 +9483,4 @@ function addChild(parent, name, params, directory) {
9388
9483
  }
9389
9484
  }
9390
9485
 
9391
- export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_AMBIGUOUS_ARCHIVE, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_INVALID_AUTHENTICATION_CODE, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_CRC32, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_PASSWORD, ERR_INVALID_SIGNATURE, ERR_INVALID_UNCOMPRESSED_SIZE, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_RESERVED_COMPRESSION_METHOD, ERR_SPLIT_ZIP_FILE, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNSUPPORTED_COMPRESSION$1 as ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_WRITER_NOT_INITIALIZED, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, Writer, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, fs, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
9486
+ export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_AMBIGUOUS_ARCHIVE, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_ENTRY_EXISTS, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_INVALID_AUTHENTICATION_CODE, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_CRC32, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_GID, ERR_INVALID_MSDOS_ATTRIBUTES, ERR_INVALID_MSDOS_DATA, ERR_INVALID_PASSWORD, ERR_INVALID_SIGNATURE, ERR_INVALID_SIGNATURE_DATA, ERR_INVALID_UID, ERR_INVALID_UNCOMPRESSED_SIZE, ERR_INVALID_UNIX_EXTRA_FIELD_TYPE, ERR_INVALID_UNIX_ID_SIZE, ERR_INVALID_UNIX_MODE, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_READABLE_CONSUMED, ERR_RESERVED_COMPRESSION_METHOD, ERR_SPLIT_ZIP_FILE, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNSUPPORTED_COMPRESSION$1 as ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_CONTEXT, ERR_UNSUPPORTED_CRYPTO_API, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, Writer, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, fs, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };