@zip.js/zip.js 2.8.44 → 2.8.46

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 (61) hide show
  1. package/README.md +28 -2
  2. package/deno.json +32 -2
  3. package/dist/zip-core-external.js +199 -149
  4. package/dist/zip-core-external.min.js +1 -1
  5. package/dist/zip-core.js +196 -120
  6. package/dist/zip-core.min.js +1 -1
  7. package/dist/zip-fs-core-external.js +251 -157
  8. package/dist/zip-fs-core-external.min.js +1 -1
  9. package/dist/zip-fs-core.js +227 -126
  10. package/dist/zip-fs-core.min.js +1 -1
  11. package/dist/zip-fs-external.js +272 -1751
  12. package/dist/zip-fs-external.min.js +1 -1
  13. package/dist/zip-fs-native.js +273 -1726
  14. package/dist/zip-fs-native.min.js +1 -1
  15. package/dist/zip-fs.js +273 -1726
  16. package/dist/zip-fs.min.js +1 -1
  17. package/dist/zip-legacy.js +198 -122
  18. package/dist/zip-legacy.min.js +1 -1
  19. package/dist/zip-native.js +200 -124
  20. package/dist/zip-native.min.js +1 -1
  21. package/dist/zip-web-worker-native.js +1 -1
  22. package/dist/zip-web-worker.js +1 -1
  23. package/dist/zip.js +200 -124
  24. package/dist/zip.min.js +1 -1
  25. package/eslint.config.mjs +31 -2
  26. package/index-native.cjs +273 -1726
  27. package/index-native.min.js +1 -1
  28. package/index.cjs +273 -1726
  29. package/index.d.cts +140 -2
  30. package/index.d.ts +140 -2
  31. package/index.min.js +1 -1
  32. package/lib/core/codec-pool.js +3 -2
  33. package/lib/core/codec-worker.js +30 -14
  34. package/lib/core/configuration.js +20 -2
  35. package/lib/core/constants.js +4 -0
  36. package/lib/core/options.js +2 -0
  37. package/lib/core/streams/aes-crypto-stream.js +15 -18
  38. package/lib/core/streams/codec-stream.js +2 -2
  39. package/lib/core/streams/zip-entry-stream.js +13 -18
  40. package/lib/core/util/mime-type-data.js +3 -0
  41. package/lib/core/util/mime-type.js +23 -1596
  42. package/lib/core/web-worker-base.js +29 -2
  43. package/lib/core/web-worker-inline-native.js +1 -1
  44. package/lib/core/web-worker-inline-wasm.js +1 -1
  45. package/lib/core/web-worker-native.js +7 -9
  46. package/lib/core/web-worker-wasm.js +9 -12
  47. package/lib/core/zip-entry.js +8 -1
  48. package/lib/core/zip-fs.js +62 -5
  49. package/lib/core/zip-reader.js +45 -17
  50. package/lib/core/zip-writer.js +58 -44
  51. package/lib/{core/web-worker-inline-template.js → zip-core-custom.js} +13 -20
  52. package/lib/zip-core-external.js +2 -0
  53. package/lib/zip-fs-core-external.js +2 -0
  54. package/lib/zip-fs-external.js +2 -0
  55. package/lib/zip-mime-types.js +2 -0
  56. package/lib/zip-module-native.js +3 -3
  57. package/lib/zip-module-wasm-base.js +3 -3
  58. package/package.json +28 -4
  59. package/worker-message-property-names.js +1 -1
  60. package/lib/core/web-worker-inline-template-native.js +0 -48
  61. package/lib/core/zlib-streams-inline-template.js +0 -45
package/index.d.cts CHANGED
@@ -314,6 +314,19 @@ export interface Configuration extends WorkerConfiguration {
314
314
  * @defaultValue "./core/web-worker.js"
315
315
  */
316
316
  workerURI?: string;
317
+ /**
318
+ * The function used to create the web workers, taking precedence over `workerURI`.
319
+ *
320
+ * It lets bundlers detect the worker script statically and compile it with its imports, e.g. a custom worker script embedding alternative compression streams.
321
+ *
322
+ * Here is an example with a custom worker script (see {@link initWorker} for the content of the script):
323
+ * ```
324
+ * configure({
325
+ * createWorker: () => new Worker(new URL("./zip-worker.js", import.meta.url), { type: "module" })
326
+ * });
327
+ * ```
328
+ */
329
+ createWorker?: () => Worker;
317
330
  /**
318
331
  * The URI of the WebAssembly module used by default implementations to compress/decompress data. It is ignored if `useCompressionStream` is set to `true` and `CompressionStream`/`DecompressionStream` are supported by the environment.
319
332
  *
@@ -352,12 +365,20 @@ export interface Configuration extends WorkerConfiguration {
352
365
  *
353
366
  * @defaultValue {@link CodecStream}
354
367
  */
355
- CompressionStreamZlib?: typeof TransformStreamLike;
368
+ CompressionStreamFallback?: typeof TransformStreamLike;
356
369
  /**
357
370
  * The stream implementation used to decompress data when `useCompressionStream` is set to `false`.
358
371
  *
359
372
  * @defaultValue {@link CodecStream}
360
373
  */
374
+ DecompressionStreamFallback?: typeof TransformStreamLike;
375
+ /**
376
+ * @deprecated Use {@link Configuration#CompressionStreamFallback} instead.
377
+ */
378
+ CompressionStreamZlib?: typeof TransformStreamLike;
379
+ /**
380
+ * @deprecated Use {@link Configuration#DecompressionStreamFallback} instead.
381
+ */
361
382
  DecompressionStreamZlib?: typeof TransformStreamLike;
362
383
  }
363
384
 
@@ -390,6 +411,75 @@ export interface WorkerConfiguration {
390
411
  */
391
412
  export function terminateWorkers(): Promise<void>;
392
413
 
414
+ /**
415
+ * Initializes a custom web worker script. This function is exposed by the `@zip.js/zip.js/worker` entry point and must be called
416
+ * in the worker script created by {@link Configuration#createWorker} or referenced by {@link Configuration#workerURI}.
417
+ *
418
+ * Here is a complete example of a worker script using fflate as the compression engine, e.g. to reduce the bundle size:
419
+ * ```
420
+ * import { initWorker } from "@zip.js/zip.js/worker";
421
+ * import { Deflate, Inflate } from "fflate";
422
+ *
423
+ * const FORMAT_DEFLATE_RAW = "deflate-raw";
424
+ *
425
+ * class FflateStream extends TransformStream {
426
+ * constructor(codec) {
427
+ * super({
428
+ * start(controller) {
429
+ * codec.ondata = chunk => {
430
+ * if (chunk.length) {
431
+ * controller.enqueue(chunk);
432
+ * }
433
+ * };
434
+ * },
435
+ * transform(chunk) {
436
+ * codec.push(chunk);
437
+ * },
438
+ * flush() {
439
+ * codec.push(new Uint8Array(0), true);
440
+ * }
441
+ * });
442
+ * }
443
+ * }
444
+ *
445
+ * class CompressionStreamFallback extends FflateStream {
446
+ * constructor(format, { level } = {}) {
447
+ * checkFormat(format);
448
+ * super(new Deflate(level === undefined ? {} : { level }));
449
+ * }
450
+ * }
451
+ *
452
+ * class DecompressionStreamFallback extends FflateStream {
453
+ * constructor(format) {
454
+ * checkFormat(format);
455
+ * super(new Inflate());
456
+ * }
457
+ * }
458
+ *
459
+ * function checkFormat(format) {
460
+ * if (format != FORMAT_DEFLATE_RAW) {
461
+ * throw new TypeError("Unsupported compression format: " + format);
462
+ * }
463
+ * }
464
+ *
465
+ * initWorker({ CompressionStreamFallback, DecompressionStreamFallback });
466
+ * ```
467
+ */
468
+ export function initWorker(options?: {
469
+ /**
470
+ * The stream implementation used to compress data when `useCompressionStream` is set to `false` or when `CompressionStream` is unsupported.
471
+ */
472
+ CompressionStreamFallback?: typeof TransformStreamLike;
473
+ /**
474
+ * The stream implementation used to decompress data when `useCompressionStream` is set to `false` or when `DecompressionStream` is unsupported.
475
+ */
476
+ DecompressionStreamFallback?: typeof TransformStreamLike;
477
+ /**
478
+ * The function called before resolving the stream implementations, e.g. to load a WebAssembly module.
479
+ */
480
+ init?(config: Configuration): Promise<unknown> | unknown;
481
+ }): void;
482
+
393
483
  /**
394
484
  * Represents a class implementing `CompressionStream` or `DecompressionStream` interfaces.
395
485
  */
@@ -1292,6 +1382,30 @@ export interface EntryExtraFieldAES extends EntryExtraField {
1292
1382
  */
1293
1383
  originalCompressionMethod?: number;
1294
1384
  }
1385
+ /**
1386
+ * Represents a Unix extra field record storing timestamps: the Info-ZIP Unix type 1 extra field (0x5855),
1387
+ * written notably by macOS Archive Utility and `ditto`, or the PKWARE Unix extra field (0x000d). Both store
1388
+ * the last access/modification dates as 32-bit Unix times, followed by the optional uid/gid in the local
1389
+ * file header.
1390
+ */
1391
+ export interface EntryExtraFieldUnixDates extends EntryExtraField {
1392
+ /**
1393
+ * The last access date.
1394
+ */
1395
+ lastAccessDate?: Date;
1396
+ /**
1397
+ * The last modification date.
1398
+ */
1399
+ lastModDate?: Date;
1400
+ /**
1401
+ * The Unix user id.
1402
+ */
1403
+ uid?: number;
1404
+ /**
1405
+ * The Unix group id.
1406
+ */
1407
+ gid?: number;
1408
+ }
1295
1409
  /**
1296
1410
  * Represents a Unicode path or comment extra field record of an entry.
1297
1411
  */
@@ -1387,6 +1501,14 @@ export interface LocalDirectory {
1387
1501
  * The Info-ZIP Unix extra field.
1388
1502
  */
1389
1503
  extraFieldInfoZip?: EntryExtraField;
1504
+ /**
1505
+ * The Info-ZIP Unix type 1 extra field (0x5855).
1506
+ */
1507
+ extraFieldUnixType1?: EntryExtraFieldUnixDates;
1508
+ /**
1509
+ * The PKWARE Unix extra field (0x000d).
1510
+ */
1511
+ extraFieldPkwareUnix?: EntryExtraFieldUnixDates;
1390
1512
  /**
1391
1513
  * The extended timestamp extra field.
1392
1514
  */
@@ -1660,6 +1782,14 @@ export interface EntryMetaData {
1660
1782
  * The Info-ZIP Unix extra field.
1661
1783
  */
1662
1784
  extraFieldInfoZip?: EntryExtraField;
1785
+ /**
1786
+ * The Info-ZIP Unix type 1 extra field (0x5855).
1787
+ */
1788
+ extraFieldUnixType1?: EntryExtraFieldUnixDates;
1789
+ /**
1790
+ * The PKWARE Unix extra field (0x000d).
1791
+ */
1792
+ extraFieldPkwareUnix?: EntryExtraFieldUnixDates;
1663
1793
  /**
1664
1794
  * The extended timestamp extra field.
1665
1795
  */
@@ -1968,15 +2098,23 @@ export interface ZipWriterAddDataOptions
1968
2098
  */
1969
2099
  comment?: string;
1970
2100
  /**
1971
- * The extra field of the entry.
2101
+ * The extra field of the entry, written in the local file header and the central directory.
1972
2102
  */
1973
2103
  extraField?: Map<number, Uint8Array>;
2104
+ /**
2105
+ * The extra field of the entry written only in the local file header.
2106
+ */
2107
+ localExtraField?: Map<number, Uint8Array>;
1974
2108
  /**
1975
2109
  * The uncompressed size of the entry. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
1976
2110
  */
1977
2111
  uncompressedSize?: number;
1978
2112
  /**
1979
2113
  * The CRC-32 checksum of the content. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
2114
+ *
2115
+ * When the entry is AES-encrypted (see {@link ZipWriterConstructorOptions#encrypted}), setting this option marks the entry as AE-1
2116
+ * and stores the checksum in the entry headers, e.g. when copying an AE-1 entry read with the
2117
+ * {@link ZipReaderOptions#passThrough} option. Otherwise, the entry is marked as AE-2 and the checksum fields are set to 0.
1980
2118
  */
1981
2119
  crc32?: number;
1982
2120
  /**
package/index.d.ts CHANGED
@@ -314,6 +314,19 @@ export interface Configuration extends WorkerConfiguration {
314
314
  * @defaultValue "./core/web-worker.js"
315
315
  */
316
316
  workerURI?: string;
317
+ /**
318
+ * The function used to create the web workers, taking precedence over `workerURI`.
319
+ *
320
+ * It lets bundlers detect the worker script statically and compile it with its imports, e.g. a custom worker script embedding alternative compression streams.
321
+ *
322
+ * Here is an example with a custom worker script (see {@link initWorker} for the content of the script):
323
+ * ```
324
+ * configure({
325
+ * createWorker: () => new Worker(new URL("./zip-worker.js", import.meta.url), { type: "module" })
326
+ * });
327
+ * ```
328
+ */
329
+ createWorker?: () => Worker;
317
330
  /**
318
331
  * The URI of the WebAssembly module used by default implementations to compress/decompress data. It is ignored if `useCompressionStream` is set to `true` and `CompressionStream`/`DecompressionStream` are supported by the environment.
319
332
  *
@@ -352,12 +365,20 @@ export interface Configuration extends WorkerConfiguration {
352
365
  *
353
366
  * @defaultValue {@link CodecStream}
354
367
  */
355
- CompressionStreamZlib?: typeof TransformStreamLike;
368
+ CompressionStreamFallback?: typeof TransformStreamLike;
356
369
  /**
357
370
  * The stream implementation used to decompress data when `useCompressionStream` is set to `false`.
358
371
  *
359
372
  * @defaultValue {@link CodecStream}
360
373
  */
374
+ DecompressionStreamFallback?: typeof TransformStreamLike;
375
+ /**
376
+ * @deprecated Use {@link Configuration#CompressionStreamFallback} instead.
377
+ */
378
+ CompressionStreamZlib?: typeof TransformStreamLike;
379
+ /**
380
+ * @deprecated Use {@link Configuration#DecompressionStreamFallback} instead.
381
+ */
361
382
  DecompressionStreamZlib?: typeof TransformStreamLike;
362
383
  }
363
384
 
@@ -390,6 +411,75 @@ export interface WorkerConfiguration {
390
411
  */
391
412
  export function terminateWorkers(): Promise<void>;
392
413
 
414
+ /**
415
+ * Initializes a custom web worker script. This function is exposed by the `@zip.js/zip.js/worker` entry point and must be called
416
+ * in the worker script created by {@link Configuration#createWorker} or referenced by {@link Configuration#workerURI}.
417
+ *
418
+ * Here is a complete example of a worker script using fflate as the compression engine, e.g. to reduce the bundle size:
419
+ * ```
420
+ * import { initWorker } from "@zip.js/zip.js/worker";
421
+ * import { Deflate, Inflate } from "fflate";
422
+ *
423
+ * const FORMAT_DEFLATE_RAW = "deflate-raw";
424
+ *
425
+ * class FflateStream extends TransformStream {
426
+ * constructor(codec) {
427
+ * super({
428
+ * start(controller) {
429
+ * codec.ondata = chunk => {
430
+ * if (chunk.length) {
431
+ * controller.enqueue(chunk);
432
+ * }
433
+ * };
434
+ * },
435
+ * transform(chunk) {
436
+ * codec.push(chunk);
437
+ * },
438
+ * flush() {
439
+ * codec.push(new Uint8Array(0), true);
440
+ * }
441
+ * });
442
+ * }
443
+ * }
444
+ *
445
+ * class CompressionStreamFallback extends FflateStream {
446
+ * constructor(format, { level } = {}) {
447
+ * checkFormat(format);
448
+ * super(new Deflate(level === undefined ? {} : { level }));
449
+ * }
450
+ * }
451
+ *
452
+ * class DecompressionStreamFallback extends FflateStream {
453
+ * constructor(format) {
454
+ * checkFormat(format);
455
+ * super(new Inflate());
456
+ * }
457
+ * }
458
+ *
459
+ * function checkFormat(format) {
460
+ * if (format != FORMAT_DEFLATE_RAW) {
461
+ * throw new TypeError("Unsupported compression format: " + format);
462
+ * }
463
+ * }
464
+ *
465
+ * initWorker({ CompressionStreamFallback, DecompressionStreamFallback });
466
+ * ```
467
+ */
468
+ export function initWorker(options?: {
469
+ /**
470
+ * The stream implementation used to compress data when `useCompressionStream` is set to `false` or when `CompressionStream` is unsupported.
471
+ */
472
+ CompressionStreamFallback?: typeof TransformStreamLike;
473
+ /**
474
+ * The stream implementation used to decompress data when `useCompressionStream` is set to `false` or when `DecompressionStream` is unsupported.
475
+ */
476
+ DecompressionStreamFallback?: typeof TransformStreamLike;
477
+ /**
478
+ * The function called before resolving the stream implementations, e.g. to load a WebAssembly module.
479
+ */
480
+ init?(config: Configuration): Promise<unknown> | unknown;
481
+ }): void;
482
+
393
483
  /**
394
484
  * Represents a class implementing `CompressionStream` or `DecompressionStream` interfaces.
395
485
  */
@@ -1292,6 +1382,30 @@ export interface EntryExtraFieldAES extends EntryExtraField {
1292
1382
  */
1293
1383
  originalCompressionMethod?: number;
1294
1384
  }
1385
+ /**
1386
+ * Represents a Unix extra field record storing timestamps: the Info-ZIP Unix type 1 extra field (0x5855),
1387
+ * written notably by macOS Archive Utility and `ditto`, or the PKWARE Unix extra field (0x000d). Both store
1388
+ * the last access/modification dates as 32-bit Unix times, followed by the optional uid/gid in the local
1389
+ * file header.
1390
+ */
1391
+ export interface EntryExtraFieldUnixDates extends EntryExtraField {
1392
+ /**
1393
+ * The last access date.
1394
+ */
1395
+ lastAccessDate?: Date;
1396
+ /**
1397
+ * The last modification date.
1398
+ */
1399
+ lastModDate?: Date;
1400
+ /**
1401
+ * The Unix user id.
1402
+ */
1403
+ uid?: number;
1404
+ /**
1405
+ * The Unix group id.
1406
+ */
1407
+ gid?: number;
1408
+ }
1295
1409
  /**
1296
1410
  * Represents a Unicode path or comment extra field record of an entry.
1297
1411
  */
@@ -1387,6 +1501,14 @@ export interface LocalDirectory {
1387
1501
  * The Info-ZIP Unix extra field.
1388
1502
  */
1389
1503
  extraFieldInfoZip?: EntryExtraField;
1504
+ /**
1505
+ * The Info-ZIP Unix type 1 extra field (0x5855).
1506
+ */
1507
+ extraFieldUnixType1?: EntryExtraFieldUnixDates;
1508
+ /**
1509
+ * The PKWARE Unix extra field (0x000d).
1510
+ */
1511
+ extraFieldPkwareUnix?: EntryExtraFieldUnixDates;
1390
1512
  /**
1391
1513
  * The extended timestamp extra field.
1392
1514
  */
@@ -1660,6 +1782,14 @@ export interface EntryMetaData {
1660
1782
  * The Info-ZIP Unix extra field.
1661
1783
  */
1662
1784
  extraFieldInfoZip?: EntryExtraField;
1785
+ /**
1786
+ * The Info-ZIP Unix type 1 extra field (0x5855).
1787
+ */
1788
+ extraFieldUnixType1?: EntryExtraFieldUnixDates;
1789
+ /**
1790
+ * The PKWARE Unix extra field (0x000d).
1791
+ */
1792
+ extraFieldPkwareUnix?: EntryExtraFieldUnixDates;
1663
1793
  /**
1664
1794
  * The extended timestamp extra field.
1665
1795
  */
@@ -1968,15 +2098,23 @@ export interface ZipWriterAddDataOptions
1968
2098
  */
1969
2099
  comment?: string;
1970
2100
  /**
1971
- * The extra field of the entry.
2101
+ * The extra field of the entry, written in the local file header and the central directory.
1972
2102
  */
1973
2103
  extraField?: Map<number, Uint8Array>;
2104
+ /**
2105
+ * The extra field of the entry written only in the local file header.
2106
+ */
2107
+ localExtraField?: Map<number, Uint8Array>;
1974
2108
  /**
1975
2109
  * The uncompressed size of the entry. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
1976
2110
  */
1977
2111
  uncompressedSize?: number;
1978
2112
  /**
1979
2113
  * The CRC-32 checksum of the content. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
2114
+ *
2115
+ * When the entry is AES-encrypted (see {@link ZipWriterConstructorOptions#encrypted}), setting this option marks the entry as AE-1
2116
+ * and stores the checksum in the entry headers, e.g. when copying an AE-1 entry read with the
2117
+ * {@link ZipReaderOptions#passThrough} option. Otherwise, the entry is marked as AE-2 and the checksum fields are set to 0.
1980
2118
  */
1981
2119
  crc32?: number;
1982
2120
  /**