@zip.js/zip.js 2.7.73 → 2.8.0

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 (69) hide show
  1. package/deno.json +2 -3
  2. package/dist/README.md +7 -25
  3. package/dist/zip-core.js +5961 -0
  4. package/dist/zip-core.min.js +1 -0
  5. package/dist/{zip-full.js → zip-fs-core.js} +4160 -7358
  6. package/dist/zip-fs-core.min.js +1 -0
  7. package/dist/zip-fs.js +4355 -2542
  8. package/dist/zip-fs.min.js +1 -1
  9. package/dist/zip-module.wasm +0 -0
  10. package/dist/zip-web-worker.js +1 -0
  11. package/dist/zip.js +2647 -2466
  12. package/dist/zip.min.js +1 -1
  13. package/index.cjs +4624 -8659
  14. package/index.d.ts +27 -176
  15. package/index.js +2 -63
  16. package/index.min.js +1 -1
  17. package/lib/core/codec-pool.js +6 -4
  18. package/lib/core/codec-worker.js +37 -20
  19. package/lib/core/configuration.js +16 -37
  20. package/lib/core/io.js +3 -8
  21. package/lib/core/streams/aes-crypto-stream.js +1 -0
  22. package/lib/core/streams/zip-entry-stream.js +19 -11
  23. package/lib/core/streams/zlib/README.md +1 -0
  24. package/lib/core/streams/{stream-adapter.js → zlib/zlib-streams-loader.js} +54 -25
  25. package/lib/core/streams/zlib/zlib-streams.js +184 -0
  26. package/lib/core/streams/zlib/zlib-streams.wasm +0 -0
  27. package/lib/core/util/decode-text.js +1 -1
  28. package/lib/core/util/encode-text.js +1 -0
  29. package/lib/core/util/mini-lz.js +198 -0
  30. package/lib/{z-worker.js → core/web-worker-inline-template.js} +10 -9
  31. package/lib/core/web-worker-inline.js +1 -0
  32. package/lib/core/{z-worker-core.js → web-worker.js} +17 -36
  33. package/lib/core/zip-entry.js +3 -7
  34. package/lib/core/zip-reader.js +11 -4
  35. package/lib/core/zip-writer.js +11 -13
  36. package/lib/{z-worker-bootstrap-pako.js → core/zlib-streams-inline-template.js} +8 -10
  37. package/lib/core/zlib-streams-inline.js +1 -0
  38. package/{index-fflate.js → lib/zip-core.js} +43 -22
  39. package/lib/{z-worker-fflate.js → zip-fs-core.js} +5 -15
  40. package/lib/zip-fs.js +7 -24
  41. package/lib/zip.js +6 -23
  42. package/package.json +5 -19
  43. package/dist/z-worker-fflate.js +0 -1
  44. package/dist/z-worker-pako.js +0 -1
  45. package/dist/z-worker.js +0 -1
  46. package/dist/zip-fs-full.js +0 -12536
  47. package/dist/zip-fs-full.min.js +0 -1
  48. package/dist/zip-full.min.js +0 -1
  49. package/dist/zip-no-worker-deflate.min.js +0 -1
  50. package/dist/zip-no-worker-inflate.min.js +0 -1
  51. package/dist/zip-no-worker.min.js +0 -1
  52. package/lib/core/streams/codecs/deflate.js +0 -2059
  53. package/lib/core/streams/codecs/inflate.js +0 -2163
  54. package/lib/core/util/stream-codec-shim.js +0 -91
  55. package/lib/z-worker-bootstrap-fflate.js +0 -40
  56. package/lib/z-worker-inline-template.js +0 -42
  57. package/lib/z-worker-inline.js +0 -1
  58. package/lib/zip-data-uri.js +0 -56
  59. package/lib/zip-fflate-shim.js +0 -37
  60. package/lib/zip-full-fflate.js +0 -54
  61. package/lib/zip-full.js +0 -55
  62. package/lib/zip-no-worker-deflate.js +0 -42
  63. package/lib/zip-no-worker-fflate-deflate.js +0 -42
  64. package/lib/zip-no-worker-fflate-inflate.js +0 -42
  65. package/lib/zip-no-worker-fflate.js +0 -43
  66. package/lib/zip-no-worker-inflate.js +0 -42
  67. package/lib/zip-no-worker.js +0 -44
  68. /package/lib/core/util/{cp437-decode.js → decode-cp437.js} +0 -0
  69. /package/lib/core/{zip-fs-core.js → zip-fs.js} +0 -0
package/index.d.ts CHANGED
@@ -214,75 +214,56 @@ export interface Configuration extends WorkerConfiguration {
214
214
  */
215
215
  terminateWorkerTimeout?: number;
216
216
  /**
217
- * The URIs of the compression/decompression scripts run in web workers.
217
+ * The URI of the web worker.
218
218
  *
219
- * It allows using alternative deflate implementations or specifying a URL to the worker script if the CSP of the page blocks scripts imported from a Blob URI.
220
- * The properties `deflate` and `inflate` must specify arrays of URLs to import the deflate/inflate web workers, respectively.
221
- * The first URL is relative to the base URI of the document. The other URLs are relative to the URL of the first script. Scripts in the array are executed in order.
222
- * If you only use deflation or inflation, the unused `deflate`/`inflate` property can be omitted.
219
+ * It allows using alternative deflate implementations or specifying a URL to the worker script if the CSP of the page blocks scripts imported from a Data URI.
223
220
  *
224
221
  * Here is an example:
225
222
  * ```
226
223
  * configure({
227
- * workerScripts: {
228
- * deflate: ["library_path/custom-worker.js", "./custom-deflate.js"],
229
- * inflate: ["library_path/custom-worker.js", "./custom-inflate.js"]
230
- * }
224
+ * workerURI: "./custom-deflate.js"
231
225
  * });
232
226
  * ```
233
227
  *
234
- * If the CSP of the page blocks scripts imported from a Blob URI you can use `z-worker.js` from https://github.com/gildas-lormeau/zip.js/tree/master/dist and specify the URL where it can be found.
228
+ * @defaultValue "./core/web-worker.js"
229
+ */
230
+ workerURI?: string;
231
+ /**
232
+ * 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.
235
233
  *
236
- * Here is an example:
237
- * ```
238
- * configure({
239
- * workerScripts: {
240
- * deflate: ["library_path/z-worker.js"],
241
- * inflate: ["library_path/z-worker.js"]
242
- * }
243
- * });
244
- * ```
234
+ * @defaultValue "./core/streams/zlib/zlib-streams.wasm"
245
235
  */
246
- workerScripts?: {
247
- /**
248
- * The URIs of the scripts implementing used for compression.
249
- */
250
- deflate?: string[];
251
- /**
252
- * The URIs of the scripts implementing used for decompression.
253
- */
254
- inflate?: string[];
255
- };
236
+ wasmURI?: string;
256
237
  /**
257
238
  * The size of the chunks in bytes during data compression/decompression.
258
239
  *
259
- * @defaultValue 524288
240
+ * @defaultValue 65536
260
241
  */
261
242
  chunkSize?: number;
262
243
  /**
263
- * The codec implementation used to compress data.
244
+ * The stream implementation used to compress data when `useCompressionStream` is set to `true`.
264
245
  *
265
- * @defaultValue {@link ZipDeflate}
246
+ * @defaultValue {@link CodecStream}
266
247
  */
267
- Deflate?: typeof ZipDeflate;
248
+ CompressionStream?: typeof TransformStreamLike;
268
249
  /**
269
- * The codec implementation used to decompress data.
250
+ * The stream implementation used to decompress data when `useCompressionStream` is set to `true`.
270
251
  *
271
- * @defaultValue {@link ZipInflate}
252
+ * @defaultValue {@link CodecStream}
272
253
  */
273
- Inflate?: typeof ZipInflate;
254
+ DecompressionStream?: typeof TransformStreamLike;
274
255
  /**
275
256
  * The stream implementation used to compress data when `useCompressionStream` is set to `false`.
276
257
  *
277
258
  * @defaultValue {@link CodecStream}
278
259
  */
279
- CompressionStream?: typeof TransformStreamLike;
260
+ CompressionStreamZlib?: typeof TransformStreamLike;
280
261
  /**
281
262
  * The stream implementation used to decompress data when `useCompressionStream` is set to `false`.
282
263
  *
283
264
  * @defaultValue {@link CodecStream}
284
265
  */
285
- DecompressionStream?: typeof TransformStreamLike;
266
+ DecompressionStreamZlib?: typeof TransformStreamLike;
286
267
  }
287
268
 
288
269
  /**
@@ -303,128 +284,11 @@ export interface WorkerConfiguration {
303
284
  useCompressionStream?: boolean;
304
285
  }
305
286
 
306
- /**
307
- * Transforms event-based third-party codec implementations into implementations compatible with zip.js
308
- *
309
- * @param library The third-party codec implementations.
310
- * @param constructorOptions The options passed to the third-party implementations when building instances.
311
- * @param registerDataHandler The function called to handle the `data` events triggered by a third-party codec implementation.
312
- * @returns An instance containing classes compatible with {@link ZipDeflate} and {@link ZipInflate}.
313
- */
314
- export function initShimAsyncCodec(
315
- library: EventBasedZipLibrary,
316
- constructorOptions: unknown | null,
317
- registerDataHandler: registerDataHandler
318
- ): ZipLibrary;
319
-
320
- /**
321
- * Represents the callback function used to register the `data` event handler.
322
- */
323
- export interface registerDataHandler {
324
- /**
325
- * @param codec The third-party codec instance.
326
- * @param onData The `data` event handler.
327
- */
328
- (codec: EventBasedCodec, onData: dataHandler): void;
329
- }
330
-
331
- /**
332
- * Represents the callback function used to handle `data` events.
333
- */
334
- export interface dataHandler {
335
- /**
336
- * @param data The processed chunk of data.
337
- */
338
- (data: Uint8Array): void;
339
- }
340
-
341
287
  /**
342
288
  * Terminates all the web workers
343
289
  */
344
290
  export function terminateWorkers(): Promise<void>;
345
291
 
346
- /**
347
- * Represents event-based implementations used to compress/decompress data.
348
- */
349
- export interface EventBasedZipLibrary {
350
- /**
351
- * The class used to compress data.
352
- */
353
- Deflate: typeof EventBasedCodec;
354
- /**
355
- * The class used to decompress data.
356
- */
357
- Inflate: typeof EventBasedCodec;
358
- }
359
-
360
- /**
361
- * Represents an event-based implementation of a third-party codec.
362
- */
363
- declare class EventBasedCodec {
364
- /**
365
- * Appends a chunk of data to compress/decompress
366
- *
367
- * @param data The chunk of data to append.
368
- */
369
- push(data: Uint8Array): void;
370
- /**
371
- * The function called when a chunk of data has been compressed/decompressed.
372
- *
373
- * @param data The chunk of compressed/decompressed data.
374
- */
375
- ondata(data?: Uint8Array): void;
376
- }
377
-
378
- /**
379
- * Represents the implementations zip.js uses to compress/decompress data.
380
- */
381
- export interface ZipLibrary {
382
- /**
383
- * The class used to compress data.
384
- *
385
- * @defaultValue {@link ZipDeflate}
386
- */
387
- Deflate: typeof ZipDeflate;
388
- /**
389
- * The class used to decompress data.
390
- *
391
- * @defaultValue {@link ZipInflate}
392
- */
393
- Inflate: typeof ZipInflate;
394
- }
395
-
396
- declare class SyncCodec {
397
- /**
398
- * Appends a chunk of decompressed data to compress
399
- *
400
- * @param data The chunk of decompressed data to append.
401
- * @returns A chunk of compressed data.
402
- */
403
- append(data: Uint8Array): Uint8Array;
404
- }
405
-
406
- /**
407
- * Represents an instance used to compress data.
408
- */
409
- declare class ZipDeflate extends SyncCodec {
410
- /**
411
- * Flushes the data
412
- *
413
- * @returns A chunk of compressed data.
414
- */
415
- flush(): Uint8Array;
416
- }
417
-
418
- /**
419
- * Represents a codec used to decompress data.
420
- */
421
- declare class ZipInflate extends SyncCodec {
422
- /**
423
- * Flushes the data
424
- */
425
- flush(): void;
426
- }
427
-
428
292
  /**
429
293
  * Represents a class implementing `CompressionStream` or `DecompressionStream` interfaces.
430
294
  */
@@ -538,13 +402,6 @@ export class Data64URIReader extends Reader<string> {}
538
402
  */
539
403
  export class Uint8ArrayReader extends Reader<Uint8Array> {}
540
404
 
541
- /**
542
- * Represents a {@link Reader} instance used to read data provided as an array of {@link ReadableReader} instances (e.g. split zip files).
543
- *
544
- * @deprecated Use {@link SplitDataReader} instead.
545
- */
546
- export class SplitZipReader extends SplitDataReader {}
547
-
548
405
  /**
549
406
  * Represents a {@link Reader} instance used to read data provided as an array of {@link ReadableReader} instances (e.g. split zip files).
550
407
  */
@@ -748,13 +605,6 @@ export class Data64URIWriter extends Writer<string> {
748
605
  constructor(mimeString?: string);
749
606
  }
750
607
 
751
- /**
752
- * Represents a {@link Writer} instance used to retrieve the written data from a generator of {@link WritableWriter} instances (i.e. split zip files).
753
- *
754
- * @deprecated Use {@link SplitDataWriter} instead.
755
- */
756
- export class SplitZipWriter extends SplitDataWriter {}
757
-
758
608
  /**
759
609
  * Represents a {@link Writer} instance used to retrieve the written data from a generator of {@link WritableWriter} instances (i.e. split zip files).
760
610
  */
@@ -1045,10 +895,6 @@ export interface EntryMetaData {
1045
895
  * `true` if the filename is encoded in UTF-8.
1046
896
  */
1047
897
  filenameUTF8: boolean;
1048
- /**
1049
- * `true` if the entry is a directory.
1050
- */
1051
- directory: boolean;
1052
898
  /**
1053
899
  * `true` if the entry is an executable file
1054
900
  */
@@ -1163,12 +1009,17 @@ export interface EntryMetaData {
1163
1009
  */
1164
1010
  compressionMethod: number;
1165
1011
  }
1166
- export interface DirectoryEntry extends Omit<EntryMetaData, "directory"> {
1012
+ export interface DirectoryEntry extends EntryMetaData {
1013
+ /**
1014
+ * `true` if the entry is a directory.
1015
+ */
1167
1016
  directory: true;
1168
- getData?: undefined;
1169
1017
  }
1170
1018
 
1171
- export interface FileEntry extends Omit<EntryMetaData, "directory"> {
1019
+ export interface FileEntry extends EntryMetaData {
1020
+ /**
1021
+ * `false` if the entry is a file.
1022
+ */
1172
1023
  directory: false;
1173
1024
  /**
1174
1025
  * Returns the content of the entry
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="./index.d.ts" />
2
2
 
3
3
  /*
4
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
4
+ Copyright (c) 2025 Gildas Lormeau. All rights reserved.
5
5
 
6
6
  Redistribution and use in source and binary forms, with or without
7
7
  modification, are permitted provided that the following conditions are met:
@@ -28,65 +28,4 @@
28
28
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
29
  */
30
30
 
31
- import { Deflate } from "./lib/core/streams/codecs/deflate.js";
32
- import { Inflate } from "./lib/core/streams/codecs/inflate.js";
33
- import { configure } from "./lib/core/configuration.js";
34
- import { getMimeType } from "./lib/core/util/mime-type.js";
35
- import { terminateWorkers } from "./lib/core/codec-pool.js";
36
-
37
- configure({ Deflate, Inflate });
38
-
39
- export {
40
- fs,
41
- configure,
42
- initShimAsyncCodec,
43
- ZipReader,
44
- ZipWriter,
45
- ZipReaderStream,
46
- ZipWriterStream,
47
- Reader,
48
- Writer,
49
- TextReader,
50
- TextWriter,
51
- Data64URIReader,
52
- Data64URIWriter,
53
- BlobReader,
54
- BlobWriter,
55
- HttpReader,
56
- HttpRangeReader,
57
- Uint8ArrayWriter,
58
- Uint8ArrayReader,
59
- SplitZipReader,
60
- SplitZipWriter,
61
- SplitDataReader,
62
- SplitDataWriter,
63
- ERR_HTTP_RANGE,
64
- ERR_BAD_FORMAT,
65
- ERR_EOCDR_NOT_FOUND,
66
- ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND,
67
- ERR_CENTRAL_DIRECTORY_NOT_FOUND,
68
- ERR_LOCAL_FILE_HEADER_NOT_FOUND,
69
- ERR_EXTRAFIELD_ZIP64_NOT_FOUND,
70
- ERR_ENCRYPTED,
71
- ERR_UNSUPPORTED_ENCRYPTION,
72
- ERR_UNSUPPORTED_COMPRESSION,
73
- ERR_INVALID_SIGNATURE,
74
- ERR_INVALID_UNCOMPRESSED_SIZE,
75
- ERR_INVALID_PASSWORD,
76
- ERR_DUPLICATED_NAME,
77
- ERR_INVALID_COMMENT,
78
- ERR_INVALID_ENTRY_NAME,
79
- ERR_INVALID_ENTRY_COMMENT,
80
- ERR_INVALID_VERSION,
81
- ERR_INVALID_EXTRAFIELD_TYPE,
82
- ERR_INVALID_EXTRAFIELD_DATA,
83
- ERR_INVALID_ENCRYPTION_STRENGTH,
84
- ERR_UNSUPPORTED_FORMAT,
85
- ERR_UNDEFINED_UNCOMPRESSED_SIZE,
86
- ERR_ZIP_NOT_EMPTY,
87
- ERR_SPLIT_ZIP_FILE,
88
- ERR_OVERLAPPING_ENTRY,
89
- ERR_ITERATOR_COMPLETED_TOO_SOON,
90
- ERR_WRITER_NOT_INITIALIZED
91
- } from "./lib/zip-fs.js";
92
- export { getMimeType, terminateWorkers };
31
+ export * from "./lib/zip-fs.js";