@zip.js/zip.js 2.8.25 → 2.8.28

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 (52) hide show
  1. package/README.md +2 -2
  2. package/deno.json +1 -1
  3. package/dist/zip-core.js +1050 -569
  4. package/dist/zip-core.min.js +1 -1
  5. package/dist/zip-fs-core.js +1146 -617
  6. package/dist/zip-fs-core.min.js +1 -1
  7. package/dist/zip-fs-native.js +1207 -627
  8. package/dist/zip-fs-native.min.js +1 -1
  9. package/dist/zip-fs.js +1279 -681
  10. package/dist/zip-fs.min.js +1 -1
  11. package/dist/zip-legacy.js +1051 -570
  12. package/dist/zip-legacy.min.js +1 -1
  13. package/dist/zip-module.wasm +0 -0
  14. package/dist/zip-native.js +1053 -572
  15. package/dist/zip-native.min.js +1 -1
  16. package/dist/zip-web-worker-native.js +1 -1
  17. package/dist/zip-web-worker.js +1 -1
  18. package/dist/zip.js +1125 -626
  19. package/dist/zip.min.js +1 -1
  20. package/eslint.config.mjs +6 -1
  21. package/index-native.cjs +1207 -627
  22. package/index-native.min.js +1 -1
  23. package/index.cjs +1279 -681
  24. package/index.d.ts +2451 -2355
  25. package/index.min.js +1 -1
  26. package/lib/core/codec-pool.js +39 -1
  27. package/lib/core/codec-worker.js +120 -34
  28. package/lib/core/configuration.js +3 -0
  29. package/lib/core/constants.js +6 -0
  30. package/lib/core/io.js +55 -25
  31. package/lib/core/options.js +2 -0
  32. package/lib/core/streams/aes-crypto-stream.js +12 -12
  33. package/lib/core/streams/codec-stream.js +11 -5
  34. package/lib/core/streams/codecs/sjcl.js +1 -33
  35. package/lib/core/streams/common-crypto.js +4 -4
  36. package/lib/core/streams/zip-crypto-stream.js +25 -15
  37. package/lib/core/streams/zip-entry-stream.js +35 -1
  38. package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
  39. package/lib/core/streams/zlib-wasm/zlib-streams.js +73 -55
  40. package/lib/core/streams/zlib-wasm/zlib-streams.wasm +0 -0
  41. package/lib/core/util/decode-cp437.js +1 -1
  42. package/lib/core/util/decode-text.js +2 -1
  43. package/lib/core/web-worker-base.js +12 -4
  44. package/lib/core/web-worker-inline-native.js +1 -1
  45. package/lib/core/web-worker-inline-wasm.js +1 -1
  46. package/lib/core/zip-fs.js +154 -55
  47. package/lib/core/zip-reader.js +185 -67
  48. package/lib/core/zip-writer.js +613 -376
  49. package/lib/core/zlib-streams-inline.js +1 -1
  50. package/lib/zip-core-reader.js +3 -1
  51. package/lib/zip-core-writer.js +1 -0
  52. package/package.json +20 -6
package/index.d.ts CHANGED
@@ -1,2355 +1,2451 @@
1
- /**
2
- * zip.js is a JavaScript open-source library (BSD-3-Clause license) for
3
- * compressing and decompressing zip files. It has been designed to handle large amounts
4
- * of data. It supports notably multi-core compression, native compression with
5
- * compression streams, archives larger than 4GB with Zip64, split zip files, data
6
- * encryption, and Deflate64 decompression.
7
- *
8
- * @author Gildas Lormeau
9
- * @license BSD-3-Clause
10
- *
11
- * @example
12
- * Hello world
13
- * ```js
14
- * import {
15
- * BlobReader,
16
- * BlobWriter,
17
- * TextReader,
18
- * TextWriter,
19
- * ZipReader,
20
- * ZipWriter,
21
- * } from from "@zip-js/zip-js";
22
- *
23
- * // ----
24
- * // Write the zip file
25
- * // ----
26
- *
27
- * // Creates a BlobWriter object where the zip content will be written.
28
- * const zipFileWriter = new BlobWriter();
29
- *
30
- * // Creates a TextReader object storing the text of the entry to add in the zip
31
- * // (i.e. "Hello world!").
32
- * const helloWorldReader = new TextReader("Hello world!");
33
- *
34
- * // Creates a ZipWriter object writing data via `zipFileWriter`, adds the entry
35
- * // "hello.txt" containing the text "Hello world!" via `helloWorldReader`, and
36
- * // closes the writer.
37
- * const zipWriter = new ZipWriter(zipFileWriter);
38
- * await zipWriter.add("hello.txt", helloWorldReader);
39
- * await zipWriter.close();
40
- *
41
- * // Retrieves the Blob object containing the zip content into `zipFileBlob`. It
42
- * // is also returned by zipWriter.close() for more convenience.
43
- * const zipFileBlob = await zipFileWriter.getData();
44
- *
45
- * // ----
46
- * // Read the zip file
47
- * // ----
48
- *
49
- * // Creates a BlobReader object used to read `zipFileBlob`.
50
- * const zipFileReader = new BlobReader(zipFileBlob);
51
- * // Creates a TextWriter object where the content of the first entry in the zip
52
- * // will be written.
53
- * const helloWorldWriter = new TextWriter();
54
- *
55
- * // Creates a ZipReader object reading the zip content via `zipFileReader`,
56
- * // retrieves metadata (name, dates, etc.) of the first entry, retrieves its
57
- * // content via `helloWorldWriter`, and closes the reader.
58
- * const zipReader = new ZipReader(zipFileReader);
59
- * const firstEntry = (await zipReader.getEntries()).shift();
60
- * const helloWorldText = await firstEntry.getData(helloWorldWriter);
61
- * await zipReader.close();
62
- *
63
- * // Displays "Hello world!".
64
- * console.log(helloWorldText);
65
- * ```
66
- *
67
- * @example
68
- * Hello world with Streams
69
- * ```js
70
- * import {
71
- * BlobReader,
72
- * ZipReader,
73
- * ZipWriter,
74
- * } from "@zip-js/zip-js";
75
- *
76
- * // ----
77
- * // Write the zip file
78
- * // ----
79
- *
80
- * // Creates a TransformStream object, the zip content will be written in the
81
- * // `writable` property.
82
- * const zipFileStream = new TransformStream();
83
- * // Creates a Promise object resolved to the zip content returned as a Blob
84
- * // object retrieved from `zipFileStream.readable`.
85
- * const zipFileBlobPromise = new Response(zipFileStream.readable).blob();
86
- * // Creates a ReadableStream object storing the text of the entry to add in the
87
- * // zip (i.e. "Hello world!").
88
- * const helloWorldReadable = new Blob(["Hello world!"]).stream();
89
- *
90
- * // Creates a ZipWriter object writing data into `zipFileStream.writable`, adds
91
- * // the entry "hello.txt" containing the text "Hello world!" retrieved from
92
- * // `helloWorldReadable`, and closes the writer.
93
- * const zipWriter = new ZipWriter(zipFileStream.writable);
94
- * await zipWriter.add("hello.txt", helloWorldReadable);
95
- * await zipWriter.close();
96
- *
97
- * // Retrieves the Blob object containing the zip content into `zipFileBlob`.
98
- * const zipFileBlob = await zipFileBlobPromise;
99
- *
100
- * // ----
101
- * // Read the zip file
102
- * // ----
103
- *
104
- * // Creates a BlobReader object used to read `zipFileBlob`.
105
- * const zipFileReader = new BlobReader(zipFileBlob);
106
- * // Creates a TransformStream object, the content of the first entry in the zip
107
- * // will be written in the `writable` property.
108
- * const helloWorldStream = new TransformStream();
109
- * // Creates a Promise object resolved to the content of the first entry returned
110
- * // as text from `helloWorldStream.readable`.
111
- * const helloWorldTextPromise = new Response(helloWorldStream.readable).text();
112
- *
113
- * // Creates a ZipReader object reading the zip content via `zipFileReader`,
114
- * // retrieves metadata (name, dates, etc.) of the first entry, retrieves its
115
- * // content into `helloWorldStream.writable`, and closes the reader.
116
- * const zipReader = new ZipReader(zipFileReader);
117
- * const firstEntry = (await zipReader.getEntries()).shift();
118
- * await firstEntry.getData(helloWorldStream.writable);
119
- * await zipReader.close();
120
- *
121
- * // Displays "Hello world!".
122
- * const helloWorldText = await helloWorldTextPromise;
123
- * console.log(helloWorldText);
124
- * ```
125
- *
126
- * @example
127
- * Adding concurrently multiple entries in a zip file
128
- * ```js
129
- * import {
130
- * BlobWriter,
131
- * HttpReader,
132
- * TextReader,
133
- * ZipWriter,
134
- * } from "@zip-js/zip-js";
135
- *
136
- * const README_URL = "https://unpkg.com/@zip.js/zip.js/README.md";
137
- * getZipFileBlob()
138
- * .then(downloadFile);
139
- *
140
- * async function getZipFileBlob() {
141
- * const zipWriter = new ZipWriter(new BlobWriter("application/zip"));
142
- * await Promise.all([
143
- * zipWriter.add("hello.txt", new TextReader("Hello world!")),
144
- * zipWriter.add("README.md", new HttpReader(README_URL)),
145
- * ]);
146
- * return zipWriter.close();
147
- * }
148
- *
149
- * function downloadFile(blob) {
150
- * document.body.appendChild(Object.assign(document.createElement("a"), {
151
- * download: "hello.zip",
152
- * href: URL.createObjectURL(blob),
153
- * textContent: "Download zip file",
154
- * }));
155
- * }
156
- * ```
157
- *
158
- * @module
159
- */
160
-
161
- /**
162
- * Represents the `FileSystemEntry` class.
163
- *
164
- * @see {@link https://wicg.github.io/entries-api/#api-entry|specification}
165
- */
166
- // deno-lint-ignore no-empty-interface
167
- interface FileSystemEntryLike {}
168
-
169
- /**
170
- * Represents the `FileSystemHandle` class.
171
- *
172
- * @see {@link https://fs.spec.whatwg.org/#api-filesystemhandle}
173
- */
174
- // deno-lint-ignore no-empty-interface
175
- interface FileSystemHandleLike {}
176
-
177
- /**
178
- * Represents a generic `TransformStream` class.
179
- *
180
- * @see {@link https://streams.spec.whatwg.org/#generictransformstream|specification}
181
- */
182
- declare class TransformStreamLike {
183
- /**
184
- * The readable stream.
185
- */
186
- readable: ReadableStream;
187
- /**
188
- * The writable stream.
189
- */
190
- writable: WritableStream;
191
- }
192
-
193
- /**
194
- * Configures zip.js
195
- *
196
- * @param configuration The configuration.
197
- */
198
- export function configure(configuration: Configuration): void;
199
-
200
- /**
201
- * Represents the configuration passed to {@link configure}.
202
- */
203
- export interface Configuration extends WorkerConfiguration {
204
- /**
205
- * The maximum number of web workers used to compress/decompress data simultaneously.
206
- *
207
- * @defaultValue `navigator.hardwareConcurrency`
208
- */
209
- maxWorkers?: number;
210
- /**
211
- * The delay in milliseconds before idle web workers are automatically terminated. You can call `terminateWorkers()` to terminate idle workers.
212
- *
213
- * @defaultValue 5000
214
- */
215
- terminateWorkerTimeout?: number;
216
- /**
217
- * The URI of the web worker.
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 Data URI.
220
- *
221
- * Here is an example to import the worker module as a URL (see `?url`) and avoid CSP issues:
222
- * ```
223
- * import workerURI from "@zip.js/zip.js/dist/zip-web-worker.js?url";
224
- *
225
- * configure({
226
- * workerURI
227
- * });
228
- * ```
229
- *
230
- * @defaultValue "./core/web-worker.js"
231
- */
232
- workerURI?: string;
233
- /**
234
- * 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
- *
236
- * Here is an example to import the WASM module as a URL (see `?url`) and avoid CSP issues:
237
- * ```
238
- * import wasmURI from "@zip.js/zip.js/dist/zip-module.wasm?url";
239
- *
240
- * configure({
241
- * wasmURI
242
- * });
243
- * ```
244
- *
245
- * @defaultValue "./core/streams/zlib-wasm/zlib-streams.wasm"
246
- */
247
- wasmURI?: string;
248
- /**
249
- * The size of the chunks in bytes during data compression/decompression.
250
- *
251
- * @defaultValue 65536
252
- */
253
- chunkSize?: number;
254
- /**
255
- * The stream implementation used to compress data when `useCompressionStream` is set to `true`.
256
- *
257
- * @defaultValue {@link CodecStream}
258
- */
259
- CompressionStream?: typeof TransformStreamLike;
260
- /**
261
- * The stream implementation used to decompress data when `useCompressionStream` is set to `true`.
262
- *
263
- * @defaultValue {@link CodecStream}
264
- */
265
- DecompressionStream?: typeof TransformStreamLike;
266
- /**
267
- * The stream implementation used to compress data when `useCompressionStream` is set to `false`.
268
- *
269
- * @defaultValue {@link CodecStream}
270
- */
271
- CompressionStreamZlib?: typeof TransformStreamLike;
272
- /**
273
- * The stream implementation used to decompress data when `useCompressionStream` is set to `false`.
274
- *
275
- * @defaultValue {@link CodecStream}
276
- */
277
- DecompressionStreamZlib?: typeof TransformStreamLike;
278
- }
279
-
280
- /**
281
- * Represents configuration passed to {@link configure}, the constructor of {@link ZipReader}, {@link FileEntry#getData}, the constructor of {@link ZipWriter}, and {@link ZipWriter#add}.
282
- */
283
- export interface WorkerConfiguration {
284
- /**
285
- * `true` to use web workers to compress/decompress data in non-blocking background processes.
286
- *
287
- * @defaultValue true
288
- */
289
- useWebWorkers?: boolean;
290
- /**
291
- * `true` to use the native API `CompressionStream`/`DecompressionStream` to compress/decompress data.
292
- *
293
- * @defaultValue true
294
- */
295
- useCompressionStream?: boolean;
296
- /**
297
- * `true` to transfer stream ownership to web workers.
298
- *
299
- * @defaultValue true
300
- */
301
- transferStreams?: boolean;
302
- }
303
-
304
- /**
305
- * Terminates all the web workers
306
- */
307
- export function terminateWorkers(): Promise<void>;
308
-
309
- /**
310
- * Represents a class implementing `CompressionStream` or `DecompressionStream` interfaces.
311
- */
312
- declare class CodecStream extends TransformStream {}
313
-
314
- /**
315
- * Returns the MIME type corresponding to a filename extension.
316
- *
317
- * @param fileExtension the extension of the filename.
318
- * @returns The corresponding MIME type.
319
- */
320
- export function getMimeType(fileExtension: string): string;
321
-
322
- /**
323
- * Represents an instance used to read or write unknown type of data.
324
- *
325
- * zip.js can handle multiple types of data thanks to a generic API. This feature is based on 2 abstract constructors: {@link Reader} and {@link Writer}.
326
- * The classes inheriting from {@link Reader} help to read data from a source of data. The classes inheriting from {@link Writer} help to write data into a destination.
327
- */
328
- export interface Initializable {
329
- /**
330
- * Initializes the instance asynchronously
331
- */
332
- init?(): Promise<void>;
333
- }
334
-
335
- /**
336
- * Represents an instance used to read data from a `ReadableStream` instance.
337
- */
338
- export interface ReadableReader {
339
- /**
340
- * The `ReadableStream` instance.
341
- */
342
- readable: ReadableStream;
343
- }
344
-
345
- /**
346
- * Represents an instance used to read unknown type of data.
347
- *
348
- * @example
349
- * Here is an example of custom {@link Reader} class used to read binary strings:
350
- * ```
351
- * class BinaryStringReader extends Reader {
352
- *
353
- * constructor(binaryString) {
354
- * super();
355
- * this.binaryString = binaryString;
356
- * }
357
- *
358
- * init() {
359
- * super.init();
360
- * this.size = this.binaryString.length;
361
- * }
362
- *
363
- * readUint8Array(offset, length) {
364
- * const result = new Uint8Array(length);
365
- * for (let indexCharacter = 0; indexCharacter < length; indexCharacter++) {
366
- * result[indexCharacter] = this.binaryString.charCodeAt(indexCharacter + offset) & 0xFF;
367
- * }
368
- * return result;
369
- * }
370
- * }
371
- * ```
372
- */
373
- export class Reader<Type> implements Initializable, ReadableReader {
374
- /**
375
- * Creates the {@link Reader} instance
376
- *
377
- * @param value The data to read.
378
- */
379
- constructor(value: Type);
380
- /**
381
- * The `ReadableStream` instance.
382
- */
383
- readable: ReadableStream;
384
- /**
385
- * The total size of the data in bytes.
386
- */
387
- size: number;
388
- /**
389
- * Initializes the instance asynchronously
390
- */
391
- init?(): Promise<void>;
392
- /**
393
- * Reads a chunk of data
394
- *
395
- * @param index The byte index of the data to read.
396
- * @param length The length of the data to read in bytes.
397
- * @returns A promise resolving to a chunk of data. The data must be trucated to the remaining size if the requested length is larger than the remaining size.
398
- */
399
- readUint8Array(index: number, length: number): Promise<Uint8Array>;
400
- }
401
-
402
- /**
403
- * Represents a {@link Reader} instance used to read data provided as a `string`.
404
- */
405
- export class TextReader extends Reader<string> {}
406
-
407
- /**
408
- * Represents a {@link Reader} instance used to read data provided as a `Blob` instance.
409
- */
410
- export class BlobReader extends Reader<Blob> {}
411
-
412
- /**
413
- * Represents a {@link Reader} instance used to read data provided as a Data URI `string` encoded in Base64.
414
- */
415
- export class Data64URIReader extends Reader<string> {}
416
-
417
- /**
418
- * Represents a {@link Reader} instance used to read data provided as a `Uint8Array` instance.
419
- */
420
- export class Uint8ArrayReader extends Reader<Uint8Array> {}
421
-
422
- /**
423
- * Represents a {@link Reader} instance used to read data provided as an array of {@link ReadableReader} instances (e.g. split zip files).
424
- */
425
- export class SplitDataReader extends Reader<
426
- Reader<unknown>[] | ReadableReader[] | ReadableStream[]
427
- > {}
428
-
429
- /**
430
- * Represents a URL stored into a `string`.
431
- */
432
- type URLString = string;
433
-
434
- /**
435
- * Represents a {@link Reader} instance used to fetch data from a URL.
436
- */
437
- export class HttpReader extends Reader<URLString> {
438
- /**
439
- * Creates the {@link HttpReader} instance
440
- *
441
- * @param url The URL of the data.
442
- * @param options The options.
443
- */
444
- constructor(url: URLString | URL, options?: HttpOptions);
445
- }
446
-
447
- /**
448
- * Represents a {@link Reader} instance used to fetch data from servers returning `Accept-Ranges` headers.
449
- */
450
- export class HttpRangeReader extends HttpReader {
451
- /**
452
- * Creates the {@link HttpRangeReader} instance. It is particularly useful for reading ZIP files via HTTP.
453
- * If you just want to add content retrieved via HTTP to a ZIP file, you can simply use
454
- * `Response#body` {@link https://developer.mozilla.org/en-US/docs/Web/API/Response/body} instead.
455
- *
456
- * @param url The URL of the data.
457
- * @param options The options.
458
- */
459
- constructor(url: URLString | URL, options?: HttpRangeOptions);
460
- }
461
-
462
- /**
463
- * Represents the options passed to the constructor of {@link HttpReader}.
464
- */
465
- export interface HttpOptions extends HttpRangeOptions {
466
- /**
467
- * `true` to use `Range` headers when fetching data from servers returning `Accept-Ranges` headers.
468
- *
469
- * @defaultValue false
470
- */
471
- useRangeHeader?: boolean;
472
- /**
473
- * `true` to always use `Range` headers when fetching data.
474
- *
475
- * @defaultValue false
476
- */
477
- forceRangeRequests?: boolean;
478
- /**
479
- * `true` to prevent using `HEAD` HTTP request in order the get the size of the content.
480
- * `false` to explicitly use `HEAD`, this is useful in case of CORS where `Access-Control-Expose-Headers: Content-Range` is not returned by the server.
481
- *
482
- * @defaultValue false
483
- */
484
- preventHeadRequest?: boolean;
485
- /**
486
- * `true` to use `Range: bytes=-22` on the first request and cache the EOCD, make sure beforehand that the server supports a suffix range request.
487
- *
488
- * @defaultValue false
489
- */
490
- combineSizeEocd?: boolean;
491
- }
492
-
493
- /**
494
- * Represents options passed to the constructor of {@link HttpRangeReader} and {@link HttpReader}.
495
- */
496
- export interface HttpRangeOptions {
497
- /**
498
- * `true` to rely `XMLHttpRequest` instead of `fetch` to fetch data.
499
- *
500
- * @defaultValue false
501
- */
502
- useXHR?: boolean;
503
- /**
504
- * The HTTP headers.
505
- */
506
- headers?: Iterable<[string, string]> | Map<string, string>;
507
- }
508
-
509
- /**
510
- * Represents an instance used to write data into a `WritableStream` instance.
511
- */
512
- export interface WritableWriter {
513
- /**
514
- * The `WritableStream` instance.
515
- */
516
- writable: WritableStream;
517
- /**
518
- * The maximum size of split data when creating a {@link ZipWriter} instance or when calling {@link FileEntry#getData} with a generator of {@link WritableWriter} instances.
519
- */
520
- maxSize?: number;
521
- }
522
-
523
- /**
524
- * Represents an instance used to write unknown type of data.
525
- *
526
- * @example
527
- * Here is an example of custom {@link Writer} class used to write binary strings:
528
- * ```
529
- * class BinaryStringWriter extends Writer {
530
- *
531
- * constructor() {
532
- * super();
533
- * this.binaryString = "";
534
- * }
535
- *
536
- * writeUint8Array(array) {
537
- * for (let indexCharacter = 0; indexCharacter < array.length; indexCharacter++) {
538
- * this.binaryString += String.fromCharCode(array[indexCharacter]);
539
- * }
540
- * }
541
- *
542
- * getData() {
543
- * return this.binaryString;
544
- * }
545
- * }
546
- * ```
547
- */
548
- export class Writer<Type> implements Initializable, WritableWriter {
549
- /**
550
- * The `WritableStream` instance.
551
- */
552
- writable: WritableStream;
553
- /**
554
- * Initializes the instance asynchronously
555
- *
556
- * @param size the total size of the written data in bytes.
557
- */
558
- init?(size?: number): Promise<void>;
559
- /**
560
- * Appends a chunk of data
561
- *
562
- * @param array The chunk data to append.
563
- *
564
- * @virtual
565
- */
566
- writeUint8Array(array: Uint8Array): Promise<void>;
567
- /**
568
- * Retrieves all the written data
569
- *
570
- * @returns A promise resolving to the written data.
571
- */
572
- getData(): Promise<Type>;
573
- }
574
-
575
- /**
576
- * Represents a {@link Writer} instance used to retrieve the written data as a `string`.
577
- */
578
- export class TextWriter extends Writer<string> {
579
- /**
580
- * Creates the {@link TextWriter} instance
581
- *
582
- * @param encoding The encoding of the text.
583
- */
584
- constructor(encoding?: string);
585
- }
586
-
587
- /**
588
- * Represents a {@link WritableWriter} instance used to retrieve the written data as a `Blob` instance.
589
- */
590
- export class BlobWriter implements Initializable, WritableWriter {
591
- /**
592
- * The `WritableStream` instance.
593
- */
594
- writable: WritableStream;
595
- /**
596
- * Initializes the instance asynchronously
597
- */
598
- init(): Promise<void>;
599
- /**
600
- * Creates the {@link BlobWriter} instance
601
- *
602
- * @param mimeString The MIME type of the content.
603
- */
604
- constructor(mimeString?: string);
605
- /**
606
- * Retrieves all the written data
607
- *
608
- * @returns A promise resolving to the written data.
609
- */
610
- getData(): Promise<Blob>;
611
- }
612
-
613
- /**
614
- * Represents a {@link Writer} instance used to retrieve the written data as a Data URI `string` encoded in Base64.
615
- */
616
- export class Data64URIWriter extends Writer<string> {
617
- /**
618
- * Creates the {@link Data64URIWriter} instance
619
- *
620
- * @param mimeString The MIME type of the content.
621
- */
622
- constructor(mimeString?: string);
623
- }
624
-
625
- /**
626
- * Represents a {@link Writer} instance used to retrieve the written data from a generator of {@link WritableWriter} instances (i.e. split zip files).
627
- */
628
- export class SplitDataWriter implements Initializable, WritableWriter {
629
- /**
630
- * The `WritableStream` instance.
631
- */
632
- writable: WritableStream;
633
- /**
634
- * Initializes the instance asynchronously
635
- */
636
- init(): Promise<void>;
637
- /**
638
- * Creates the {@link SplitDataWriter} instance
639
- *
640
- * @param writerGenerator A generator of Writer instances.
641
- * @param maxSize The maximum size of the data written into {@link Writer} instances (default: 4GB).
642
- */
643
- constructor(
644
- writerGenerator: AsyncGenerator<
645
- Writer<unknown> | WritableWriter | WritableStream,
646
- boolean
647
- >,
648
- maxSize?: number
649
- );
650
- }
651
-
652
- /**
653
- * Represents a {@link Writer} instance used to retrieve the written data as a `Uint8Array` instance.
654
- */
655
- export class Uint8ArrayWriter extends Writer<Uint8Array<ArrayBuffer>> {
656
- /**
657
- * Creates the {@link Uint8ArrayWriter} instance
658
- *
659
- * @param defaultBufferSize The initial size of the internal buffer (default: 256KB).
660
- */
661
- constructor(defaultBufferSize?: number);
662
- }
663
-
664
- /**
665
- * Represents an instance used to create an unzipped stream.
666
- *
667
- * @example
668
- * This example will take a zip file, decompress it and then save its files and directories to disk.
669
- * ```
670
- * import {resolve} from "https://deno.land/std/path/mod.ts";
671
- * import {ensureDir, ensureFile} from "https://deno.land/std/fs/mod.ts";
672
- *
673
- * for await (const entry of (await fetch(urlToZippedFile)).body.pipeThrough(new ZipReaderStream())) {
674
- * const fullPath = resolve(destination, entry.filename);
675
- * if (entry.directory) {
676
- * await ensureDir(fullPath);
677
- * continue;
678
- * }
679
- *
680
- * await ensureFile(fullPath);
681
- * await entry.readable?.pipeTo((await Deno.create(fullPath)).writable);
682
- * }
683
- * ```
684
- */
685
- export class ZipReaderStream<T> {
686
- /**
687
- * Creates the stream.
688
- *
689
- * @param options The options.
690
- */
691
- constructor(options?: ZipReaderConstructorOptions);
692
-
693
- /**
694
- * The readable stream.
695
- */
696
- readable: ReadableStream<
697
- Omit<Entry, "getData"> & { readable?: ReadableStream<Uint8Array> }
698
- >;
699
-
700
- /**
701
- * The writable stream.
702
- */
703
- writable: WritableStream<T>;
704
- }
705
-
706
- /**
707
- * Represents an instance used to read a zip file.
708
- *
709
- * @example
710
- * Here is an example showing how to read the text data of the first entry from a zip file:
711
- * ```
712
- * // create a BlobReader to read with a ZipReader the zip from a Blob object
713
- * const reader = new zip.ZipReader(new zip.BlobReader(blob));
714
- *
715
- * // get all entries from the zip
716
- * const entries = await reader.getEntries();
717
- * if (entries.length) {
718
- *
719
- * // get first entry content as text by using a TextWriter
720
- * const text = await entries[0].getData(
721
- * // writer
722
- * new zip.TextWriter(),
723
- * // options
724
- * {
725
- * onprogress: (index, max) => {
726
- * // onprogress callback
727
- * }
728
- * }
729
- * );
730
- * // text contains the entry data as a String
731
- * console.log(text);
732
- * }
733
- *
734
- * // close the ZipReader
735
- * await reader.close();
736
- * ```
737
- */
738
- export class ZipReader<Type> {
739
- /**
740
- * Creates the instance
741
- *
742
- * @param reader The {@link Reader} instance used to read data.
743
- * @param options The options.
744
- */
745
- constructor(
746
- reader:
747
- | Reader<Type>
748
- | ReadableReader
749
- | ReadableStream
750
- | Reader<unknown>[]
751
- | ReadableReader[]
752
- | ReadableStream[],
753
- options?: ZipReaderConstructorOptions
754
- );
755
- /**
756
- * The global comment of the zip file.
757
- */
758
- comment: Uint8Array;
759
- /**
760
- * The data prepended before the zip file.
761
- */
762
- prependedData?: Uint8Array;
763
- /**
764
- * The data appended after the zip file.
765
- */
766
- appendedData?: Uint8Array;
767
- /**
768
- * Returns all the entries in the zip file
769
- *
770
- * @param options The options.
771
- * @returns A promise resolving to an `array` of {@link Entry} instances.
772
- */
773
- getEntries(options?: ZipReaderGetEntriesOptions): Promise<Entry[]>;
774
- /**
775
- * Returns a generator used to iterate on all the entries in the zip file
776
- *
777
- * @param options The options.
778
- * @returns An asynchronous generator of {@link Entry} instances.
779
- */
780
- getEntriesGenerator(
781
- options?: ZipReaderGetEntriesOptions
782
- ): AsyncGenerator<Entry, boolean>;
783
- /**
784
- * Closes the zip file
785
- */
786
- close(): Promise<void>;
787
- }
788
-
789
- /**
790
- * Represents the options passed to the constructor of {@link ZipReader}, and `{@link ZipDirectory}#import*`.
791
- */
792
- export interface ZipReaderConstructorOptions
793
- extends ZipReaderOptions,
794
- GetEntriesOptions,
795
- WorkerConfiguration {
796
- /**
797
- * `true` to extract the prepended data into {@link ZipReader#prependedData}.
798
- *
799
- * @defaultValue false
800
- */
801
- extractPrependedData?: boolean;
802
- /**
803
- * `true` to extract the appended data into {@link ZipReader#appendedData}.
804
- *
805
- * @defaultValue false
806
- */
807
- extractAppendedData?: boolean;
808
- }
809
-
810
- /**
811
- * Represents the options passed to {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
812
- */
813
- export interface ZipReaderGetEntriesOptions
814
- extends GetEntriesOptions,
815
- EntryOnprogressOptions {}
816
-
817
- /**
818
- * Represents options passed to the constructor of {@link ZipReader}, {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
819
- */
820
- export interface GetEntriesOptions {
821
- /**
822
- * The encoding of the filename of the entry.
823
- */
824
- filenameEncoding?: string;
825
- /**
826
- * The encoding of the comment of the entry.
827
- */
828
- commentEncoding?: string;
829
- /**
830
- * The function called for decoding the filename and the comment of the entry.
831
- *
832
- * @param value The raw text value.
833
- * @param encoding The encoding of the text.
834
- * @returns The decoded text value or `undefined` if the raw text value should be decoded by zip.js.
835
- */
836
- decodeText?(value: Uint8Array, encoding: string): string | undefined;
837
- }
838
-
839
- /**
840
- * Represents options passed to the constructor of {@link ZipReader} and {@link FileEntry#getData}.
841
- */
842
- export interface ZipReaderOptions {
843
- /**
844
- * `true` to check only if the password is valid.
845
- *
846
- * @defaultValue false
847
- */
848
- checkPasswordOnly?: boolean;
849
- /**
850
- * `true` to check the signature of the entry.
851
- *
852
- * @defaultValue false
853
- */
854
- checkSignature?: boolean;
855
- /**
856
- * `true` to throw an {@link ERR_OVERLAPPING_ENTRY} error when calling {@link FileEntry#getData} if the entry
857
- * overlaps with another entry on which {@link FileEntry#getData} has already been called (with the option
858
- * `checkOverlappingEntry` or `checkOverlappingEntryOnly` set to `true`).
859
- *
860
- * @defaultValue false
861
- */
862
- checkOverlappingEntry?: boolean;
863
- /**
864
- * `true` to throw an {@link ERR_OVERLAPPING_ENTRY} error when calling {@link FileEntry#getData} if the entry
865
- * overlaps with another entry on which {@link FileEntry#getData} has already been called (with the option
866
- * `checkOverlappingEntry` or `checkOverlappingEntryOnly` set to `true`) without trying to read the content of the
867
- * entry.
868
- *
869
- * @defaultValue false
870
- */
871
- checkOverlappingEntryOnly?: boolean;
872
- /**
873
- * The password used to decrypt the content of the entry.
874
- */
875
- password?: string;
876
- /**
877
- * `true` to read the data as-is without decompressing it and without decrypting it.
878
- */
879
- passThrough?: boolean;
880
- /**
881
- * The password used to encrypt the content of the entry (raw).
882
- */
883
- rawPassword?: Uint8Array;
884
- /**
885
- * The `AbortSignal` instance used to cancel the decompression.
886
- */
887
- signal?: AbortSignal;
888
- /**
889
- * `true` to prevent closing of {@link Writer#writable} when calling {@link FileEntry#getData}.
890
- *
891
- * @defaultValue false
892
- */
893
- preventClose?: boolean;
894
- }
895
-
896
- /**
897
- * Represents the metadata of an entry in a zip file (Core API).
898
- */
899
- export interface EntryMetaData {
900
- /**
901
- * The byte offset of the entry.
902
- */
903
- offset: number;
904
- /**
905
- * The filename of the entry.
906
- */
907
- filename: string;
908
- /**
909
- * The filename of the entry (raw).
910
- */
911
- rawFilename: Uint8Array;
912
- /**
913
- * `true` if the filename is encoded in UTF-8.
914
- */
915
- filenameUTF8: boolean;
916
- /**
917
- * `true` if the entry is an executable file
918
- */
919
- executable: boolean;
920
- /**
921
- * `true` if the content of the entry is encrypted.
922
- */
923
- encrypted: boolean;
924
- /**
925
- * `true` if the content of the entry is encrypted with the ZipCrypto algorithm.
926
- */
927
- zipCrypto: boolean;
928
- /**
929
- * The size of the compressed data in bytes.
930
- */
931
- compressedSize: number;
932
- /**
933
- * The size of the decompressed data in bytes.
934
- */
935
- uncompressedSize: number;
936
- /**
937
- * The last modification date.
938
- */
939
- lastModDate: Date;
940
- /**
941
- * The last access date.
942
- */
943
- lastAccessDate?: Date;
944
- /**
945
- * The creation date.
946
- */
947
- creationDate?: Date;
948
- /**
949
- * The last modification date (raw).
950
- */
951
- rawLastModDate: number | bigint;
952
- /**
953
- * The last access date (raw).
954
- */
955
- rawLastAccessDate?: number | bigint;
956
- /**
957
- * The creation date (raw).
958
- */
959
- rawCreationDate?: number | bigint;
960
- /**
961
- * The comment of the entry.
962
- */
963
- comment: string;
964
- /**
965
- * The comment of the entry (raw).
966
- */
967
- rawComment: Uint8Array;
968
- /**
969
- * `true` if the comment is encoded in UTF-8.
970
- */
971
- commentUTF8: boolean;
972
- /**
973
- * The signature (CRC32 checksum) of the content.
974
- */
975
- signature: number;
976
- /**
977
- * The extra field.
978
- */
979
- extraField?: Map<number, { type: number; data: Uint8Array }>;
980
- /**
981
- * The extra field (raw).
982
- */
983
- rawExtraField: Uint8Array;
984
- /**
985
- * `true` if the entry is using Zip64.
986
- */
987
- zip64: boolean;
988
- /**
989
- * The "Version" field.
990
- */
991
- version: number;
992
- /**
993
- * The "Version made by" field.
994
- */
995
- versionMadeBy: number;
996
- /**
997
- * `true` if `internalFileAttributes` and `externalFileAttributes` are compatible with MS-DOS format.
998
- */
999
- msDosCompatible: boolean;
1000
- /**
1001
- * Note (MS-DOS / Unix attributes):
1002
- *
1003
- * - The single source of truth for on-disk metadata is the 32-bit `externalFileAttributes` value stored in
1004
- * the ZIP headers. The upper 16 bits are commonly used for Unix `st_mode` (type/permissions/special bits)
1005
- * and the low 8 bits for MS-DOS attribute flags.
1006
- *
1007
- * - Writer vs Reader:
1008
- * - The writer composes `externalFileAttributes` from the provided options (`externalFileAttributes`,
1009
- * `unixMode`/special flags, `msdosAttributesRaw`/`msdosAttributes`).
1010
- * - The reader decodes the stored `externalFileAttributes` and exposes convenience fields such as
1011
- * `msdosAttributesRaw`, `msdosAttributes`, `unixExternalUpper`, and `unixMode`.
1012
- *
1013
- * - Practical rule: treat `externalFileAttributes` as authoritative; other fields are conveniences derived
1014
- * from it. If you need a specific on-disk value, set `externalFileAttributes` explicitly.
1015
- */
1016
- /**
1017
- * The MS-DOS attributes low byte (raw).
1018
- * This is the low 8 bits of {@link EntryMetaData#externalFileAttributes} when present.
1019
- */
1020
- msdosAttributesRaw?: number;
1021
- /**
1022
- * The MS-DOS attribute flags exposed as booleans.
1023
- */
1024
- msdosAttributes?: {
1025
- readOnly: boolean;
1026
- hidden: boolean;
1027
- system: boolean;
1028
- directory: boolean;
1029
- archive: boolean;
1030
- };
1031
- /**
1032
- * Unix owner id when available.
1033
- */
1034
- uid?: number;
1035
- /**
1036
- * Unix group id when available.
1037
- */
1038
- gid?: number;
1039
- /**
1040
- * Unix mode (st_mode) when available.
1041
- */
1042
- unixMode?: number;
1043
- /**
1044
- * `true` if the setuid bit is set on the entry.
1045
- */
1046
- setuid?: boolean;
1047
- /**
1048
- * `true` if the setgid bit is set on the entry.
1049
- */
1050
- setgid?: boolean;
1051
- /**
1052
- * `true` if the sticky bit is set on the entry.
1053
- */
1054
- sticky?: boolean;
1055
- /**
1056
- * The internal file attributes (raw).
1057
- */
1058
- internalFileAttributes: number;
1059
- /**
1060
- * The 32-bit `externalFileAttributes` field is the authoritative on-disk metadata for each entry.
1061
- * - Upper 16 bits: Unix mode/type (e.g., permissions, file type)
1062
- * - Low 8 bits: MS-DOS file attributes (e.g., directory, read-only)
1063
- *
1064
- * When writing, all provided options are merged into this field. When reading, convenience fields are decoded from it.
1065
- * For most use cases, prefer the high-level options and fields; only advanced users need to manipulate the raw value directly.
1066
- */
1067
- externalFileAttributes: number;
1068
- /**
1069
- * The upper 16-bit portion of {@link EntryMetaData#externalFileAttributes} when it represents Unix mode bits.
1070
- */
1071
- unixExternalUpper?: number;
1072
- /**
1073
- * The number of the disk where the entry data starts.
1074
- */
1075
- /**
1076
- * The internal file attribute (raw).
1077
- * @deprecated Use {@link EntryMetaData#internalFileAttributes} instead.
1078
- */
1079
- internalFileAttribute: number;
1080
- /**
1081
- * The external file attribute (raw).
1082
- * @deprecated Use {@link EntryMetaData#externalFileAttributes} instead.
1083
- */
1084
- externalFileAttribute: number;
1085
- /**
1086
- * The number of the disk where the entry data starts.
1087
- */
1088
- diskNumberStart: number;
1089
- /**
1090
- * The compression method.
1091
- */
1092
- compressionMethod: number;
1093
- }
1094
- export interface DirectoryEntry extends EntryMetaData {
1095
- /**
1096
- * `true` if the entry is a directory.
1097
- */
1098
- directory: true;
1099
- }
1100
-
1101
- export interface FileEntry extends EntryMetaData {
1102
- /**
1103
- * `false` if the entry is a file.
1104
- */
1105
- directory: false;
1106
- /**
1107
- * Returns the content of the entry
1108
- *
1109
- * @param writer The {@link Writer} instance used to write the content of the entry.
1110
- * @param options The options.
1111
- * @returns A promise resolving to the type to data associated to `writer`.
1112
- */
1113
- getData<Type>(
1114
- writer:
1115
- | Writer<Type>
1116
- | WritableWriter
1117
- | WritableStream
1118
- | AsyncGenerator<
1119
- Writer<unknown> | WritableWriter | WritableStream,
1120
- boolean
1121
- >,
1122
- options?: EntryGetDataCheckPasswordOptions
1123
- ): Promise<Type>;
1124
- /**
1125
- * Retrieves the content of the entry as an `ArrayBuffer` instance
1126
- *
1127
- * @param options The options.
1128
- * @returns A promise resolving to an `ArrayBuffer` instance.
1129
- */
1130
- arrayBuffer(options?: EntryGetDataOptions): Promise<ArrayBuffer>;
1131
- }
1132
-
1133
- /**
1134
- * Represents an entry with its data and metadata in a zip file (Core API).
1135
- * This is a union type of {@link DirectoryEntry} and {@link FileEntry}.
1136
- *
1137
- * Before using getData, you should check if the entry is a file.
1138
- *
1139
- * @example
1140
- *
1141
- * ```ts
1142
- * for await (const entry of reader.getEntriesGenerator()) {
1143
- * if (entry.directory) continue;
1144
- *
1145
- * // entry is a FileEntry
1146
- * const plainTextData = await entry.getData(new TextWriter());
1147
- *
1148
- * // Do something with the plainTextData
1149
- * }
1150
- * ```
1151
- */
1152
- export type Entry = DirectoryEntry | FileEntry;
1153
-
1154
- /**
1155
- * Represents the options passed to {@link FileEntry#getData} and `{@link ZipFileEntry}.get*`.
1156
- */
1157
- export interface EntryGetDataOptions
1158
- extends EntryDataOnprogressOptions,
1159
- ZipReaderOptions,
1160
- WorkerConfiguration {}
1161
-
1162
- /**
1163
- * Represents the options passed to {@link FileEntry#getData} and `{@link ZipFileEntry}.get*`.
1164
- */
1165
- export interface EntryGetDataCheckPasswordOptions extends EntryGetDataOptions {}
1166
-
1167
- /**
1168
- * Represents an instance used to create a zipped stream.
1169
- *
1170
- * @example
1171
- * This example creates a zipped file called numbers.txt.zip containing the numbers 0 - 1000 each on their own line.
1172
- * ```
1173
- * const readable = ReadableStream.from((function* () {
1174
- * for (let i = 0; i < 1000; ++i)
1175
- * yield i + '\n'
1176
- * })())
1177
- *
1178
- * readable
1179
- * .pipeThrough(new ZipWriterStream().transform('numbers.txt'))
1180
- * .pipeTo((await Deno.create('numbers.txt.zip')).writable)
1181
- * ```
1182
- *
1183
- * @example
1184
- * This example creates a zipped file called Archive.zip containing two files called numbers.txt and letters.txt
1185
- * ```
1186
- * const readable1 = ReadableStream.from((function* () {
1187
- * for (let i = 0; i < 1000; ++i)
1188
- * yield i + '\n'
1189
- * })())
1190
- * const readable2 = ReadableStream.from((function* () {
1191
- * const letters = 'abcdefghijklmnopqrstuvwxyz'.split('')
1192
- * while (letters.length)
1193
- * yield letters.shift() + '\n'
1194
- * })())
1195
- *
1196
- * const zipper = new ZipWriterStream()
1197
- * zipper.readable.pipeTo((await Deno.create('Archive.zip')).writable)
1198
- * readable1.pipeTo(zipper.writable('numbers.txt'))
1199
- * readable2.pipeTo(zipper.writable('letters.txt'))
1200
- * zipper.close()
1201
- * ```
1202
- */
1203
- export class ZipWriterStream {
1204
- /**
1205
- * Creates the stream.
1206
- *
1207
- * @param options The options.
1208
- */
1209
- constructor(options?: ZipWriterConstructorOptions);
1210
-
1211
- /**
1212
- * The readable stream.
1213
- */
1214
- readable: ReadableStream<Uint8Array>;
1215
-
1216
- /**
1217
- * The ZipWriter property.
1218
- */
1219
- zipWriter: ZipWriter<unknown>;
1220
-
1221
- /**
1222
- * Returns an object containing a readable and writable property for the .pipeThrough method
1223
- *
1224
- * @param path The name of the stream when unzipped.
1225
- * @returns An object containing readable and writable properties
1226
- */
1227
- transform<T>(path: string): {
1228
- readable: ReadableStream<T>;
1229
- writable: WritableStream<T>;
1230
- };
1231
-
1232
- /**
1233
- * Returns a WritableStream for the .pipeTo method
1234
- *
1235
- * @param path The directory path of where the stream should exist in the zipped stream.
1236
- * @returns A WritableStream.
1237
- */
1238
- writable<T>(path: string): WritableStream<T>;
1239
-
1240
- /**
1241
- * Writes the entries directory, writes the global comment, and returns the content of the zipped file.
1242
- *
1243
- * @param comment The global comment of the zip file.
1244
- * @param options The options.
1245
- * @returns The content of the zip file.
1246
- */
1247
- close(
1248
- comment?: Uint8Array,
1249
- options?: ZipWriterCloseOptions
1250
- ): Promise<unknown>;
1251
- }
1252
-
1253
- /**
1254
- * Represents an instance used to create a zip file.
1255
- *
1256
- * @example
1257
- * Here is an example showing how to create a zip file containing a compressed text file:
1258
- * ```
1259
- * // use a BlobWriter to store with a ZipWriter the zip into a Blob object
1260
- * const blobWriter = new zip.BlobWriter("application/zip");
1261
- * const writer = new zip.ZipWriter(blobWriter);
1262
- *
1263
- * // use a TextReader to read the String to add
1264
- * await writer.add("filename.txt", new zip.TextReader("test!"));
1265
- *
1266
- * // close the ZipReader
1267
- * await writer.close();
1268
- *
1269
- * // get the zip file as a Blob
1270
- * const blob = await blobWriter.getData();
1271
- * ```
1272
- */
1273
- export class ZipWriter<Type> {
1274
- /**
1275
- * Creates the {@link ZipWriter} instance
1276
- *
1277
- * @param writer The {@link Writer} instance where the zip content will be written.
1278
- * @param options The options.
1279
- */
1280
- constructor(
1281
- writer:
1282
- | Writer<Type>
1283
- | WritableWriter
1284
- | WritableStream
1285
- | AsyncGenerator<
1286
- Writer<unknown> | WritableWriter | WritableStream,
1287
- boolean
1288
- >,
1289
- options?: ZipWriterConstructorOptions
1290
- );
1291
- /**
1292
- * `true` if the zip contains at least one entry that has been partially written.
1293
- */
1294
- readonly hasCorruptedEntries?: boolean;
1295
-
1296
- /**
1297
- * Adds an existing zip file at the beginning of the current zip. This method
1298
- * cannot be called after the first call to {@link ZipWriter#add}.
1299
- *
1300
- * @param reader The {@link Reader} instance used to read the content of the zip file.
1301
- * @returns A promise resolving when the zip file has been added.
1302
- */
1303
- prependZip<ReaderType>(
1304
- reader:
1305
- | Reader<ReaderType>
1306
- | ReadableReader
1307
- | ReadableStream
1308
- | Reader<unknown>[]
1309
- | ReadableReader[]
1310
- | ReadableStream[]
1311
- ): Promise<void>;
1312
-
1313
- /**
1314
- * Adds an entry into the zip file
1315
- *
1316
- * @param filename The filename of the entry.
1317
- * @param reader The {@link Reader} instance used to read the content of the entry.
1318
- * @param options The options.
1319
- * @returns A promise resolving to an {@link EntryMetaData} instance.
1320
- */
1321
- add<ReaderType>(
1322
- filename: string,
1323
- reader?:
1324
- | Reader<ReaderType>
1325
- | ReadableReader
1326
- | ReadableStream
1327
- | Reader<unknown>[]
1328
- | ReadableReader[]
1329
- | ReadableStream[],
1330
- options?: ZipWriterAddDataOptions
1331
- ): Promise<EntryMetaData>;
1332
-
1333
- /**
1334
- * Removes an entry from the central directory that will be written for the zip file. The entry
1335
- * data itself cannot be removed because it has already been streamed to the output.
1336
- *
1337
- * @param entry The entry to remove. This can be an {@link Entry} instance or the filename of the entry.
1338
- * @returns `true` if the entry has been removed, `false` otherwise.
1339
- */
1340
- remove(entry: Entry | string): boolean;
1341
-
1342
- /**
1343
- * Writes the entries directory, writes the global comment, and returns the content of the zip file
1344
- *
1345
- * @param comment The global comment of the zip file.
1346
- * @param options The options.
1347
- * @returns The content of the zip file.
1348
- */
1349
- close(comment?: Uint8Array, options?: ZipWriterCloseOptions): Promise<Type>;
1350
- }
1351
-
1352
- /**
1353
- * Represents the options passed to {@link ZipWriter#add}.
1354
- */
1355
- export interface ZipWriterAddDataOptions
1356
- extends ZipWriterConstructorOptions,
1357
- EntryDataOnprogressOptions,
1358
- WorkerConfiguration {
1359
- /**
1360
- * `true` if the entry is a directory.
1361
- *
1362
- * @defaultValue false
1363
- */
1364
- directory?: boolean;
1365
- /**
1366
- * `true` if the entry is an executable file.
1367
- *
1368
- * @defaultValue false
1369
- */
1370
- executable?: boolean;
1371
- /**
1372
- * The comment of the entry.
1373
- */
1374
- comment?: string;
1375
- /**
1376
- * The extra field of the entry.
1377
- */
1378
- extraField?: Map<number, Uint8Array>;
1379
- /**
1380
- * The uncompressed size of the entry. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
1381
- */
1382
- uncompressedSize?: number;
1383
- /**
1384
- * The signature (CRC32 checksum) of the content. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
1385
- */
1386
- signature?: number;
1387
- }
1388
-
1389
- /**
1390
- * Represents the options passed to {@link ZipWriter#close}.
1391
- */
1392
- export interface ZipWriterCloseOptions extends EntryOnprogressOptions {
1393
- /**
1394
- * `true` to use Zip64 to write the entries directory.
1395
- *
1396
- * @defaultValue false
1397
- */
1398
- zip64?: boolean;
1399
- /**
1400
- * `true` to prevent closing of {@link WritableWriter#writable}.
1401
- *
1402
- * @defaultValue false
1403
- */
1404
- preventClose?: boolean;
1405
- }
1406
-
1407
- /**
1408
- * Represents options passed to the constructor of {@link ZipWriter}, {@link ZipWriter#add} and `{@link ZipDirectoryEntry}#export*`.
1409
- */
1410
- export interface ZipWriterConstructorOptions extends WorkerConfiguration {
1411
- /**
1412
- * `true` to use Zip64 to store the entry.
1413
- *
1414
- * `zip64` is automatically set to `true` when necessary (e.g. compressed data larger than 4GB or with unknown size).
1415
- *
1416
- * @defaultValue false
1417
- */
1418
- zip64?: boolean;
1419
- /**
1420
- * `true` to prevent closing of {@link WritableWriter#writable}.
1421
- *
1422
- * @defaultValue false
1423
- */
1424
- preventClose?: boolean;
1425
- /**
1426
- * The level of compression.
1427
- *
1428
- * The minimum value is 0 and means that no compression is applied. The maximum value is 9.
1429
- *
1430
- * @defaultValue 6
1431
- */
1432
- level?: number;
1433
- /**
1434
- * `true` to write entry data in a buffer before appending it to the zip file.
1435
- *
1436
- * `bufferedWrite` is automatically set to `true` when compressing more than one entry in parallel.
1437
- *
1438
- * @defaultValue false
1439
- */
1440
- bufferedWrite?: boolean;
1441
- /**
1442
- * An async factory function that returns a `TransformStream`-like object (`{ writable, readable }`) used as a temporary buffer when entries are written in parallel.
1443
- *
1444
- * When provided, this replaces the default in-memory `TransformStream` buffer, allowing data to be stored externally (e.g. filesystem, OPFS, network).
1445
- * The `writable` side receives compressed entry data. The `readable` side is consumed when the entry is replayed into the final zip stream.
1446
- */
1447
- createTempStream?: () => Promise<{ writable: WritableStream; readable: ReadableStream }>;
1448
- /**
1449
- * `true` to keep the order of the entry physically in the zip file.
1450
- *
1451
- * When set to `true`, the use of web workers will be improved.
1452
- *
1453
- * @defaultValue true
1454
- */
1455
- keepOrder?: boolean;
1456
- /**
1457
- * The password used to encrypt the content of the entry.
1458
- */
1459
- password?: string;
1460
- /**
1461
- * The password used to encrypt the content of the entry (raw).
1462
- */
1463
- rawPassword?: Uint8Array;
1464
- /**
1465
- * The encryption strength (AES):
1466
- * - 1: 128-bit encryption key
1467
- * - 2: 192-bit encryption key
1468
- * - 3: 256-bit encryption key
1469
- *
1470
- * @defaultValue 3
1471
- */
1472
- encryptionStrength?: 1 | 2 | 3;
1473
- /**
1474
- * The `AbortSignal` instance used to cancel the compression.
1475
- */
1476
- signal?: AbortSignal;
1477
- /**
1478
- * The last modification date.
1479
- *
1480
- * @defaultValue The current date.
1481
- */
1482
- lastModDate?: Date;
1483
- /**
1484
- * The last access date.
1485
- *
1486
- * This option is ignored if the {@link ZipWriterConstructorOptions#extendedTimestamp} option is set to `false`.
1487
- *
1488
- * @defaultValue The current date.
1489
- */
1490
- lastAccessDate?: Date;
1491
- /**
1492
- * The creation date.
1493
- *
1494
- * This option is ignored if the {@link ZipWriterConstructorOptions#extendedTimestamp} option is set to `false`.
1495
- *
1496
- * @defaultValue The current date.
1497
- */
1498
- creationDate?: Date;
1499
- /**
1500
- * `true` to store extended timestamp extra fields.
1501
- *
1502
- * When set to `false`, the maximum last modification date cannot exceed November 31, 2107 and the maximum accuracy is 2 seconds.
1503
- *
1504
- * @defaultValue true
1505
- */
1506
- extendedTimestamp?: boolean;
1507
- /**
1508
- * `true` to use the ZipCrypto algorithm to encrypt the content of the entry. Setting it to `true` will also
1509
- * set the {@link ZipWriterConstructorOptions#dataDescriptor} to `true`.
1510
- *
1511
- * It is not recommended to set `zipCrypto` to `true` because the ZipCrypto encryption can be easily broken.
1512
- *
1513
- * @defaultValue false
1514
- */
1515
- zipCrypto?: boolean;
1516
- /**
1517
- * The "Version" field.
1518
- */
1519
- version?: number;
1520
- /**
1521
- * The "Version made by" field.
1522
- *
1523
- * @defaultValue 20
1524
- */
1525
- versionMadeBy?: number;
1526
- /**
1527
- * `true` to mark the file names as UTF-8 setting the general purpose bit 11 in the header (see Appendix D -
1528
- * Language Encoding (EFS)), `false` to mark the names as compliant with the original IBM Code Page 437.
1529
- *
1530
- * Note that this does not ensure that the file names are in the correct encoding.
1531
- *
1532
- * @defaultValue true
1533
- */
1534
- useUnicodeFileNames?: boolean;
1535
- /**
1536
- * `true` to add a data descriptor.
1537
- *
1538
- * When set to `false`, the {@link ZipWriterConstructorOptions#bufferedWrite} option will automatically be
1539
- * set to `true`. It will be automatically set to `false` when it is `undefined` and the
1540
- * {@link ZipWriterConstructorOptions#bufferedWrite} option is set to `true`, or when the
1541
- * {@link ZipWriterConstructorOptions#zipCrypto} option is set to `true`. Otherwise, the default value is `true`.
1542
- */
1543
- dataDescriptor?: boolean;
1544
- /**
1545
- * `true` to add the signature of the data descriptor.
1546
- *
1547
- * @defaultValue false
1548
- */
1549
- dataDescriptorSignature?: boolean;
1550
- /**
1551
- * `true` to write {@link EntryMetaData#externalFileAttributes} in MS-DOS format for folder entries.
1552
- *
1553
- * @defaultValue false
1554
- */
1555
- msDosCompatible?: boolean;
1556
- /**
1557
- * The external file attribute.
1558
- *
1559
- * @defaultValue 0
1560
- */
1561
- externalFileAttributes?: number;
1562
- /**
1563
- * The Unix owner id to write in the Unix extra field or as part of the external attributes.
1564
- */
1565
- uid?: number;
1566
- /**
1567
- * The Unix group id to write in the Unix extra field or as part of the external attributes.
1568
- */
1569
- gid?: number;
1570
- /**
1571
- * The Unix mode (st_mode bits) to use when writing external attributes.
1572
- */
1573
- unixMode?: number;
1574
- /**
1575
- * `true` to set the setuid bit when writing the Unix mode.
1576
- */
1577
- setuid?: boolean;
1578
- /**
1579
- * `true` to set the setgid bit when writing the Unix mode.
1580
- */
1581
- setgid?: boolean;
1582
- /**
1583
- * `true` to set the sticky bit when writing the Unix mode.
1584
- */
1585
- sticky?: boolean;
1586
- /**
1587
- * Which Unix extra field format to write when creating entries that include Unix metadata.
1588
- * - "infozip": use Info-ZIP New Unix extra field
1589
- * - "unix": use the traditional Unix extra field format
1590
- */
1591
- unixExtraFieldType?: "infozip" | "unix";
1592
- /**
1593
- * The internal file attribute.
1594
- *
1595
- * @defaultValue 0
1596
- */
1597
- internalFileAttributes?: number;
1598
- /**
1599
- * When provided, the low 8-bit MS-DOS attributes to write into external file attributes.
1600
- * Must be an integer between 0 and 255.
1601
- */
1602
- msdosAttributesRaw?: number;
1603
- /**
1604
- * When provided, MS-DOS attribute flags (boolean object) to write into external file attributes low byte.
1605
- */
1606
- msdosAttributes?: {
1607
- readOnly?: boolean;
1608
- hidden?: boolean;
1609
- system?: boolean;
1610
- directory?: boolean;
1611
- archive?: boolean;
1612
- };
1613
- /**
1614
- * `false` to never write disk numbers in zip64 data.
1615
- *
1616
- * @defaultValue true
1617
- */
1618
- supportZip64SplitFile?: boolean;
1619
- /**
1620
- * `true`to produce zip files compatible with the USDZ specification.
1621
- *
1622
- * @defaultValue false
1623
- */
1624
- usdz?: boolean;
1625
- /**
1626
- * `true` to write the data as-is without compressing it and without crypting it.
1627
- */
1628
- passThrough?: boolean;
1629
- /**
1630
- * `true` to write encrypted data when `passThrough` is set to `true`.
1631
- */
1632
- encrypted?: boolean;
1633
- /**
1634
- * The offset of the first entry in the zip file.
1635
- */
1636
- offset?: number;
1637
- /**
1638
- * The compression method (e.g. 8 for DEFLATE, 0 for STORE).
1639
- */
1640
- compressionMethod?: number;
1641
- /**
1642
- * The function called for encoding the filename and the comment of the entry.
1643
- *
1644
- * @param text The text to encode.
1645
- * @returns The encoded text or `undefined` if the text should be encoded by zip.js.
1646
- */
1647
- encodeText?(text: string): Uint8Array | undefined;
1648
- }
1649
-
1650
- /**
1651
- * Represents options passed to {@link FileEntry#getData}, {@link ZipWriter.add} and `{@link ZipDirectory}.export*`.
1652
- */
1653
- export interface EntryDataOnprogressOptions {
1654
- /**
1655
- * The function called when starting compression/decompression.
1656
- *
1657
- * @param total The total number of bytes.
1658
- * @returns An empty promise or `undefined`.
1659
- */
1660
- onstart?(total: number): Promise<void> | undefined;
1661
- /**
1662
- * The function called during compression/decompression.
1663
- *
1664
- * @param progress The current progress in bytes.
1665
- * @param total The total number of bytes.
1666
- * @returns An empty promise or `undefined`.
1667
- */
1668
- onprogress?(progress: number, total: number): Promise<void> | undefined;
1669
- /**
1670
- * The function called when ending compression/decompression.
1671
- *
1672
- * @param computedSize The total number of bytes (computed).
1673
- * @returns An empty promise or `undefined`.
1674
- */
1675
- onend?(computedSize: number): Promise<void> | undefined;
1676
- }
1677
-
1678
- /**
1679
- * Represents options passed to {@link ZipReader#getEntries}, {@link ZipReader#getEntriesGenerator}, and {@link ZipWriter#close}.
1680
- */
1681
- export interface EntryOnprogressOptions {
1682
- /**
1683
- * The function called each time an entry is read/written.
1684
- *
1685
- * @param progress The entry index.
1686
- * @param total The total number of entries.
1687
- * @param entry The entry being read/written.
1688
- * @returns An empty promise or `undefined`.
1689
- */
1690
- onprogress?(
1691
- progress: number,
1692
- total: number,
1693
- entry: EntryMetaData
1694
- ): Promise<void> | undefined;
1695
- }
1696
-
1697
- /**
1698
- * Represents an entry in a zip file (Filesystem API).
1699
- */
1700
- declare class ZipEntry {
1701
- /**
1702
- * The relative filename of the entry.
1703
- */
1704
- name: string;
1705
- /**
1706
- * The underlying {@link EntryMetaData} instance.
1707
- */
1708
- data?: EntryMetaData;
1709
- /**
1710
- * The ID of the instance.
1711
- */
1712
- id: number;
1713
- /**
1714
- * The parent directory of the entry.
1715
- */
1716
- parent?: ZipEntry;
1717
- /**
1718
- * The uncompressed size of the content.
1719
- */
1720
- uncompressedSize: number;
1721
- /**
1722
- * The children of the entry.
1723
- */
1724
- children: ZipEntry[];
1725
- /**
1726
- * Clones the entry
1727
- *
1728
- * @param deepClone `true` to clone all the descendants.
1729
- */
1730
- clone(deepClone?: boolean): ZipEntry;
1731
- /**
1732
- * Returns the full filename of the entry
1733
- */
1734
- getFullname(): string;
1735
- /**
1736
- * Returns the filename of the entry relative to a parent directory
1737
- */
1738
- getRelativeName(ancestor: ZipDirectoryEntry): string;
1739
- /**
1740
- * Tests if a {@link ZipDirectoryEntry} instance is an ancestor of the entry
1741
- *
1742
- * @param ancestor The {@link ZipDirectoryEntry} instance.
1743
- */
1744
- isDescendantOf(ancestor: ZipDirectoryEntry): boolean;
1745
- /**
1746
- * Tests if the entry or any of its children is password protected
1747
- */
1748
- isPasswordProtected(): boolean;
1749
- /**
1750
- * Tests the password on the entry and all children if any, returns `true` if the entry is not password protected
1751
- */
1752
- checkPassword(
1753
- password: string,
1754
- options?: EntryGetDataOptions
1755
- ): Promise<boolean>;
1756
- /**
1757
- * Set the name of the entry
1758
- *
1759
- * @param name The new name of the entry.
1760
- */
1761
- rename(name: string): void;
1762
- }
1763
-
1764
- /**
1765
- * Represents a file entry in the zip (Filesystem API).
1766
- */
1767
- export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
1768
- /**
1769
- * `void` for {@link ZipFileEntry} instances.
1770
- */
1771
- directory: void;
1772
- /**
1773
- * The {@link Reader} instance used to read the content of the entry.
1774
- */
1775
- reader:
1776
- | Reader<ReaderType>
1777
- | ReadableReader
1778
- | ReadableStream
1779
- | Reader<unknown>[]
1780
- | ReadableReader[]
1781
- | ReadableStream[];
1782
- /**
1783
- * The {@link Writer} instance used to write the content of the entry.
1784
- */
1785
- writer:
1786
- | Writer<WriterType>
1787
- | WritableWriter
1788
- | WritableStream
1789
- | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>;
1790
- /**
1791
- * Retrieves the text content of the entry as a `string`
1792
- *
1793
- * @param encoding The encoding of the text.
1794
- * @param options The options.
1795
- * @returns A promise resolving to a `string`.
1796
- */
1797
- getText(encoding?: string, options?: EntryGetDataOptions): Promise<string>;
1798
- /**
1799
- * Retrieves the content of the entry as a `Blob` instance
1800
- *
1801
- * @param mimeType The MIME type of the content.
1802
- * @param options The options.
1803
- * @returns A promise resolving to a `Blob` instance.
1804
- */
1805
- getBlob(mimeType?: string, options?: EntryGetDataOptions): Promise<Blob>;
1806
- /**
1807
- * Retrieves the content of the entry as as a Data URI `string` encoded in Base64
1808
- *
1809
- * @param mimeType The MIME type of the content.
1810
- * @param options The options.
1811
- * @returns A promise resolving to a Data URI `string` encoded in Base64.
1812
- */
1813
- getData64URI(
1814
- mimeType?: string,
1815
- options?: EntryGetDataOptions
1816
- ): Promise<string>;
1817
- /**
1818
- * Retrieves the content of the entry as a `Uint8Array` instance
1819
- *
1820
- * @param options The options.
1821
- * @returns A promise resolving to a `Uint8Array` instance.
1822
- */
1823
- getUint8Array(options?: EntryGetDataOptions): Promise<Uint8Array>;
1824
- /**
1825
- * Retrieves the content of the entry via a `WritableStream` instance
1826
- *
1827
- * @param writable The `WritableStream` instance.
1828
- * @param options The options.
1829
- * @returns A promise resolving to the `WritableStream` instance.
1830
- */
1831
- getWritable(
1832
- writable?: WritableStream,
1833
- options?: EntryGetDataOptions
1834
- ): Promise<WritableStream>;
1835
- /**
1836
- * Retrieves the content of the entry via a {@link Writer} instance
1837
- *
1838
- * @param writer The {@link Writer} instance.
1839
- * @param options The options.
1840
- * @returns A promise resolving to data associated to the {@link Writer} instance.
1841
- */
1842
- getData<Type>(
1843
- writer:
1844
- | Writer<unknown>
1845
- | WritableWriter
1846
- | WritableStream
1847
- | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>,
1848
- options?: EntryGetDataOptions
1849
- ): Promise<Type>;
1850
- /**
1851
- * Retrieves the content of the entry as an `ArrayBuffer` instance
1852
- *
1853
- * @param options The options.
1854
- * @returns A promise resolving to an `ArrayBuffer` instance.
1855
- */
1856
- getArrayBuffer(options?: EntryGetDataOptions): Promise<ArrayBuffer>;
1857
- /**
1858
- * Replaces the content of the entry with a `Blob` instance
1859
- *
1860
- * @param blob The `Blob` instance.
1861
- */
1862
- replaceBlob(blob: Blob): void;
1863
- /**
1864
- * Replaces the content of the entry with a `string`
1865
- *
1866
- * @param text The `string`.
1867
- */
1868
- replaceText(text: string): void;
1869
- /**
1870
- * Replaces the content of the entry with a Data URI `string` encoded in Base64
1871
- *
1872
- * @param dataURI The Data URI `string` encoded in Base64.
1873
- */
1874
- replaceData64URI(dataURI: string): void;
1875
- /**
1876
- * Replaces the content of the entry with a `Uint8Array` instance
1877
- *
1878
- * @param array The `Uint8Array` instance.
1879
- */
1880
- replaceUint8Array(array: Uint8Array): void;
1881
- /**
1882
- * Replaces the content of the entry with a `ReadableStream` instance
1883
- *
1884
- * @param readable The `ReadableStream` instance.
1885
- */
1886
- replaceReadable(readable: ReadableStream): void;
1887
- }
1888
-
1889
- /**
1890
- * Represents a directory entry in the zip (Filesystem API).
1891
- */
1892
- export class ZipDirectoryEntry extends ZipEntry {
1893
- /**
1894
- * `true` for {@link ZipDirectoryEntry} instances.
1895
- */
1896
- directory: true;
1897
- /**
1898
- * Gets a {@link ZipEntry} child instance from its relative filename
1899
- *
1900
- * @param name The relative filename.
1901
- * @returns A {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance (use the {@link ZipFileEntry#directory} and {@link ZipDirectoryEntry#directory} properties to differentiate entries).
1902
- */
1903
- getChildByName(name: string): ZipEntry | undefined;
1904
- /**
1905
- * Adds a directory
1906
- *
1907
- * @param name The relative filename of the directory.
1908
- * @param options The options.
1909
- * @returns A {@link ZipDirectoryEntry} instance.
1910
- */
1911
- addDirectory(
1912
- name: string,
1913
- options?: ZipWriterAddDataOptions
1914
- ): ZipDirectoryEntry;
1915
- /**
1916
- * Adds an entry with content provided as text
1917
- *
1918
- * @param name The relative filename of the entry.
1919
- * @param text The text.
1920
- * @param options The options.
1921
- * @returns A {@link ZipFileEntry} instance.
1922
- */
1923
- addText(
1924
- name: string,
1925
- text: string,
1926
- options?: ZipWriterAddDataOptions
1927
- ): ZipFileEntry<string, string>;
1928
- /**
1929
- * Adds a entry entry with content provided as a `Blob` instance
1930
- *
1931
- * @param name The relative filename of the entry.
1932
- * @param blob The `Blob` instance.
1933
- * @param options The options.
1934
- * @returns A {@link ZipFileEntry} instance.
1935
- */
1936
- addBlob(
1937
- name: string,
1938
- blob: Blob,
1939
- options?: ZipWriterAddDataOptions
1940
- ): ZipFileEntry<Blob, Blob>;
1941
- /**
1942
- * Adds a entry entry with content provided as a Data URI `string` encoded in Base64
1943
- *
1944
- * @param name The relative filename of the entry.
1945
- * @param dataURI The Data URI `string` encoded in Base64.
1946
- * @param options The options.
1947
- * @returns A {@link ZipFileEntry} instance.
1948
- */
1949
- addData64URI(
1950
- name: string,
1951
- dataURI: string,
1952
- options?: ZipWriterAddDataOptions
1953
- ): ZipFileEntry<string, string>;
1954
- /**
1955
- * Adds an entry with content provided as a `Uint8Array` instance
1956
- *
1957
- * @param name The relative filename of the entry.
1958
- * @param array The `Uint8Array` instance.
1959
- * @param options The options.
1960
- * @returns A {@link ZipFileEntry} instance.
1961
- */
1962
- addUint8Array(
1963
- name: string,
1964
- array: Uint8Array,
1965
- options?: ZipWriterAddDataOptions
1966
- ): ZipFileEntry<Uint8Array, Uint8Array>;
1967
- /**
1968
- * Adds an entry with content fetched from a URL
1969
- *
1970
- * @param name The relative filename of the entry.
1971
- * @param url The URL.
1972
- * @param options The options.
1973
- * @returns A {@link ZipFileEntry} instance.
1974
- */
1975
- addHttpContent(
1976
- name: string,
1977
- url: string,
1978
- options?: HttpOptions & ZipWriterAddDataOptions
1979
- ): ZipFileEntry<string, void>;
1980
- /**
1981
- * Adds a entry entry with content provided via a `ReadableStream` instance
1982
- *
1983
- * @param name The relative filename of the entry.
1984
- * @param readable The `ReadableStream` instance.
1985
- * @param options The options.
1986
- * @returns A {@link ZipFileEntry} instance.
1987
- */
1988
- addReadable(
1989
- name: string,
1990
- readable: ReadableStream,
1991
- options?: ZipWriterAddDataOptions
1992
- ): ZipFileEntry<ReadableStream, void>;
1993
- /**
1994
- * Adds an entry with content provided via a `File` instance
1995
- *
1996
- * @param file The `File` instance.
1997
- * @param options The options.
1998
- * @returns A promise resolving to a {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance.
1999
- */
2000
- addFile(file: File, options?: ZipWriterAddDataOptions): Promise<ZipEntry>;
2001
- /**
2002
- * Adds an entry with content provided via a `FileSystemEntry` instance
2003
- *
2004
- * @param fileSystemEntry The `FileSystemEntry` instance.
2005
- * @param options The options.
2006
- * @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
2007
- */
2008
- addFileSystemEntry(
2009
- fileSystemEntry: FileSystemEntryLike,
2010
- options?: ZipWriterAddDataOptions
2011
- ): Promise<ZipEntry[]>;
2012
- /**
2013
- * Adds an entry with content provided via a `FileSystemHandle` instance
2014
- *
2015
- * @param fileSystemHandle The `fileSystemHandle` instance.
2016
- * @param options The options.
2017
- * @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
2018
- */
2019
- addFileSystemHandle(
2020
- fileSystemHandle: FileSystemHandleLike,
2021
- options?: ZipWriterAddDataOptions
2022
- ): Promise<ZipEntry[]>;
2023
- /**
2024
- * Extracts a zip file provided as a `Blob` instance into the entry
2025
- *
2026
- * @param blob The `Blob` instance.
2027
- * @param options The options.
2028
- */
2029
- importBlob(
2030
- blob: Blob,
2031
- options?: ZipReaderConstructorOptions
2032
- ): Promise<[ZipEntry]>;
2033
- /**
2034
- * Extracts a zip file provided as a Data URI `string` encoded in Base64 into the entry
2035
- *
2036
- * @param dataURI The Data URI `string` encoded in Base64.
2037
- * @param options The options.
2038
- */
2039
- importData64URI(
2040
- dataURI: string,
2041
- options?: ZipReaderConstructorOptions
2042
- ): Promise<[ZipEntry]>;
2043
- /**
2044
- * Extracts a zip file provided as a `Uint8Array` instance into the entry
2045
- *
2046
- * @param array The `Uint8Array` instance.
2047
- * @param options The options.
2048
- */
2049
- importUint8Array(
2050
- array: Uint8Array,
2051
- options?: ZipReaderConstructorOptions
2052
- ): Promise<[ZipEntry]>;
2053
- /**
2054
- * Extracts a zip file fetched from a URL into the entry
2055
- *
2056
- * @param url The URL.
2057
- * @param options The options.
2058
- */
2059
- importHttpContent(
2060
- url: string,
2061
- options?: ZipDirectoryEntryImportHttpOptions
2062
- ): Promise<[ZipEntry]>;
2063
- /**
2064
- * Extracts a zip file provided via a `ReadableStream` instance into the entry
2065
- *
2066
- * @param readable The `ReadableStream` instance.
2067
- * @param options The options.
2068
- */
2069
- importReadable(
2070
- readable: ReadableStream,
2071
- options?: ZipReaderConstructorOptions
2072
- ): Promise<[ZipEntry]>;
2073
- /**
2074
- * Extracts a zip file provided via a custom {@link Reader} instance into the entry
2075
- *
2076
- * @param reader The {@link Reader} instance.
2077
- * @param options The options.
2078
- */
2079
- importZip(
2080
- reader:
2081
- | Reader<unknown>
2082
- | ReadableReader
2083
- | ReadableStream
2084
- | Reader<unknown>[]
2085
- | ReadableReader[]
2086
- | ReadableStream[],
2087
- options?: ZipReaderConstructorOptions
2088
- ): Promise<[ZipEntry]>;
2089
- /**
2090
- * Returns a `Blob` instance containing a zip file of the entry and its descendants
2091
- *
2092
- * @param options The options.
2093
- * @returns A promise resolving to the `Blob` instance.
2094
- */
2095
- exportBlob(options?: ZipDirectoryEntryExportOptions): Promise<Blob>;
2096
- /**
2097
- * Returns a Data URI `string` encoded in Base64 containing a zip file of the entry and its descendants
2098
- *
2099
- * @param options The options.
2100
- * @returns A promise resolving to the Data URI `string` encoded in Base64.
2101
- */
2102
- exportData64URI(options?: ZipDirectoryEntryExportOptions): Promise<string>;
2103
- /**
2104
- * Returns a `Uint8Array` instance containing a zip file of the entry and its descendants
2105
- *
2106
- * @param options The options.
2107
- * @returns A promise resolving to the `Uint8Array` instance.
2108
- */
2109
- exportUint8Array(
2110
- options?: ZipDirectoryEntryExportOptions
2111
- ): Promise<Uint8Array>;
2112
- /**
2113
- * Creates a zip file via a `WritableStream` instance containing the entry and its descendants
2114
- *
2115
- * @param writable The `WritableStream` instance.
2116
- * @param options The options.
2117
- * @returns A promise resolving to the `Uint8Array` instance.
2118
- */
2119
- exportWritable(
2120
- writable?: WritableStream,
2121
- options?: ZipDirectoryEntryExportOptions
2122
- ): Promise<WritableStream>;
2123
- /**
2124
- * Creates a zip file via a custom {@link Writer} instance containing the entry and its descendants
2125
- *
2126
- * @param writer The {@link Writer} instance.
2127
- * @param options The options.
2128
- * @returns A promise resolving to the data.
2129
- */
2130
- exportZip(
2131
- writer:
2132
- | Writer<unknown>
2133
- | WritableWriter
2134
- | WritableStream
2135
- | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>,
2136
- options?: ZipDirectoryEntryExportOptions
2137
- ): Promise<unknown>;
2138
- }
2139
-
2140
- /**
2141
- * Represents the options passed to {@link ZipDirectoryEntry#importHttpContent}.
2142
- */
2143
- export interface ZipDirectoryEntryImportHttpOptions
2144
- extends ZipReaderConstructorOptions,
2145
- HttpOptions {}
2146
-
2147
- /**
2148
- * Represents the options passed to `{@link ZipDirectoryEntry}#export*()`.
2149
- */
2150
- export interface ZipDirectoryEntryExportOptions
2151
- extends ZipWriterConstructorOptions,
2152
- EntryDataOnprogressOptions {
2153
- /**
2154
- * `true` to use filenames relative to the entry instead of full filenames.
2155
- */
2156
- relativePath?: boolean;
2157
- /**
2158
- * The MIME type of the exported data when relevant.
2159
- */
2160
- mimeType?: string;
2161
- /**
2162
- * The options passed to the Reader instances
2163
- */
2164
- readerOptions?: ZipReaderConstructorOptions;
2165
- }
2166
-
2167
- /**
2168
- * Represents a Filesystem instance.
2169
- *
2170
- * @example
2171
- * Here is an example showing how to create and read a zip file containing a compressed text file:
2172
- * ```
2173
- * const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.";
2174
- * const FILENAME = "lorem.txt";
2175
- * const BLOB = new Blob([TEXT_CONTENT], { type: zip.getMimeType(FILENAME) });
2176
- * let zipFs = new zip.fs.FS();
2177
- * zipFs.addBlob("lorem.txt", BLOB);
2178
- * const zippedBlob = await zipFs.exportBlob();
2179
- * zipFs = new zip.fs.FS();
2180
- * await zipFs.importBlob(zippedBlob);
2181
- * const firstEntry = zipFs.children[0];
2182
- * const unzippedBlob = await firstEntry.getBlob(zip.getMimeType(firstEntry.name));
2183
- * ```
2184
- */
2185
- export class FS extends ZipDirectoryEntry {
2186
- /**
2187
- * The root directory.
2188
- */
2189
- root: ZipDirectoryEntry;
2190
- /**
2191
- * Removes a {@link ZipEntry} instance and its children
2192
- *
2193
- * @param entry The {@link ZipEntry} instance to remove.
2194
- */
2195
- remove(entry: ZipEntry): void;
2196
- /**
2197
- * Moves a {@link ZipEntry} instance and its children into a {@link ZipDirectoryEntry} instance
2198
- *
2199
- * @param entry The {@link ZipEntry} instance to move.
2200
- * @param destination The {@link ZipDirectoryEntry} instance.
2201
- */
2202
- move(entry: ZipEntry, destination: ZipDirectoryEntry): void;
2203
- /**
2204
- * Returns a {@link ZipEntry} instance from its full filename
2205
- *
2206
- * @param fullname The full filename.
2207
- * @returns The {@link ZipEntry} instance.
2208
- */
2209
- find(fullname: string): ZipEntry | undefined;
2210
- /**
2211
- * Returns a {@link ZipEntry} instance from the value of {@link ZipEntry#id}
2212
- *
2213
- * @param id The id of the {@link ZipEntry} instance.
2214
- * @returns The {@link ZipEntry} instance.
2215
- */
2216
- getById(id: number): ZipEntry | undefined;
2217
- }
2218
-
2219
- /**
2220
- * The Filesystem API.
2221
- */
2222
- export const fs: {
2223
- /**
2224
- * The Filesystem constructor.
2225
- *
2226
- * @defaultValue {@link FS}
2227
- */
2228
- FS: typeof FS;
2229
- /**
2230
- * The {@link ZipDirectoryEntry} constructor.
2231
- *
2232
- * @defaultValue {@link ZipDirectoryEntry}
2233
- */
2234
- ZipDirectoryEntry: typeof ZipDirectoryEntry;
2235
- /**
2236
- * The {@link ZipFileEntry} constructor.
2237
- *
2238
- * @defaultValue {@link ZipFileEntry}
2239
- */
2240
- ZipFileEntry: typeof ZipFileEntry;
2241
- };
2242
-
2243
- // The error messages.
2244
- /**
2245
- * HTTP range error
2246
- */
2247
- export const ERR_HTTP_RANGE: string;
2248
- /**
2249
- * Zip format error
2250
- */
2251
- export const ERR_BAD_FORMAT: string;
2252
- /**
2253
- * End of Central Directory Record not found error
2254
- */
2255
- export const ERR_EOCDR_NOT_FOUND: string;
2256
- /**
2257
- * Zip64 End of Central Directory Locator not found error
2258
- */
2259
- export const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: string;
2260
- /**
2261
- * Central Directory not found error
2262
- */
2263
- export const ERR_CENTRAL_DIRECTORY_NOT_FOUND: string;
2264
- /**
2265
- * Local file header not found error
2266
- */
2267
- export const ERR_LOCAL_FILE_HEADER_NOT_FOUND: string;
2268
- /**
2269
- * Extra field Zip64 not found error
2270
- */
2271
- export const ERR_EXTRAFIELD_ZIP64_NOT_FOUND: string;
2272
- /**
2273
- * Encrypted entry error
2274
- */
2275
- export const ERR_ENCRYPTED: string;
2276
- /**
2277
- * Unsupported encryption error
2278
- */
2279
- export const ERR_UNSUPPORTED_ENCRYPTION: string;
2280
- /**
2281
- * Unsupported compression error
2282
- */
2283
- export const ERR_UNSUPPORTED_COMPRESSION: string;
2284
- /**
2285
- * Invalid signature error
2286
- */
2287
- export const ERR_INVALID_SIGNATURE: string;
2288
- /**
2289
- * Invalid uncompressed size error
2290
- */
2291
- export const ERR_INVALID_UNCOMPRESSED_SIZE: string;
2292
- /**
2293
- * Invalid password error
2294
- */
2295
- export const ERR_INVALID_PASSWORD: string;
2296
- /**
2297
- * Duplicate entry error
2298
- */
2299
- export const ERR_DUPLICATED_NAME: string;
2300
- /**
2301
- * Invalid comment error
2302
- */
2303
- export const ERR_INVALID_COMMENT: string;
2304
- /**
2305
- * Invalid entry name error
2306
- */
2307
- export const ERR_INVALID_ENTRY_NAME: string;
2308
- /**
2309
- * Invalid entry comment error
2310
- */
2311
- export const ERR_INVALID_ENTRY_COMMENT: string;
2312
- /**
2313
- * Invalid version error
2314
- */
2315
- export const ERR_INVALID_VERSION: string;
2316
- /**
2317
- * Invalid extra field type error
2318
- */
2319
- export const ERR_INVALID_EXTRAFIELD_TYPE: string;
2320
- /**
2321
- * Invalid extra field data error
2322
- */
2323
- export const ERR_INVALID_EXTRAFIELD_DATA: string;
2324
- /**
2325
- * Invalid encryption strength error
2326
- */
2327
- export const ERR_INVALID_ENCRYPTION_STRENGTH: string;
2328
- /**
2329
- * Invalid format error
2330
- */
2331
- export const ERR_UNSUPPORTED_FORMAT: string;
2332
- /**
2333
- * Split zip file error
2334
- */
2335
- export const ERR_SPLIT_ZIP_FILE: string;
2336
- /**
2337
- * Overlapping entry error
2338
- */
2339
- export const ERR_OVERLAPPING_ENTRY: string;
2340
- /**
2341
- * Iteration completed too soon error
2342
- */
2343
- export const ERR_ITERATOR_COMPLETED_TOO_SOON: string;
2344
- /**
2345
- * Undefined uncompressed size error
2346
- */
2347
- export const ERR_UNDEFINED_UNCOMPRESSED_SIZE: string;
2348
- /**
2349
- * Writer not initialized error
2350
- */
2351
- export const ERR_WRITER_NOT_INITIALIZED: string;
2352
- /**
2353
- * Zip file not empty error
2354
- */
2355
- export const ERR_ZIP_NOT_EMPTY: string;
1
+ /**
2
+ * zip.js is a JavaScript open-source library (BSD-3-Clause license) for
3
+ * compressing and decompressing zip files. It has been designed to handle large amounts
4
+ * of data. It supports notably multi-core compression, native compression with
5
+ * compression streams, archives larger than 4GB with Zip64, split zip files, data
6
+ * encryption, and Deflate64 decompression.
7
+ *
8
+ * @author Gildas Lormeau
9
+ * @license BSD-3-Clause
10
+ *
11
+ * @example
12
+ * Hello world
13
+ * ```js
14
+ * import {
15
+ * BlobReader,
16
+ * BlobWriter,
17
+ * TextReader,
18
+ * TextWriter,
19
+ * ZipReader,
20
+ * ZipWriter,
21
+ * } from from "@zip-js/zip-js";
22
+ *
23
+ * // ----
24
+ * // Write the zip file
25
+ * // ----
26
+ *
27
+ * // Creates a BlobWriter object where the zip content will be written.
28
+ * const zipFileWriter = new BlobWriter();
29
+ *
30
+ * // Creates a TextReader object storing the text of the entry to add in the zip
31
+ * // (i.e. "Hello world!").
32
+ * const helloWorldReader = new TextReader("Hello world!");
33
+ *
34
+ * // Creates a ZipWriter object writing data via `zipFileWriter`, adds the entry
35
+ * // "hello.txt" containing the text "Hello world!" via `helloWorldReader`, and
36
+ * // closes the writer.
37
+ * const zipWriter = new ZipWriter(zipFileWriter);
38
+ * await zipWriter.add("hello.txt", helloWorldReader);
39
+ * await zipWriter.close();
40
+ *
41
+ * // Retrieves the Blob object containing the zip content into `zipFileBlob`. It
42
+ * // is also returned by zipWriter.close() for more convenience.
43
+ * const zipFileBlob = await zipFileWriter.getData();
44
+ *
45
+ * // ----
46
+ * // Read the zip file
47
+ * // ----
48
+ *
49
+ * // Creates a BlobReader object used to read `zipFileBlob`.
50
+ * const zipFileReader = new BlobReader(zipFileBlob);
51
+ * // Creates a TextWriter object where the content of the first entry in the zip
52
+ * // will be written.
53
+ * const helloWorldWriter = new TextWriter();
54
+ *
55
+ * // Creates a ZipReader object reading the zip content via `zipFileReader`,
56
+ * // retrieves metadata (name, dates, etc.) of the first entry, retrieves its
57
+ * // content via `helloWorldWriter`, and closes the reader.
58
+ * const zipReader = new ZipReader(zipFileReader);
59
+ * const firstEntry = (await zipReader.getEntries()).shift();
60
+ * const helloWorldText = await firstEntry.getData(helloWorldWriter);
61
+ * await zipReader.close();
62
+ *
63
+ * // Displays "Hello world!".
64
+ * console.log(helloWorldText);
65
+ * ```
66
+ *
67
+ * @example
68
+ * Hello world with Streams
69
+ * ```js
70
+ * import {
71
+ * BlobReader,
72
+ * ZipReader,
73
+ * ZipWriter,
74
+ * } from "@zip-js/zip-js";
75
+ *
76
+ * // ----
77
+ * // Write the zip file
78
+ * // ----
79
+ *
80
+ * // Creates a TransformStream object, the zip content will be written in the
81
+ * // `writable` property.
82
+ * const zipFileStream = new TransformStream();
83
+ * // Creates a Promise object resolved to the zip content returned as a Blob
84
+ * // object retrieved from `zipFileStream.readable`.
85
+ * const zipFileBlobPromise = new Response(zipFileStream.readable).blob();
86
+ * // Creates a ReadableStream object storing the text of the entry to add in the
87
+ * // zip (i.e. "Hello world!").
88
+ * const helloWorldReadable = new Blob(["Hello world!"]).stream();
89
+ *
90
+ * // Creates a ZipWriter object writing data into `zipFileStream.writable`, adds
91
+ * // the entry "hello.txt" containing the text "Hello world!" retrieved from
92
+ * // `helloWorldReadable`, and closes the writer.
93
+ * const zipWriter = new ZipWriter(zipFileStream.writable);
94
+ * await zipWriter.add("hello.txt", helloWorldReadable);
95
+ * await zipWriter.close();
96
+ *
97
+ * // Retrieves the Blob object containing the zip content into `zipFileBlob`.
98
+ * const zipFileBlob = await zipFileBlobPromise;
99
+ *
100
+ * // ----
101
+ * // Read the zip file
102
+ * // ----
103
+ *
104
+ * // Creates a BlobReader object used to read `zipFileBlob`.
105
+ * const zipFileReader = new BlobReader(zipFileBlob);
106
+ * // Creates a TransformStream object, the content of the first entry in the zip
107
+ * // will be written in the `writable` property.
108
+ * const helloWorldStream = new TransformStream();
109
+ * // Creates a Promise object resolved to the content of the first entry returned
110
+ * // as text from `helloWorldStream.readable`.
111
+ * const helloWorldTextPromise = new Response(helloWorldStream.readable).text();
112
+ *
113
+ * // Creates a ZipReader object reading the zip content via `zipFileReader`,
114
+ * // retrieves metadata (name, dates, etc.) of the first entry, retrieves its
115
+ * // content into `helloWorldStream.writable`, and closes the reader.
116
+ * const zipReader = new ZipReader(zipFileReader);
117
+ * const firstEntry = (await zipReader.getEntries()).shift();
118
+ * await firstEntry.getData(helloWorldStream.writable);
119
+ * await zipReader.close();
120
+ *
121
+ * // Displays "Hello world!".
122
+ * const helloWorldText = await helloWorldTextPromise;
123
+ * console.log(helloWorldText);
124
+ * ```
125
+ *
126
+ * @example
127
+ * Adding concurrently multiple entries in a zip file
128
+ * ```js
129
+ * import {
130
+ * BlobWriter,
131
+ * HttpReader,
132
+ * TextReader,
133
+ * ZipWriter,
134
+ * } from "@zip-js/zip-js";
135
+ *
136
+ * const README_URL = "https://unpkg.com/@zip.js/zip.js/README.md";
137
+ * getZipFileBlob()
138
+ * .then(downloadFile);
139
+ *
140
+ * async function getZipFileBlob() {
141
+ * const zipWriter = new ZipWriter(new BlobWriter("application/zip"));
142
+ * await Promise.all([
143
+ * zipWriter.add("hello.txt", new TextReader("Hello world!")),
144
+ * zipWriter.add("README.md", new HttpReader(README_URL)),
145
+ * ]);
146
+ * return zipWriter.close();
147
+ * }
148
+ *
149
+ * function downloadFile(blob) {
150
+ * document.body.appendChild(Object.assign(document.createElement("a"), {
151
+ * download: "hello.zip",
152
+ * href: URL.createObjectURL(blob),
153
+ * textContent: "Download zip file",
154
+ * }));
155
+ * }
156
+ * ```
157
+ *
158
+ * @module
159
+ */
160
+
161
+ /**
162
+ * Represents the `FileSystemEntry` class.
163
+ *
164
+ * @see {@link https://wicg.github.io/entries-api/#api-entry|specification}
165
+ */
166
+ // deno-lint-ignore no-empty-interface
167
+ interface FileSystemEntryLike {}
168
+
169
+ /**
170
+ * Represents the `FileSystemHandle` class.
171
+ *
172
+ * @see {@link https://fs.spec.whatwg.org/#api-filesystemhandle}
173
+ */
174
+ // deno-lint-ignore no-empty-interface
175
+ interface FileSystemHandleLike {}
176
+
177
+ /**
178
+ * Represents a generic `TransformStream` class.
179
+ *
180
+ * @see {@link https://streams.spec.whatwg.org/#generictransformstream|specification}
181
+ */
182
+ declare class TransformStreamLike {
183
+ /**
184
+ * The readable stream.
185
+ */
186
+ readable: ReadableStream;
187
+ /**
188
+ * The writable stream.
189
+ */
190
+ writable: WritableStream;
191
+ }
192
+
193
+ /**
194
+ * Configures zip.js
195
+ *
196
+ * @param configuration The configuration.
197
+ */
198
+ export function configure(configuration: Configuration): void;
199
+
200
+ /**
201
+ * Represents the configuration passed to {@link configure}.
202
+ */
203
+ export interface Configuration extends WorkerConfiguration {
204
+ /**
205
+ * The maximum number of web workers used to compress/decompress data simultaneously.
206
+ *
207
+ * @defaultValue `navigator.hardwareConcurrency`
208
+ */
209
+ maxWorkers?: number;
210
+ /**
211
+ * The delay in milliseconds before idle web workers are automatically terminated. You can call `terminateWorkers()` to terminate idle workers.
212
+ *
213
+ * @defaultValue 5000
214
+ */
215
+ terminateWorkerTimeout?: number;
216
+ /**
217
+ * The delay in milliseconds after which the oldest pending compression/decompression task is run without a web worker when no task completes.
218
+ *
219
+ * It prevents deadlocks when entries read from a `ZipReader` are added concurrently into a `ZipWriter` and all the web workers are waiting for data.
220
+ *
221
+ * @defaultValue 5000
222
+ */
223
+ workerStarvationTimeout?: number;
224
+ /**
225
+ * The URI of the web worker.
226
+ *
227
+ * 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.
228
+ *
229
+ * Here is an example to import the worker module as a URL (see `?url`) and avoid CSP issues:
230
+ * ```
231
+ * import workerURI from "@zip.js/zip.js/dist/zip-web-worker.js?url";
232
+ *
233
+ * configure({
234
+ * workerURI
235
+ * });
236
+ * ```
237
+ *
238
+ * @defaultValue "./core/web-worker.js"
239
+ */
240
+ workerURI?: string;
241
+ /**
242
+ * 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.
243
+ *
244
+ * Here is an example to import the WASM module as a URL (see `?url`) and avoid CSP issues:
245
+ * ```
246
+ * import wasmURI from "@zip.js/zip.js/dist/zip-module.wasm?url";
247
+ *
248
+ * configure({
249
+ * wasmURI
250
+ * });
251
+ * ```
252
+ *
253
+ * @defaultValue "./core/streams/zlib-wasm/zlib-streams.wasm"
254
+ */
255
+ wasmURI?: string;
256
+ /**
257
+ * The size of the chunks in bytes during data compression/decompression.
258
+ *
259
+ * @defaultValue 65536
260
+ */
261
+ chunkSize?: number;
262
+ /**
263
+ * The stream implementation used to compress data when `useCompressionStream` is set to `true`.
264
+ *
265
+ * @defaultValue {@link CodecStream}
266
+ */
267
+ CompressionStream?: typeof TransformStreamLike;
268
+ /**
269
+ * The stream implementation used to decompress data when `useCompressionStream` is set to `true`.
270
+ *
271
+ * @defaultValue {@link CodecStream}
272
+ */
273
+ DecompressionStream?: typeof TransformStreamLike;
274
+ /**
275
+ * The stream implementation used to compress data when `useCompressionStream` is set to `false`.
276
+ *
277
+ * @defaultValue {@link CodecStream}
278
+ */
279
+ CompressionStreamZlib?: typeof TransformStreamLike;
280
+ /**
281
+ * The stream implementation used to decompress data when `useCompressionStream` is set to `false`.
282
+ *
283
+ * @defaultValue {@link CodecStream}
284
+ */
285
+ DecompressionStreamZlib?: typeof TransformStreamLike;
286
+ }
287
+
288
+ /**
289
+ * Represents configuration passed to {@link configure}, the constructor of {@link ZipReader}, {@link FileEntry#getData}, the constructor of {@link ZipWriter}, and {@link ZipWriter#add}.
290
+ */
291
+ export interface WorkerConfiguration {
292
+ /**
293
+ * `true` to use web workers to compress/decompress data in non-blocking background processes.
294
+ *
295
+ * @defaultValue true
296
+ */
297
+ useWebWorkers?: boolean;
298
+ /**
299
+ * `true` to use the native API `CompressionStream`/`DecompressionStream` to compress/decompress data.
300
+ *
301
+ * @defaultValue true
302
+ */
303
+ useCompressionStream?: boolean;
304
+ /**
305
+ * `true` to transfer stream ownership to web workers.
306
+ *
307
+ * @defaultValue true
308
+ */
309
+ transferStreams?: boolean;
310
+ }
311
+
312
+ /**
313
+ * Terminates all the web workers
314
+ */
315
+ export function terminateWorkers(): Promise<void>;
316
+
317
+ /**
318
+ * Represents a class implementing `CompressionStream` or `DecompressionStream` interfaces.
319
+ */
320
+ declare class CodecStream extends TransformStream {}
321
+
322
+ /**
323
+ * Returns the MIME type corresponding to a filename extension.
324
+ *
325
+ * @param fileExtension the extension of the filename.
326
+ * @returns The corresponding MIME type.
327
+ */
328
+ export function getMimeType(fileExtension: string): string;
329
+
330
+ /**
331
+ * Represents an instance used to read or write unknown type of data.
332
+ *
333
+ * zip.js can handle multiple types of data thanks to a generic API. This feature is based on 2 abstract constructors: {@link Reader} and {@link Writer}.
334
+ * The classes inheriting from {@link Reader} help to read data from a source of data. The classes inheriting from {@link Writer} help to write data into a destination.
335
+ */
336
+ export interface Initializable {
337
+ /**
338
+ * Initializes the instance asynchronously
339
+ */
340
+ init?(): Promise<void>;
341
+ }
342
+
343
+ /**
344
+ * Represents an instance used to read data from a `ReadableStream` instance.
345
+ */
346
+ export interface ReadableReader {
347
+ /**
348
+ * The `ReadableStream` instance.
349
+ */
350
+ readable: ReadableStream;
351
+ }
352
+
353
+ /**
354
+ * Represents an instance used to read unknown type of data.
355
+ *
356
+ * @example
357
+ * Here is an example of custom {@link Reader} class used to read binary strings:
358
+ * ```
359
+ * class BinaryStringReader extends Reader {
360
+ *
361
+ * constructor(binaryString) {
362
+ * super();
363
+ * this.binaryString = binaryString;
364
+ * }
365
+ *
366
+ * init() {
367
+ * super.init();
368
+ * this.size = this.binaryString.length;
369
+ * }
370
+ *
371
+ * readUint8Array(offset, length) {
372
+ * const result = new Uint8Array(length);
373
+ * for (let indexCharacter = 0; indexCharacter < length; indexCharacter++) {
374
+ * result[indexCharacter] = this.binaryString.charCodeAt(indexCharacter + offset) & 0xFF;
375
+ * }
376
+ * return result;
377
+ * }
378
+ * }
379
+ * ```
380
+ */
381
+ export class Reader<Type> implements Initializable, ReadableReader {
382
+ /**
383
+ * Creates the {@link Reader} instance
384
+ *
385
+ * @param value The data to read.
386
+ */
387
+ constructor(value: Type);
388
+ /**
389
+ * The `ReadableStream` instance.
390
+ */
391
+ readable: ReadableStream;
392
+ /**
393
+ * The total size of the data in bytes.
394
+ */
395
+ size: number;
396
+ /**
397
+ * Initializes the instance asynchronously
398
+ */
399
+ init?(): Promise<void>;
400
+ /**
401
+ * Reads a chunk of data
402
+ *
403
+ * @param index The byte index of the data to read.
404
+ * @param length The length of the data to read in bytes.
405
+ * @returns A promise resolving to a chunk of data. The data must be trucated to the remaining size if the requested length is larger than the remaining size.
406
+ */
407
+ readUint8Array(index: number, length: number): Promise<Uint8Array>;
408
+ }
409
+
410
+ /**
411
+ * Represents a {@link Reader} instance used to read data provided as a `string`.
412
+ */
413
+ export class TextReader extends Reader<string> {}
414
+
415
+ /**
416
+ * Represents a {@link Reader} instance used to read data provided as a `Blob` instance.
417
+ */
418
+ export class BlobReader extends Reader<Blob> {}
419
+
420
+ /**
421
+ * Represents a {@link Reader} instance used to read data provided as a Data URI `string` encoded in Base64.
422
+ */
423
+ export class Data64URIReader extends Reader<string> {}
424
+
425
+ /**
426
+ * Represents a {@link Reader} instance used to read data provided as a `Uint8Array` instance.
427
+ */
428
+ export class Uint8ArrayReader extends Reader<Uint8Array> {}
429
+
430
+ /**
431
+ * Represents a {@link Reader} instance used to read data provided as an array of {@link ReadableReader} instances (e.g. split zip files).
432
+ */
433
+ export class SplitDataReader extends Reader<
434
+ Reader<unknown>[] | ReadableReader[] | ReadableStream[]
435
+ > {}
436
+
437
+ /**
438
+ * Represents a URL stored into a `string`.
439
+ */
440
+ type URLString = string;
441
+
442
+ /**
443
+ * Represents a {@link Reader} instance used to fetch data from a URL.
444
+ */
445
+ export class HttpReader extends Reader<URLString> {
446
+ /**
447
+ * Creates the {@link HttpReader} instance
448
+ *
449
+ * @param url The URL of the data.
450
+ * @param options The options.
451
+ */
452
+ constructor(url: URLString | URL, options?: HttpOptions);
453
+ }
454
+
455
+ /**
456
+ * Represents a {@link Reader} instance used to fetch data from servers returning `Accept-Ranges` headers.
457
+ */
458
+ export class HttpRangeReader extends HttpReader {
459
+ /**
460
+ * Creates the {@link HttpRangeReader} instance. It is particularly useful for reading ZIP files via HTTP.
461
+ * If you just want to add content retrieved via HTTP to a ZIP file, you can simply use
462
+ * `Response#body` {@link https://developer.mozilla.org/en-US/docs/Web/API/Response/body} instead.
463
+ *
464
+ * @param url The URL of the data.
465
+ * @param options The options.
466
+ */
467
+ constructor(url: URLString | URL, options?: HttpRangeOptions);
468
+ }
469
+
470
+ /**
471
+ * Represents the options passed to the constructor of {@link HttpReader}.
472
+ */
473
+ export interface HttpOptions extends HttpRangeOptions {
474
+ /**
475
+ * `true` to use `Range` headers when fetching data from servers returning `Accept-Ranges` headers.
476
+ *
477
+ * @defaultValue false
478
+ */
479
+ useRangeHeader?: boolean;
480
+ /**
481
+ * `true` to always use `Range` headers when fetching data.
482
+ *
483
+ * @defaultValue false
484
+ */
485
+ forceRangeRequests?: boolean;
486
+ /**
487
+ * `true` to prevent using `HEAD` HTTP request in order the get the size of the content.
488
+ * `false` to explicitly use `HEAD`, this is useful in case of CORS where `Access-Control-Expose-Headers: Content-Range` is not returned by the server.
489
+ *
490
+ * @defaultValue false
491
+ */
492
+ preventHeadRequest?: boolean;
493
+ /**
494
+ * `true` to use `Range: bytes=-22` on the first request and cache the EOCD, make sure beforehand that the server supports a suffix range request.
495
+ *
496
+ * @defaultValue false
497
+ */
498
+ combineSizeEocd?: boolean;
499
+ }
500
+
501
+ /**
502
+ * Represents options passed to the constructor of {@link HttpRangeReader} and {@link HttpReader}.
503
+ */
504
+ export interface HttpRangeOptions {
505
+ /**
506
+ * `true` to rely `XMLHttpRequest` instead of `fetch` to fetch data.
507
+ *
508
+ * @defaultValue false
509
+ */
510
+ useXHR?: boolean;
511
+ /**
512
+ * The function used to fetch the data. It takes precedence over {@link HttpRangeOptions#useXHR}
513
+ * when set. The returned object must expose the `status`, `statusText` and `headers` properties,
514
+ * and the `arrayBuffer()` method of the `Response` class.
515
+ *
516
+ * @defaultValue `fetch`
517
+ */
518
+ fetch?(input: string, init?: RequestInit): Promise<Response>;
519
+ /**
520
+ * The HTTP headers.
521
+ */
522
+ headers?: Iterable<[string, string]> | Map<string, string>;
523
+ }
524
+
525
+ /**
526
+ * Represents an instance used to write data into a `WritableStream` instance.
527
+ */
528
+ export interface WritableWriter {
529
+ /**
530
+ * The `WritableStream` instance.
531
+ */
532
+ writable: WritableStream;
533
+ /**
534
+ * The maximum size of split data when creating a {@link ZipWriter} instance or when calling {@link FileEntry#getData} with a generator of {@link WritableWriter} instances.
535
+ */
536
+ maxSize?: number;
537
+ }
538
+
539
+ /**
540
+ * Represents an instance used to write unknown type of data.
541
+ *
542
+ * @example
543
+ * Here is an example of custom {@link Writer} class used to write binary strings:
544
+ * ```
545
+ * class BinaryStringWriter extends Writer {
546
+ *
547
+ * constructor() {
548
+ * super();
549
+ * this.binaryString = "";
550
+ * }
551
+ *
552
+ * writeUint8Array(array) {
553
+ * for (let indexCharacter = 0; indexCharacter < array.length; indexCharacter++) {
554
+ * this.binaryString += String.fromCharCode(array[indexCharacter]);
555
+ * }
556
+ * }
557
+ *
558
+ * getData() {
559
+ * return this.binaryString;
560
+ * }
561
+ * }
562
+ * ```
563
+ */
564
+ export class Writer<Type> implements Initializable, WritableWriter {
565
+ /**
566
+ * The `WritableStream` instance.
567
+ */
568
+ writable: WritableStream;
569
+ /**
570
+ * Initializes the instance asynchronously
571
+ *
572
+ * @param size the total size of the written data in bytes.
573
+ */
574
+ init?(size?: number): Promise<void>;
575
+ /**
576
+ * Appends a chunk of data
577
+ *
578
+ * @param array The chunk data to append.
579
+ *
580
+ * @virtual
581
+ */
582
+ writeUint8Array(array: Uint8Array): Promise<void>;
583
+ /**
584
+ * Retrieves all the written data
585
+ *
586
+ * @returns A promise resolving to the written data.
587
+ */
588
+ getData(): Promise<Type>;
589
+ }
590
+
591
+ /**
592
+ * Represents a {@link Writer} instance used to retrieve the written data as a `string`.
593
+ */
594
+ export class TextWriter extends Writer<string> {
595
+ /**
596
+ * Creates the {@link TextWriter} instance
597
+ *
598
+ * @param encoding The encoding of the text.
599
+ */
600
+ constructor(encoding?: string);
601
+ }
602
+
603
+ /**
604
+ * Represents a {@link WritableWriter} instance used to retrieve the written data as a `Blob` instance.
605
+ */
606
+ export class BlobWriter implements Initializable, WritableWriter {
607
+ /**
608
+ * The `WritableStream` instance.
609
+ */
610
+ writable: WritableStream;
611
+ /**
612
+ * Initializes the instance asynchronously
613
+ */
614
+ init(): Promise<void>;
615
+ /**
616
+ * Creates the {@link BlobWriter} instance
617
+ *
618
+ * @param mimeString The MIME type of the content.
619
+ */
620
+ constructor(mimeString?: string);
621
+ /**
622
+ * Retrieves all the written data
623
+ *
624
+ * @returns A promise resolving to the written data.
625
+ */
626
+ getData(): Promise<Blob>;
627
+ }
628
+
629
+ /**
630
+ * Represents a {@link Writer} instance used to retrieve the written data as a Data URI `string` encoded in Base64.
631
+ */
632
+ export class Data64URIWriter extends Writer<string> {
633
+ /**
634
+ * Creates the {@link Data64URIWriter} instance
635
+ *
636
+ * @param mimeString The MIME type of the content.
637
+ */
638
+ constructor(mimeString?: string);
639
+ }
640
+
641
+ /**
642
+ * Represents a {@link Writer} instance used to retrieve the written data from a generator of {@link WritableWriter} instances (i.e. split zip files).
643
+ */
644
+ export class SplitDataWriter implements Initializable, WritableWriter {
645
+ /**
646
+ * The `WritableStream` instance.
647
+ */
648
+ writable: WritableStream;
649
+ /**
650
+ * Initializes the instance asynchronously
651
+ */
652
+ init(): Promise<void>;
653
+ /**
654
+ * Creates the {@link SplitDataWriter} instance
655
+ *
656
+ * @param writerGenerator A generator of Writer instances.
657
+ * @param maxSize The maximum size of the data written into {@link Writer} instances (default: 4GB).
658
+ */
659
+ constructor(
660
+ writerGenerator: AsyncGenerator<
661
+ Writer<unknown> | WritableWriter | WritableStream,
662
+ boolean
663
+ >,
664
+ maxSize?: number
665
+ );
666
+ }
667
+
668
+ /**
669
+ * Represents a {@link Writer} instance used to retrieve the written data as a `Uint8Array` instance.
670
+ */
671
+ export class Uint8ArrayWriter extends Writer<Uint8Array<ArrayBuffer>> {
672
+ /**
673
+ * Creates the {@link Uint8ArrayWriter} instance
674
+ *
675
+ * @param defaultBufferSize The initial size of the internal buffer (default: 256KB).
676
+ */
677
+ constructor(defaultBufferSize?: number);
678
+ }
679
+
680
+ /**
681
+ * Represents an instance used to create an unzipped stream.
682
+ *
683
+ * @example
684
+ * This example will take a zip file, decompress it and then save its files and directories to disk.
685
+ * ```
686
+ * import {resolve} from "https://deno.land/std/path/mod.ts";
687
+ * import {ensureDir, ensureFile} from "https://deno.land/std/fs/mod.ts";
688
+ *
689
+ * for await (const entry of (await fetch(urlToZippedFile)).body.pipeThrough(new ZipReaderStream())) {
690
+ * const fullPath = resolve(destination, entry.filename);
691
+ * if (entry.directory) {
692
+ * await ensureDir(fullPath);
693
+ * continue;
694
+ * }
695
+ *
696
+ * await ensureFile(fullPath);
697
+ * await entry.readable?.pipeTo((await Deno.create(fullPath)).writable);
698
+ * }
699
+ * ```
700
+ */
701
+ export class ZipReaderStream<T> {
702
+ /**
703
+ * Creates the stream.
704
+ *
705
+ * @param options The options.
706
+ */
707
+ constructor(options?: ZipReaderConstructorOptions);
708
+
709
+ /**
710
+ * The readable stream.
711
+ */
712
+ readable: ReadableStream<
713
+ Omit<Entry, "getData"> & { readable?: ReadableStream<Uint8Array> }
714
+ >;
715
+
716
+ /**
717
+ * The writable stream.
718
+ */
719
+ writable: WritableStream<T>;
720
+ }
721
+
722
+ /**
723
+ * Represents an instance used to read a zip file.
724
+ *
725
+ * @example
726
+ * Here is an example showing how to read the text data of the first entry from a zip file:
727
+ * ```
728
+ * // create a BlobReader to read with a ZipReader the zip from a Blob object
729
+ * const reader = new zip.ZipReader(new zip.BlobReader(blob));
730
+ *
731
+ * // get all entries from the zip
732
+ * const entries = await reader.getEntries();
733
+ * if (entries.length) {
734
+ *
735
+ * // get first entry content as text by using a TextWriter
736
+ * const text = await entries[0].getData(
737
+ * // writer
738
+ * new zip.TextWriter(),
739
+ * // options
740
+ * {
741
+ * onprogress: (index, max) => {
742
+ * // onprogress callback
743
+ * }
744
+ * }
745
+ * );
746
+ * // text contains the entry data as a String
747
+ * console.log(text);
748
+ * }
749
+ *
750
+ * // close the ZipReader
751
+ * await reader.close();
752
+ * ```
753
+ */
754
+ export class ZipReader<Type> {
755
+ /**
756
+ * Creates the instance
757
+ *
758
+ * @param reader The {@link Reader} instance used to read data.
759
+ * @param options The options.
760
+ */
761
+ constructor(
762
+ reader:
763
+ | Reader<Type>
764
+ | ReadableReader
765
+ | ReadableStream
766
+ | Reader<unknown>[]
767
+ | ReadableReader[]
768
+ | ReadableStream[],
769
+ options?: ZipReaderConstructorOptions
770
+ );
771
+ /**
772
+ * The global comment of the zip file.
773
+ */
774
+ comment: Uint8Array;
775
+ /**
776
+ * The data prepended before the zip file.
777
+ */
778
+ prependedData?: Uint8Array;
779
+ /**
780
+ * The data appended after the zip file.
781
+ */
782
+ appendedData?: Uint8Array;
783
+ /**
784
+ * Returns all the entries in the zip file
785
+ *
786
+ * @param options The options.
787
+ * @returns A promise resolving to an `array` of {@link Entry} instances.
788
+ */
789
+ getEntries(options?: ZipReaderGetEntriesOptions): Promise<Entry[]>;
790
+ /**
791
+ * Returns a generator used to iterate on all the entries in the zip file
792
+ *
793
+ * @param options The options.
794
+ * @returns An asynchronous generator of {@link Entry} instances.
795
+ */
796
+ getEntriesGenerator(
797
+ options?: ZipReaderGetEntriesOptions
798
+ ): AsyncGenerator<Entry, boolean>;
799
+ /**
800
+ * Closes the zip file
801
+ */
802
+ close(): Promise<void>;
803
+ }
804
+
805
+ /**
806
+ * Represents the options passed to the constructor of {@link ZipReader}, and `{@link ZipDirectory}#import*`.
807
+ */
808
+ export interface ZipReaderConstructorOptions
809
+ extends ZipReaderOptions,
810
+ GetEntriesOptions,
811
+ WorkerConfiguration {
812
+ /**
813
+ * `true` to extract the prepended data into {@link ZipReader#prependedData}.
814
+ *
815
+ * @defaultValue false
816
+ */
817
+ extractPrependedData?: boolean;
818
+ /**
819
+ * `true` to extract the appended data into {@link ZipReader#appendedData}.
820
+ *
821
+ * @defaultValue false
822
+ */
823
+ extractAppendedData?: boolean;
824
+ }
825
+
826
+ /**
827
+ * Represents the options passed to {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
828
+ */
829
+ export interface ZipReaderGetEntriesOptions
830
+ extends GetEntriesOptions,
831
+ EntryOnprogressOptions {}
832
+
833
+ /**
834
+ * Represents options passed to the constructor of {@link ZipReader}, {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
835
+ */
836
+ export interface GetEntriesOptions {
837
+ /**
838
+ * The encoding of the filename of the entry.
839
+ */
840
+ filenameEncoding?: string;
841
+ /**
842
+ * The encoding of the comment of the entry.
843
+ */
844
+ commentEncoding?: string;
845
+ /**
846
+ * The function called for decoding the filename and the comment of the entry.
847
+ *
848
+ * @param value The raw text value.
849
+ * @param encoding The encoding of the text.
850
+ * @returns The decoded text value or `undefined` if the raw text value should be decoded by zip.js.
851
+ */
852
+ decodeText?(value: Uint8Array, encoding: string): string | undefined;
853
+ /**
854
+ * `true` to throw an {@link ERR_AMBIGUOUS_ARCHIVE} error when the archive could be parsed differently by other
855
+ * tools. This detects data before or after the zip structure (e.g. a self-extracting archive stub or a
856
+ * concatenated archive), central directory records not accounted for by the end of central directory record, an
857
+ * end of central directory record disagreeing with its zip64 counterpart, and duplicate filenames. When reading
858
+ * the content of an entry, it also validates the local file header against the central directory record (see
859
+ * {@link ZipReaderOptions#checkAmbiguity}).
860
+ *
861
+ * @defaultValue false
862
+ */
863
+ checkAmbiguity?: boolean;
864
+ }
865
+
866
+ /**
867
+ * Represents options passed to the constructor of {@link ZipReader} and {@link FileEntry#getData}.
868
+ */
869
+ export interface ZipReaderOptions {
870
+ /**
871
+ * `true` to throw an {@link ERR_AMBIGUOUS_ARCHIVE} error when calling {@link FileEntry#getData} if the local
872
+ * file header of the entry disagrees with its central directory record in a way that could make other tools
873
+ * (e.g. streaming readers based on local file headers) interpret the entry differently. This detects mismatched
874
+ * filenames, general purpose bit flags (encryption, data descriptor and language encoding flags), compression
875
+ * methods, signatures and sizes. The extra fields are not compared because the zip specification allows them
876
+ * to differ.
877
+ *
878
+ * @defaultValue false
879
+ */
880
+ checkAmbiguity?: boolean;
881
+ /**
882
+ * `true` to check only if the password is valid.
883
+ *
884
+ * @defaultValue false
885
+ */
886
+ checkPasswordOnly?: boolean;
887
+ /**
888
+ * `true` to check the signature of the entry.
889
+ *
890
+ * @defaultValue false
891
+ */
892
+ checkSignature?: boolean;
893
+ /**
894
+ * `true` to throw an {@link ERR_OVERLAPPING_ENTRY} error when calling {@link FileEntry#getData} if the entry
895
+ * overlaps with another entry on which {@link FileEntry#getData} has already been called (with the option
896
+ * `checkOverlappingEntry` or `checkOverlappingEntryOnly` set to `true`).
897
+ *
898
+ * @defaultValue false
899
+ */
900
+ checkOverlappingEntry?: boolean;
901
+ /**
902
+ * `true` to throw an {@link ERR_OVERLAPPING_ENTRY} error when calling {@link FileEntry#getData} if the entry
903
+ * overlaps with another entry on which {@link FileEntry#getData} has already been called (with the option
904
+ * `checkOverlappingEntry` or `checkOverlappingEntryOnly` set to `true`) without trying to read the content of the
905
+ * entry.
906
+ *
907
+ * @defaultValue false
908
+ */
909
+ checkOverlappingEntryOnly?: boolean;
910
+ /**
911
+ * The password used to decrypt the content of the entry.
912
+ */
913
+ password?: string;
914
+ /**
915
+ * `true` to read the data as-is without decompressing it and without decrypting it.
916
+ */
917
+ passThrough?: boolean;
918
+ /**
919
+ * The password used to encrypt the content of the entry (raw).
920
+ */
921
+ rawPassword?: Uint8Array;
922
+ /**
923
+ * The `AbortSignal` instance used to cancel the decompression.
924
+ */
925
+ signal?: AbortSignal;
926
+ /**
927
+ * `true` to prevent closing of {@link Writer#writable} when calling {@link FileEntry#getData}.
928
+ *
929
+ * @defaultValue false
930
+ */
931
+ preventClose?: boolean;
932
+ }
933
+
934
+ /**
935
+ * Represents the metadata of an entry in a zip file (Core API).
936
+ */
937
+ export interface EntryMetaData {
938
+ /**
939
+ * The byte offset of the entry.
940
+ */
941
+ offset: number;
942
+ /**
943
+ * The filename of the entry.
944
+ */
945
+ filename: string;
946
+ /**
947
+ * The filename of the entry (raw).
948
+ */
949
+ rawFilename: Uint8Array;
950
+ /**
951
+ * `true` if the filename is encoded in UTF-8.
952
+ */
953
+ filenameUTF8: boolean;
954
+ /**
955
+ * `true` if the entry is an executable file
956
+ */
957
+ executable: boolean;
958
+ /**
959
+ * `true` if the content of the entry is encrypted.
960
+ */
961
+ encrypted: boolean;
962
+ /**
963
+ * `true` if the content of the entry is encrypted with the ZipCrypto algorithm.
964
+ */
965
+ zipCrypto: boolean;
966
+ /**
967
+ * The size of the compressed data in bytes.
968
+ */
969
+ compressedSize: number;
970
+ /**
971
+ * The size of the decompressed data in bytes.
972
+ */
973
+ uncompressedSize: number;
974
+ /**
975
+ * The last modification date.
976
+ */
977
+ lastModDate: Date;
978
+ /**
979
+ * The last access date.
980
+ */
981
+ lastAccessDate?: Date;
982
+ /**
983
+ * The creation date.
984
+ */
985
+ creationDate?: Date;
986
+ /**
987
+ * The last modification date (raw).
988
+ */
989
+ rawLastModDate: number | bigint;
990
+ /**
991
+ * The last access date (raw).
992
+ */
993
+ rawLastAccessDate?: number | bigint;
994
+ /**
995
+ * The creation date (raw).
996
+ */
997
+ rawCreationDate?: number | bigint;
998
+ /**
999
+ * The comment of the entry.
1000
+ */
1001
+ comment: string;
1002
+ /**
1003
+ * The comment of the entry (raw).
1004
+ */
1005
+ rawComment: Uint8Array;
1006
+ /**
1007
+ * `true` if the comment is encoded in UTF-8.
1008
+ */
1009
+ commentUTF8: boolean;
1010
+ /**
1011
+ * The signature (CRC32 checksum) of the content.
1012
+ */
1013
+ signature: number;
1014
+ /**
1015
+ * The extra field.
1016
+ */
1017
+ extraField?: Map<number, { type: number; data: Uint8Array }>;
1018
+ /**
1019
+ * The extra field (raw).
1020
+ */
1021
+ rawExtraField: Uint8Array;
1022
+ /**
1023
+ * `true` if the entry is using Zip64.
1024
+ */
1025
+ zip64: boolean;
1026
+ /**
1027
+ * The "Version" field.
1028
+ */
1029
+ version: number;
1030
+ /**
1031
+ * The "Version made by" field.
1032
+ */
1033
+ versionMadeBy: number;
1034
+ /**
1035
+ * `true` if `internalFileAttributes` and `externalFileAttributes` are compatible with MS-DOS format.
1036
+ */
1037
+ msDosCompatible: boolean;
1038
+ /**
1039
+ * Note (MS-DOS / Unix attributes):
1040
+ *
1041
+ * - The single source of truth for on-disk metadata is the 32-bit `externalFileAttributes` value stored in
1042
+ * the ZIP headers. The upper 16 bits are commonly used for Unix `st_mode` (type/permissions/special bits)
1043
+ * and the low 8 bits for MS-DOS attribute flags.
1044
+ *
1045
+ * - Writer vs Reader:
1046
+ * - The writer composes `externalFileAttributes` from the provided options (`externalFileAttributes`,
1047
+ * `unixMode`/special flags, `msdosAttributesRaw`/`msdosAttributes`).
1048
+ * - The reader decodes the stored `externalFileAttributes` and exposes convenience fields such as
1049
+ * `msdosAttributesRaw`, `msdosAttributes`, `unixExternalUpper`, and `unixMode`.
1050
+ *
1051
+ * - Practical rule: treat `externalFileAttributes` as authoritative; other fields are conveniences derived
1052
+ * from it. If you need a specific on-disk value, set `externalFileAttributes` explicitly.
1053
+ */
1054
+ /**
1055
+ * The MS-DOS attributes low byte (raw).
1056
+ * This is the low 8 bits of {@link EntryMetaData#externalFileAttributes} when present.
1057
+ */
1058
+ msdosAttributesRaw?: number;
1059
+ /**
1060
+ * The MS-DOS attribute flags exposed as booleans.
1061
+ */
1062
+ msdosAttributes?: {
1063
+ readOnly: boolean;
1064
+ hidden: boolean;
1065
+ system: boolean;
1066
+ directory: boolean;
1067
+ archive: boolean;
1068
+ };
1069
+ /**
1070
+ * Unix owner id when available.
1071
+ */
1072
+ uid?: number;
1073
+ /**
1074
+ * Unix group id when available.
1075
+ */
1076
+ gid?: number;
1077
+ /**
1078
+ * Unix mode (st_mode) when available.
1079
+ */
1080
+ unixMode?: number;
1081
+ /**
1082
+ * `true` if the setuid bit is set on the entry.
1083
+ */
1084
+ setuid?: boolean;
1085
+ /**
1086
+ * `true` if the setgid bit is set on the entry.
1087
+ */
1088
+ setgid?: boolean;
1089
+ /**
1090
+ * `true` if the sticky bit is set on the entry.
1091
+ */
1092
+ sticky?: boolean;
1093
+ /**
1094
+ * The internal file attributes (raw).
1095
+ */
1096
+ internalFileAttributes: number;
1097
+ /**
1098
+ * The 32-bit `externalFileAttributes` field is the authoritative on-disk metadata for each entry.
1099
+ * - Upper 16 bits: Unix mode/type (e.g., permissions, file type)
1100
+ * - Low 8 bits: MS-DOS file attributes (e.g., directory, read-only)
1101
+ *
1102
+ * When writing, all provided options are merged into this field. When reading, convenience fields are decoded from it.
1103
+ * For most use cases, prefer the high-level options and fields; only advanced users need to manipulate the raw value directly.
1104
+ */
1105
+ externalFileAttributes: number;
1106
+ /**
1107
+ * The upper 16-bit portion of {@link EntryMetaData#externalFileAttributes} when it represents Unix mode bits.
1108
+ */
1109
+ unixExternalUpper?: number;
1110
+ /**
1111
+ * The number of the disk where the entry data starts.
1112
+ */
1113
+ /**
1114
+ * The internal file attribute (raw).
1115
+ * @deprecated Use {@link EntryMetaData#internalFileAttributes} instead.
1116
+ */
1117
+ internalFileAttribute: number;
1118
+ /**
1119
+ * The external file attribute (raw).
1120
+ * @deprecated Use {@link EntryMetaData#externalFileAttributes} instead.
1121
+ */
1122
+ externalFileAttribute: number;
1123
+ /**
1124
+ * The number of the disk where the entry data starts.
1125
+ */
1126
+ diskNumberStart: number;
1127
+ /**
1128
+ * The compression method.
1129
+ */
1130
+ compressionMethod: number;
1131
+ }
1132
+ export interface DirectoryEntry extends EntryMetaData {
1133
+ /**
1134
+ * `true` if the entry is a directory.
1135
+ */
1136
+ directory: true;
1137
+ }
1138
+
1139
+ export interface FileEntry extends EntryMetaData {
1140
+ /**
1141
+ * `false` if the entry is a file.
1142
+ */
1143
+ directory: false;
1144
+ /**
1145
+ * Returns the content of the entry
1146
+ *
1147
+ * @param writer The {@link Writer} instance used to write the content of the entry.
1148
+ * @param options The options.
1149
+ * @returns A promise resolving to the type to data associated to `writer`.
1150
+ */
1151
+ getData<Type>(
1152
+ writer:
1153
+ | Writer<Type>
1154
+ | WritableWriter
1155
+ | WritableStream
1156
+ | AsyncGenerator<
1157
+ Writer<unknown> | WritableWriter | WritableStream,
1158
+ boolean
1159
+ >,
1160
+ options?: EntryGetDataCheckPasswordOptions
1161
+ ): Promise<Type>;
1162
+ /**
1163
+ * Retrieves the content of the entry as an `ArrayBuffer` instance
1164
+ *
1165
+ * @param options The options.
1166
+ * @returns A promise resolving to an `ArrayBuffer` instance.
1167
+ */
1168
+ arrayBuffer(options?: EntryGetDataOptions): Promise<ArrayBuffer>;
1169
+ }
1170
+
1171
+ /**
1172
+ * Represents an entry with its data and metadata in a zip file (Core API).
1173
+ * This is a union type of {@link DirectoryEntry} and {@link FileEntry}.
1174
+ *
1175
+ * Before using getData, you should check if the entry is a file.
1176
+ *
1177
+ * @example
1178
+ *
1179
+ * ```ts
1180
+ * for await (const entry of reader.getEntriesGenerator()) {
1181
+ * if (entry.directory) continue;
1182
+ *
1183
+ * // entry is a FileEntry
1184
+ * const plainTextData = await entry.getData(new TextWriter());
1185
+ *
1186
+ * // Do something with the plainTextData
1187
+ * }
1188
+ * ```
1189
+ */
1190
+ export type Entry = DirectoryEntry | FileEntry;
1191
+
1192
+ /**
1193
+ * Represents the options passed to {@link FileEntry#getData} and `{@link ZipFileEntry}.get*`.
1194
+ */
1195
+ export interface EntryGetDataOptions
1196
+ extends EntryDataOnprogressOptions,
1197
+ ZipReaderOptions,
1198
+ WorkerConfiguration {}
1199
+
1200
+ /**
1201
+ * Represents the options passed to {@link FileEntry#getData} and `{@link ZipFileEntry}.get*`.
1202
+ */
1203
+ export interface EntryGetDataCheckPasswordOptions extends EntryGetDataOptions {}
1204
+
1205
+ /**
1206
+ * Represents an instance used to create a zipped stream.
1207
+ *
1208
+ * @example
1209
+ * This example creates a zipped file called numbers.txt.zip containing the numbers 0 - 1000 each on their own line.
1210
+ * ```
1211
+ * const readable = ReadableStream.from((function* () {
1212
+ * for (let i = 0; i < 1000; ++i)
1213
+ * yield i + '\n'
1214
+ * })())
1215
+ *
1216
+ * readable
1217
+ * .pipeThrough(new ZipWriterStream().transform('numbers.txt'))
1218
+ * .pipeTo((await Deno.create('numbers.txt.zip')).writable)
1219
+ * ```
1220
+ *
1221
+ * @example
1222
+ * This example creates a zipped file called Archive.zip containing two files called numbers.txt and letters.txt
1223
+ * ```
1224
+ * const readable1 = ReadableStream.from((function* () {
1225
+ * for (let i = 0; i < 1000; ++i)
1226
+ * yield i + '\n'
1227
+ * })())
1228
+ * const readable2 = ReadableStream.from((function* () {
1229
+ * const letters = 'abcdefghijklmnopqrstuvwxyz'.split('')
1230
+ * while (letters.length)
1231
+ * yield letters.shift() + '\n'
1232
+ * })())
1233
+ *
1234
+ * const zipper = new ZipWriterStream()
1235
+ * zipper.readable.pipeTo((await Deno.create('Archive.zip')).writable)
1236
+ * readable1.pipeTo(zipper.writable('numbers.txt'))
1237
+ * readable2.pipeTo(zipper.writable('letters.txt'))
1238
+ * zipper.close()
1239
+ * ```
1240
+ */
1241
+ export class ZipWriterStream {
1242
+ /**
1243
+ * Creates the stream.
1244
+ *
1245
+ * @param options The options.
1246
+ */
1247
+ constructor(options?: ZipWriterConstructorOptions);
1248
+
1249
+ /**
1250
+ * The readable stream.
1251
+ */
1252
+ readable: ReadableStream<Uint8Array>;
1253
+
1254
+ /**
1255
+ * The ZipWriter property.
1256
+ */
1257
+ zipWriter: ZipWriter<unknown>;
1258
+
1259
+ /**
1260
+ * Returns an object containing a readable and writable property for the .pipeThrough method
1261
+ *
1262
+ * @param path The name of the stream when unzipped. Paths must use forward slashes ("/") as
1263
+ * separator (see {@link ZipWriter#add}).
1264
+ * @returns An object containing readable and writable properties
1265
+ */
1266
+ transform<T>(path: string): {
1267
+ readable: ReadableStream<T>;
1268
+ writable: WritableStream<T>;
1269
+ };
1270
+
1271
+ /**
1272
+ * Returns a WritableStream for the .pipeTo method
1273
+ *
1274
+ * @param path The directory path of where the stream should exist in the zipped stream. Paths
1275
+ * must use forward slashes ("/") as separator (see {@link ZipWriter#add}).
1276
+ * @returns A WritableStream.
1277
+ */
1278
+ writable<T>(path: string): WritableStream<T>;
1279
+
1280
+ /**
1281
+ * Writes the entries directory, writes the global comment, and returns the content of the zipped file.
1282
+ *
1283
+ * @param comment The global comment of the zip file.
1284
+ * @param options The options.
1285
+ * @returns The content of the zip file.
1286
+ */
1287
+ close(
1288
+ comment?: Uint8Array,
1289
+ options?: ZipWriterCloseOptions
1290
+ ): Promise<unknown>;
1291
+ }
1292
+
1293
+ /**
1294
+ * Represents an instance used to create a zip file.
1295
+ *
1296
+ * @example
1297
+ * Here is an example showing how to create a zip file containing a compressed text file:
1298
+ * ```
1299
+ * // use a BlobWriter to store with a ZipWriter the zip into a Blob object
1300
+ * const blobWriter = new zip.BlobWriter("application/zip");
1301
+ * const writer = new zip.ZipWriter(blobWriter);
1302
+ *
1303
+ * // use a TextReader to read the String to add
1304
+ * await writer.add("filename.txt", new zip.TextReader("test!"));
1305
+ *
1306
+ * // close the ZipReader
1307
+ * await writer.close();
1308
+ *
1309
+ * // get the zip file as a Blob
1310
+ * const blob = await blobWriter.getData();
1311
+ * ```
1312
+ */
1313
+ export class ZipWriter<Type> {
1314
+ /**
1315
+ * Creates the {@link ZipWriter} instance
1316
+ *
1317
+ * @param writer The {@link Writer} instance where the zip content will be written.
1318
+ * @param options The options.
1319
+ */
1320
+ constructor(
1321
+ writer:
1322
+ | Writer<Type>
1323
+ | WritableWriter
1324
+ | WritableStream
1325
+ | AsyncGenerator<
1326
+ Writer<unknown> | WritableWriter | WritableStream,
1327
+ boolean
1328
+ >,
1329
+ options?: ZipWriterConstructorOptions
1330
+ );
1331
+ /**
1332
+ * `true` if the zip contains at least one entry that has been partially written.
1333
+ */
1334
+ readonly hasCorruptedEntries?: boolean;
1335
+
1336
+ /**
1337
+ * Adds an existing zip file at the beginning of the current zip. This method
1338
+ * cannot be called after the first call to {@link ZipWriter#add}.
1339
+ *
1340
+ * @param reader The {@link Reader} instance used to read the content of the zip file.
1341
+ * @returns A promise resolving when the zip file has been added.
1342
+ */
1343
+ prependZip<ReaderType>(
1344
+ reader:
1345
+ | Reader<ReaderType>
1346
+ | ReadableReader
1347
+ | ReadableStream
1348
+ | Reader<unknown>[]
1349
+ | ReadableReader[]
1350
+ | ReadableStream[]
1351
+ ): Promise<void>;
1352
+
1353
+ /**
1354
+ * Adds an entry into the zip file
1355
+ *
1356
+ * @param filename The filename of the entry. Paths must use forward slashes ("/") as separator,
1357
+ * as required by section 4.4.17.1 of the zip specification. The value is stored as-is; in
1358
+ * particular, Windows path separators ("\\") are not converted and become part of the filename,
1359
+ * which is interpreted inconsistently by zip tools.
1360
+ * @param reader The {@link Reader} instance used to read the content of the entry.
1361
+ * @param options The options.
1362
+ * @returns A promise resolving to an {@link EntryMetaData} instance.
1363
+ */
1364
+ add<ReaderType>(
1365
+ filename: string,
1366
+ reader?:
1367
+ | Reader<ReaderType>
1368
+ | ReadableReader
1369
+ | ReadableStream
1370
+ | Reader<unknown>[]
1371
+ | ReadableReader[]
1372
+ | ReadableStream[],
1373
+ options?: ZipWriterAddDataOptions
1374
+ ): Promise<EntryMetaData>;
1375
+
1376
+ /**
1377
+ * Removes an entry from the central directory that will be written for the zip file. The entry
1378
+ * data itself cannot be removed because it has already been streamed to the output.
1379
+ *
1380
+ * @param entry The entry to remove. This can be an {@link Entry} instance or the filename of the entry.
1381
+ * @returns `true` if the entry has been removed, `false` otherwise.
1382
+ */
1383
+ remove(entry: Entry | string): boolean;
1384
+
1385
+ /**
1386
+ * Writes the entries directory, writes the global comment, and returns the content of the zip file
1387
+ *
1388
+ * @param comment The global comment of the zip file.
1389
+ * @param options The options.
1390
+ * @returns The content of the zip file.
1391
+ */
1392
+ close(comment?: Uint8Array, options?: ZipWriterCloseOptions): Promise<Type>;
1393
+ }
1394
+
1395
+ /**
1396
+ * Represents the options passed to {@link ZipWriter#add}.
1397
+ */
1398
+ export interface ZipWriterAddDataOptions
1399
+ extends ZipWriterConstructorOptions,
1400
+ EntryDataOnprogressOptions,
1401
+ WorkerConfiguration {
1402
+ /**
1403
+ * `true` if the entry is a directory.
1404
+ *
1405
+ * @defaultValue false
1406
+ */
1407
+ directory?: boolean;
1408
+ /**
1409
+ * `true` if the entry is an executable file.
1410
+ *
1411
+ * @defaultValue false
1412
+ */
1413
+ executable?: boolean;
1414
+ /**
1415
+ * The comment of the entry.
1416
+ */
1417
+ comment?: string;
1418
+ /**
1419
+ * The extra field of the entry.
1420
+ */
1421
+ extraField?: Map<number, Uint8Array>;
1422
+ /**
1423
+ * The uncompressed size of the entry. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
1424
+ */
1425
+ uncompressedSize?: number;
1426
+ /**
1427
+ * The signature (CRC32 checksum) of the content. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
1428
+ */
1429
+ signature?: number;
1430
+ }
1431
+
1432
+ /**
1433
+ * Represents the options passed to {@link ZipWriter#close}.
1434
+ */
1435
+ export interface ZipWriterCloseOptions extends EntryOnprogressOptions {
1436
+ /**
1437
+ * `true` to use Zip64 to write the entries directory.
1438
+ *
1439
+ * @defaultValue false
1440
+ */
1441
+ zip64?: boolean;
1442
+ /**
1443
+ * `true` to prevent closing of {@link WritableWriter#writable}.
1444
+ *
1445
+ * @defaultValue false
1446
+ */
1447
+ preventClose?: boolean;
1448
+ }
1449
+
1450
+ /**
1451
+ * Represents options passed to the constructor of {@link ZipWriter}, {@link ZipWriter#add} and `{@link ZipDirectoryEntry}#export*`.
1452
+ */
1453
+ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
1454
+ /**
1455
+ * `true` to use Zip64 to store the entry.
1456
+ *
1457
+ * `zip64` is automatically set to `true` when necessary (e.g. compressed data larger than 4GB or with unknown size).
1458
+ *
1459
+ * @defaultValue false
1460
+ */
1461
+ zip64?: boolean;
1462
+ /**
1463
+ * `true` to prevent closing of {@link WritableWriter#writable}.
1464
+ *
1465
+ * @defaultValue false
1466
+ */
1467
+ preventClose?: boolean;
1468
+ /**
1469
+ * The level of compression.
1470
+ *
1471
+ * The minimum value is 0 and means that no compression is applied. The maximum value is 9.
1472
+ *
1473
+ * @defaultValue 6
1474
+ */
1475
+ level?: number;
1476
+ /**
1477
+ * `true` to write entry data in a buffer before appending it to the zip file.
1478
+ *
1479
+ * `bufferedWrite` is automatically set to `true` when compressing more than one entry in parallel.
1480
+ *
1481
+ * @defaultValue false
1482
+ */
1483
+ bufferedWrite?: boolean;
1484
+ /**
1485
+ * An async factory function that returns a `TransformStream`-like object (`{ writable, readable }`) used as a temporary buffer when entries are written in parallel.
1486
+ *
1487
+ * When provided, this replaces the default in-memory `TransformStream` buffer, allowing data to be stored externally (e.g. filesystem, OPFS, network).
1488
+ * The `writable` side receives compressed entry data. The `readable` side is consumed when the entry is replayed into the final zip stream.
1489
+ */
1490
+ createTempStream?: () => Promise<{ writable: WritableStream; readable: ReadableStream }>;
1491
+ /**
1492
+ * `true` to keep the order of the entry physically in the zip file.
1493
+ *
1494
+ * When set to `true`, the use of web workers will be improved.
1495
+ *
1496
+ * @defaultValue true
1497
+ */
1498
+ keepOrder?: boolean;
1499
+ /**
1500
+ * The password used to encrypt the content of the entry.
1501
+ */
1502
+ password?: string;
1503
+ /**
1504
+ * The password used to encrypt the content of the entry (raw).
1505
+ */
1506
+ rawPassword?: Uint8Array;
1507
+ /**
1508
+ * The encryption strength (AES):
1509
+ * - 1: 128-bit encryption key
1510
+ * - 2: 192-bit encryption key
1511
+ * - 3: 256-bit encryption key
1512
+ *
1513
+ * @defaultValue 3
1514
+ */
1515
+ encryptionStrength?: 1 | 2 | 3;
1516
+ /**
1517
+ * The `AbortSignal` instance used to cancel the compression.
1518
+ */
1519
+ signal?: AbortSignal;
1520
+ /**
1521
+ * The last modification date.
1522
+ *
1523
+ * @defaultValue The current date.
1524
+ */
1525
+ lastModDate?: Date;
1526
+ /**
1527
+ * The last access date.
1528
+ *
1529
+ * This option is ignored if the {@link ZipWriterConstructorOptions#extendedTimestamp} option is set to `false`.
1530
+ *
1531
+ * @defaultValue The current date.
1532
+ */
1533
+ lastAccessDate?: Date;
1534
+ /**
1535
+ * The creation date.
1536
+ *
1537
+ * This option is ignored if the {@link ZipWriterConstructorOptions#extendedTimestamp} option is set to `false`.
1538
+ *
1539
+ * @defaultValue The current date.
1540
+ */
1541
+ creationDate?: Date;
1542
+ /**
1543
+ * `true` to store extended timestamp extra fields.
1544
+ *
1545
+ * When set to `false`, the maximum last modification date cannot exceed November 31, 2107 and the maximum accuracy is 2 seconds.
1546
+ *
1547
+ * @defaultValue true
1548
+ */
1549
+ extendedTimestamp?: boolean;
1550
+ /**
1551
+ * `true` to use the ZipCrypto algorithm to encrypt the content of the entry. Setting it to `true` will also
1552
+ * set the {@link ZipWriterConstructorOptions#dataDescriptor} to `true`.
1553
+ *
1554
+ * It is not recommended to set `zipCrypto` to `true` because the ZipCrypto encryption can be easily broken.
1555
+ *
1556
+ * @defaultValue false
1557
+ */
1558
+ zipCrypto?: boolean;
1559
+ /**
1560
+ * The "Version" field.
1561
+ */
1562
+ version?: number;
1563
+ /**
1564
+ * The "Version made by" field.
1565
+ *
1566
+ * @defaultValue 20
1567
+ */
1568
+ versionMadeBy?: number;
1569
+ /**
1570
+ * `true` to mark the file names as UTF-8 setting the general purpose bit 11 in the header (see Appendix D -
1571
+ * Language Encoding (EFS)), `false` to mark the names as compliant with the original IBM Code Page 437.
1572
+ *
1573
+ * Note that this does not ensure that the file names are in the correct encoding.
1574
+ *
1575
+ * @defaultValue true
1576
+ */
1577
+ useUnicodeFileNames?: boolean;
1578
+ /**
1579
+ * `true` to add a data descriptor.
1580
+ *
1581
+ * When set to `false`, the {@link ZipWriterConstructorOptions#bufferedWrite} option will automatically be
1582
+ * set to `true`. It will be automatically set to `false` when it is `undefined` and the
1583
+ * {@link ZipWriterConstructorOptions#bufferedWrite} option is set to `true`, or when the
1584
+ * {@link ZipWriterConstructorOptions#zipCrypto} option is set to `true`. Otherwise, the default value is `true`.
1585
+ */
1586
+ dataDescriptor?: boolean;
1587
+ /**
1588
+ * `true` to add the signature of the data descriptor.
1589
+ *
1590
+ * @defaultValue true
1591
+ */
1592
+ dataDescriptorSignature?: boolean;
1593
+ /**
1594
+ * `true` to write {@link EntryMetaData#externalFileAttributes} in MS-DOS format for folder entries.
1595
+ *
1596
+ * @defaultValue false
1597
+ */
1598
+ msDosCompatible?: boolean;
1599
+ /**
1600
+ * The external file attribute.
1601
+ *
1602
+ * @defaultValue 0
1603
+ */
1604
+ externalFileAttributes?: number;
1605
+ /**
1606
+ * The Unix owner id to write in the Unix extra field or as part of the external attributes.
1607
+ */
1608
+ uid?: number;
1609
+ /**
1610
+ * The Unix group id to write in the Unix extra field or as part of the external attributes.
1611
+ */
1612
+ gid?: number;
1613
+ /**
1614
+ * The Unix mode (st_mode bits) to use when writing external attributes.
1615
+ */
1616
+ unixMode?: number;
1617
+ /**
1618
+ * `true` to set the setuid bit when writing the Unix mode.
1619
+ */
1620
+ setuid?: boolean;
1621
+ /**
1622
+ * `true` to set the setgid bit when writing the Unix mode.
1623
+ */
1624
+ setgid?: boolean;
1625
+ /**
1626
+ * `true` to set the sticky bit when writing the Unix mode.
1627
+ */
1628
+ sticky?: boolean;
1629
+ /**
1630
+ * Which Unix extra field format to write when creating entries that include Unix metadata.
1631
+ * - "infozip": Info-ZIP New Unix extra field (0x7875), storing variable-length uid/gid up to 32 bits.
1632
+ * - "unix": Info-ZIP Unix extra field type 2 (0x7855), storing fixed 2-byte uid/gid (0..65535); a
1633
+ * larger uid or gid is rejected. The Unix mode is not part of this field; it is written to the
1634
+ * external file attributes.
1635
+ */
1636
+ unixExtraFieldType?: "infozip" | "unix";
1637
+ /**
1638
+ * The internal file attribute.
1639
+ *
1640
+ * @defaultValue 0
1641
+ */
1642
+ internalFileAttributes?: number;
1643
+ /**
1644
+ * When provided, the low 8-bit MS-DOS attributes to write into external file attributes.
1645
+ * Must be an integer between 0 and 255.
1646
+ */
1647
+ msdosAttributesRaw?: number;
1648
+ /**
1649
+ * When provided, MS-DOS attribute flags (boolean object) to write into external file attributes low byte.
1650
+ */
1651
+ msdosAttributes?: {
1652
+ readOnly?: boolean;
1653
+ hidden?: boolean;
1654
+ system?: boolean;
1655
+ directory?: boolean;
1656
+ archive?: boolean;
1657
+ };
1658
+ /**
1659
+ * `false` to never write disk numbers in zip64 data.
1660
+ *
1661
+ * @defaultValue true
1662
+ */
1663
+ supportZip64SplitFile?: boolean;
1664
+ /**
1665
+ * `true`to produce zip files compatible with the USDZ specification.
1666
+ *
1667
+ * @defaultValue false
1668
+ */
1669
+ usdz?: boolean;
1670
+ /**
1671
+ * `true` to write the data as-is without compressing it and without crypting it.
1672
+ */
1673
+ passThrough?: boolean;
1674
+ /**
1675
+ * `true` to write encrypted data when `passThrough` is set to `true`.
1676
+ */
1677
+ encrypted?: boolean;
1678
+ /**
1679
+ * The offset of the first entry in the zip file.
1680
+ */
1681
+ offset?: number;
1682
+ /**
1683
+ * The compression method (e.g. 8 for DEFLATE, 0 for STORE).
1684
+ */
1685
+ compressionMethod?: number;
1686
+ /**
1687
+ * The function called for encoding the filename and the comment of the entry.
1688
+ *
1689
+ * @param text The text to encode.
1690
+ * @returns The encoded text or `undefined` if the text should be encoded by zip.js.
1691
+ */
1692
+ encodeText?(text: string): Uint8Array | undefined;
1693
+ }
1694
+
1695
+ /**
1696
+ * Represents options passed to {@link FileEntry#getData}, {@link ZipWriter.add} and `{@link ZipDirectory}.export*`.
1697
+ */
1698
+ export interface EntryDataOnprogressOptions {
1699
+ /**
1700
+ * The function called when starting compression/decompression.
1701
+ *
1702
+ * @param total The total number of bytes.
1703
+ * @returns An empty promise or `undefined`.
1704
+ */
1705
+ onstart?(total: number): Promise<void> | void;
1706
+ /**
1707
+ * The function called during compression/decompression.
1708
+ *
1709
+ * @param progress The current progress in bytes.
1710
+ * @param total The total number of bytes.
1711
+ * @returns An empty promise or `undefined`.
1712
+ */
1713
+ onprogress?(progress: number, total: number): Promise<void> | void;
1714
+ /**
1715
+ * The function called when ending compression/decompression.
1716
+ *
1717
+ * @param computedSize The total number of bytes (computed).
1718
+ * @returns An empty promise or `undefined`.
1719
+ */
1720
+ onend?(computedSize: number): Promise<void> | void;
1721
+ }
1722
+
1723
+ /**
1724
+ * Represents options passed to {@link ZipReader#getEntries}, {@link ZipReader#getEntriesGenerator}, and {@link ZipWriter#close}.
1725
+ */
1726
+ export interface EntryOnprogressOptions {
1727
+ /**
1728
+ * The function called each time an entry is read/written.
1729
+ *
1730
+ * @param progress The entry index.
1731
+ * @param total The total number of entries.
1732
+ * @param entry The entry being read/written.
1733
+ * @returns An empty promise or `undefined`.
1734
+ */
1735
+ onprogress?(
1736
+ progress: number,
1737
+ total: number,
1738
+ entry: EntryMetaData
1739
+ ): Promise<void> | void;
1740
+ }
1741
+
1742
+ /**
1743
+ * Represents an entry in a zip file (Filesystem API).
1744
+ */
1745
+ declare class ZipEntry {
1746
+ /**
1747
+ * The relative filename of the entry.
1748
+ */
1749
+ name: string;
1750
+ /**
1751
+ * The underlying {@link EntryMetaData} instance.
1752
+ */
1753
+ data?: EntryMetaData;
1754
+ /**
1755
+ * The ID of the instance.
1756
+ */
1757
+ id: number;
1758
+ /**
1759
+ * The parent directory of the entry.
1760
+ */
1761
+ parent?: ZipEntry;
1762
+ /**
1763
+ * The uncompressed size of the content.
1764
+ */
1765
+ uncompressedSize: number;
1766
+ /**
1767
+ * The children of the entry.
1768
+ */
1769
+ children: ZipEntry[];
1770
+ /**
1771
+ * Clones the entry
1772
+ *
1773
+ * @param deepClone `true` to clone all the descendants.
1774
+ */
1775
+ clone(deepClone?: boolean): ZipEntry;
1776
+ /**
1777
+ * Returns the full filename of the entry
1778
+ */
1779
+ getFullname(): string;
1780
+ /**
1781
+ * Returns the filename of the entry relative to a parent directory
1782
+ */
1783
+ getRelativeName(ancestor: ZipDirectoryEntry): string;
1784
+ /**
1785
+ * Tests if a {@link ZipDirectoryEntry} instance is an ancestor of the entry
1786
+ *
1787
+ * @param ancestor The {@link ZipDirectoryEntry} instance.
1788
+ */
1789
+ isDescendantOf(ancestor: ZipDirectoryEntry): boolean;
1790
+ /**
1791
+ * Tests if the entry or any of its children is password protected
1792
+ */
1793
+ isPasswordProtected(): boolean;
1794
+ /**
1795
+ * Tests the password on the entry and all children if any, returns `true` if the entry is not password protected
1796
+ */
1797
+ checkPassword(
1798
+ password: string,
1799
+ options?: EntryGetDataOptions
1800
+ ): Promise<boolean>;
1801
+ /**
1802
+ * Set the name of the entry
1803
+ *
1804
+ * @param name The new name of the entry.
1805
+ */
1806
+ rename(name: string): void;
1807
+ }
1808
+
1809
+ /**
1810
+ * Represents a file entry in the zip (Filesystem API).
1811
+ */
1812
+ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
1813
+ /**
1814
+ * `void` for {@link ZipFileEntry} instances.
1815
+ */
1816
+ directory: void;
1817
+ /**
1818
+ * The {@link Reader} instance used to read the content of the entry.
1819
+ */
1820
+ reader:
1821
+ | Reader<ReaderType>
1822
+ | ReadableReader
1823
+ | ReadableStream
1824
+ | Reader<unknown>[]
1825
+ | ReadableReader[]
1826
+ | ReadableStream[];
1827
+ /**
1828
+ * The {@link Writer} instance used to write the content of the entry.
1829
+ */
1830
+ writer:
1831
+ | Writer<WriterType>
1832
+ | WritableWriter
1833
+ | WritableStream
1834
+ | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>;
1835
+ /**
1836
+ * Retrieves the text content of the entry as a `string`
1837
+ *
1838
+ * @param encoding The encoding of the text.
1839
+ * @param options The options.
1840
+ * @returns A promise resolving to a `string`.
1841
+ */
1842
+ getText(encoding?: string, options?: EntryGetDataOptions): Promise<string>;
1843
+ /**
1844
+ * Retrieves the content of the entry as a `Blob` instance
1845
+ *
1846
+ * @param mimeType The MIME type of the content.
1847
+ * @param options The options.
1848
+ * @returns A promise resolving to a `Blob` instance.
1849
+ */
1850
+ getBlob(mimeType?: string, options?: EntryGetDataOptions): Promise<Blob>;
1851
+ /**
1852
+ * Retrieves the content of the entry as as a Data URI `string` encoded in Base64
1853
+ *
1854
+ * @param mimeType The MIME type of the content.
1855
+ * @param options The options.
1856
+ * @returns A promise resolving to a Data URI `string` encoded in Base64.
1857
+ */
1858
+ getData64URI(
1859
+ mimeType?: string,
1860
+ options?: EntryGetDataOptions
1861
+ ): Promise<string>;
1862
+ /**
1863
+ * Retrieves the content of the entry as a `Uint8Array` instance
1864
+ *
1865
+ * @param options The options.
1866
+ * @returns A promise resolving to a `Uint8Array` instance.
1867
+ */
1868
+ getUint8Array(options?: EntryGetDataOptions): Promise<Uint8Array>;
1869
+ /**
1870
+ * Retrieves the content of the entry via a `WritableStream` instance
1871
+ *
1872
+ * @param writable The `WritableStream` instance.
1873
+ * @param options The options.
1874
+ * @returns A promise resolving to the `WritableStream` instance.
1875
+ */
1876
+ getWritable(
1877
+ writable?: WritableStream,
1878
+ options?: EntryGetDataOptions
1879
+ ): Promise<WritableStream>;
1880
+ /**
1881
+ * Retrieves the content of the entry via a {@link Writer} instance
1882
+ *
1883
+ * @param writer The {@link Writer} instance.
1884
+ * @param options The options.
1885
+ * @returns A promise resolving to data associated to the {@link Writer} instance.
1886
+ */
1887
+ getData<Type>(
1888
+ writer:
1889
+ | Writer<unknown>
1890
+ | WritableWriter
1891
+ | WritableStream
1892
+ | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>,
1893
+ options?: EntryGetDataOptions
1894
+ ): Promise<Type>;
1895
+ /**
1896
+ * Retrieves the content of the entry as an `ArrayBuffer` instance
1897
+ *
1898
+ * @param options The options.
1899
+ * @returns A promise resolving to an `ArrayBuffer` instance.
1900
+ */
1901
+ getArrayBuffer(options?: EntryGetDataOptions): Promise<ArrayBuffer>;
1902
+ /**
1903
+ * Replaces the content of the entry with a `Blob` instance
1904
+ *
1905
+ * @param blob The `Blob` instance.
1906
+ */
1907
+ replaceBlob(blob: Blob): void;
1908
+ /**
1909
+ * Replaces the content of the entry with a `string`
1910
+ *
1911
+ * @param text The `string`.
1912
+ */
1913
+ replaceText(text: string): void;
1914
+ /**
1915
+ * Replaces the content of the entry with a Data URI `string` encoded in Base64
1916
+ *
1917
+ * @param dataURI The Data URI `string` encoded in Base64.
1918
+ */
1919
+ replaceData64URI(dataURI: string): void;
1920
+ /**
1921
+ * Replaces the content of the entry with a `Uint8Array` instance
1922
+ *
1923
+ * @param array The `Uint8Array` instance.
1924
+ */
1925
+ replaceUint8Array(array: Uint8Array): void;
1926
+ /**
1927
+ * Replaces the content of the entry with a `ReadableStream` instance
1928
+ *
1929
+ * @param readable The `ReadableStream` instance.
1930
+ */
1931
+ replaceReadable(readable: ReadableStream): void;
1932
+ }
1933
+
1934
+ /**
1935
+ * Represents a directory entry in the zip (Filesystem API).
1936
+ */
1937
+ export class ZipDirectoryEntry extends ZipEntry {
1938
+ /**
1939
+ * `true` for {@link ZipDirectoryEntry} instances.
1940
+ */
1941
+ directory: true;
1942
+ /**
1943
+ * Gets a {@link ZipEntry} child instance from its relative filename
1944
+ *
1945
+ * @param name The relative filename.
1946
+ * @returns A {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance (use the {@link ZipFileEntry#directory} and {@link ZipDirectoryEntry#directory} properties to differentiate entries).
1947
+ */
1948
+ getChildByName(name: string): ZipEntry | undefined;
1949
+ /**
1950
+ * Adds a directory
1951
+ *
1952
+ * @param name The relative filename of the directory.
1953
+ * @param options The options.
1954
+ * @returns A {@link ZipDirectoryEntry} instance.
1955
+ */
1956
+ addDirectory(
1957
+ name: string,
1958
+ options?: ZipWriterAddDataOptions
1959
+ ): ZipDirectoryEntry;
1960
+ /**
1961
+ * Adds an entry with content provided as text
1962
+ *
1963
+ * @param name The relative filename of the entry.
1964
+ * @param text The text.
1965
+ * @param options The options.
1966
+ * @returns A {@link ZipFileEntry} instance.
1967
+ */
1968
+ addText(
1969
+ name: string,
1970
+ text: string,
1971
+ options?: ZipWriterAddDataOptions
1972
+ ): ZipFileEntry<string, string>;
1973
+ /**
1974
+ * Adds a entry entry with content provided as a `Blob` instance
1975
+ *
1976
+ * @param name The relative filename of the entry.
1977
+ * @param blob The `Blob` instance.
1978
+ * @param options The options.
1979
+ * @returns A {@link ZipFileEntry} instance.
1980
+ */
1981
+ addBlob(
1982
+ name: string,
1983
+ blob: Blob,
1984
+ options?: ZipWriterAddDataOptions
1985
+ ): ZipFileEntry<Blob, Blob>;
1986
+ /**
1987
+ * Adds a entry entry with content provided as a Data URI `string` encoded in Base64
1988
+ *
1989
+ * @param name The relative filename of the entry.
1990
+ * @param dataURI The Data URI `string` encoded in Base64.
1991
+ * @param options The options.
1992
+ * @returns A {@link ZipFileEntry} instance.
1993
+ */
1994
+ addData64URI(
1995
+ name: string,
1996
+ dataURI: string,
1997
+ options?: ZipWriterAddDataOptions
1998
+ ): ZipFileEntry<string, string>;
1999
+ /**
2000
+ * Adds an entry with content provided as a `Uint8Array` instance
2001
+ *
2002
+ * @param name The relative filename of the entry.
2003
+ * @param array The `Uint8Array` instance.
2004
+ * @param options The options.
2005
+ * @returns A {@link ZipFileEntry} instance.
2006
+ */
2007
+ addUint8Array(
2008
+ name: string,
2009
+ array: Uint8Array,
2010
+ options?: ZipWriterAddDataOptions
2011
+ ): ZipFileEntry<Uint8Array, Uint8Array>;
2012
+ /**
2013
+ * Adds an entry with content fetched from a URL
2014
+ *
2015
+ * @param name The relative filename of the entry.
2016
+ * @param url The URL.
2017
+ * @param options The options.
2018
+ * @returns A {@link ZipFileEntry} instance.
2019
+ */
2020
+ addHttpContent(
2021
+ name: string,
2022
+ url: string,
2023
+ options?: HttpOptions & ZipWriterAddDataOptions
2024
+ ): ZipFileEntry<string, void>;
2025
+ /**
2026
+ * Adds a entry entry with content provided via a `ReadableStream` instance
2027
+ *
2028
+ * @param name The relative filename of the entry.
2029
+ * @param readable The `ReadableStream` instance.
2030
+ * @param options The options.
2031
+ * @returns A {@link ZipFileEntry} instance.
2032
+ */
2033
+ addReadable(
2034
+ name: string,
2035
+ readable: ReadableStream,
2036
+ options?: ZipWriterAddDataOptions
2037
+ ): ZipFileEntry<ReadableStream, void>;
2038
+ /**
2039
+ * Adds an entry with content provided via a `File` instance
2040
+ *
2041
+ * @param file The `File` instance.
2042
+ * @param options The options.
2043
+ * @returns A promise resolving to a {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance.
2044
+ */
2045
+ addFile(file: File, options?: ZipWriterAddDataOptions): Promise<ZipEntry>;
2046
+ /**
2047
+ * Adds an entry with content provided via a `FileSystemEntry` instance
2048
+ *
2049
+ * @param fileSystemEntry The `FileSystemEntry` instance.
2050
+ * @param options The options.
2051
+ * @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
2052
+ */
2053
+ addFileSystemEntry(
2054
+ fileSystemEntry: FileSystemEntryLike,
2055
+ options?: ZipWriterAddDataOptions
2056
+ ): Promise<ZipEntry[]>;
2057
+ /**
2058
+ * Adds an entry with content provided via a `FileSystemHandle` instance
2059
+ *
2060
+ * @param fileSystemHandle The `fileSystemHandle` instance.
2061
+ * @param options The options.
2062
+ * @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
2063
+ */
2064
+ addFileSystemHandle(
2065
+ fileSystemHandle: FileSystemHandleLike,
2066
+ options?: ZipWriterAddDataOptions
2067
+ ): Promise<ZipEntry[]>;
2068
+ /**
2069
+ * Extracts a zip file provided as a `Blob` instance into the entry
2070
+ *
2071
+ * @param blob The `Blob` instance.
2072
+ * @param options The options.
2073
+ */
2074
+ importBlob(
2075
+ blob: Blob,
2076
+ options?: ZipReaderConstructorOptions
2077
+ ): Promise<[ZipEntry]>;
2078
+ /**
2079
+ * Extracts a zip file provided as a Data URI `string` encoded in Base64 into the entry
2080
+ *
2081
+ * @param dataURI The Data URI `string` encoded in Base64.
2082
+ * @param options The options.
2083
+ */
2084
+ importData64URI(
2085
+ dataURI: string,
2086
+ options?: ZipReaderConstructorOptions
2087
+ ): Promise<[ZipEntry]>;
2088
+ /**
2089
+ * Extracts a zip file provided as a `Uint8Array` instance into the entry
2090
+ *
2091
+ * @param array The `Uint8Array` instance.
2092
+ * @param options The options.
2093
+ */
2094
+ importUint8Array(
2095
+ array: Uint8Array,
2096
+ options?: ZipReaderConstructorOptions
2097
+ ): Promise<[ZipEntry]>;
2098
+ /**
2099
+ * Extracts a zip file fetched from a URL into the entry
2100
+ *
2101
+ * @param url The URL.
2102
+ * @param options The options.
2103
+ */
2104
+ importHttpContent(
2105
+ url: string,
2106
+ options?: ZipDirectoryEntryImportHttpOptions
2107
+ ): Promise<[ZipEntry]>;
2108
+ /**
2109
+ * Extracts a zip file provided via a `ReadableStream` instance into the entry
2110
+ *
2111
+ * @param readable The `ReadableStream` instance.
2112
+ * @param options The options.
2113
+ */
2114
+ importReadable(
2115
+ readable: ReadableStream,
2116
+ options?: ZipReaderConstructorOptions
2117
+ ): Promise<[ZipEntry]>;
2118
+ /**
2119
+ * Extracts a zip file provided via a custom {@link Reader} instance into the entry
2120
+ *
2121
+ * @param reader The {@link Reader} instance.
2122
+ * @param options The options.
2123
+ */
2124
+ importZip(
2125
+ reader:
2126
+ | Reader<unknown>
2127
+ | ReadableReader
2128
+ | ReadableStream
2129
+ | Reader<unknown>[]
2130
+ | ReadableReader[]
2131
+ | ReadableStream[],
2132
+ options?: ZipReaderConstructorOptions
2133
+ ): Promise<[ZipEntry]>;
2134
+ /**
2135
+ * Returns a `Blob` instance containing a zip file of the entry and its descendants
2136
+ *
2137
+ * @param options The options.
2138
+ * @returns A promise resolving to the `Blob` instance.
2139
+ */
2140
+ exportBlob(options?: ZipDirectoryEntryExportOptions): Promise<Blob>;
2141
+ /**
2142
+ * Returns a Data URI `string` encoded in Base64 containing a zip file of the entry and its descendants
2143
+ *
2144
+ * @param options The options.
2145
+ * @returns A promise resolving to the Data URI `string` encoded in Base64.
2146
+ */
2147
+ exportData64URI(options?: ZipDirectoryEntryExportOptions): Promise<string>;
2148
+ /**
2149
+ * Returns a `Uint8Array` instance containing a zip file of the entry and its descendants
2150
+ *
2151
+ * @param options The options.
2152
+ * @returns A promise resolving to the `Uint8Array` instance.
2153
+ */
2154
+ exportUint8Array(
2155
+ options?: ZipDirectoryEntryExportOptions
2156
+ ): Promise<Uint8Array>;
2157
+ /**
2158
+ * Creates a zip file via a `WritableStream` instance containing the entry and its descendants
2159
+ *
2160
+ * @param writable The `WritableStream` instance.
2161
+ * @param options The options.
2162
+ * @returns A promise resolving to the `Uint8Array` instance.
2163
+ */
2164
+ exportWritable(
2165
+ writable?: WritableStream,
2166
+ options?: ZipDirectoryEntryExportOptions
2167
+ ): Promise<WritableStream>;
2168
+ /**
2169
+ * Creates a zip file via a custom {@link Writer} instance containing the entry and its descendants
2170
+ *
2171
+ * @param writer The {@link Writer} instance.
2172
+ * @param options The options.
2173
+ * @returns A promise resolving to the data.
2174
+ */
2175
+ exportZip(
2176
+ writer:
2177
+ | Writer<unknown>
2178
+ | WritableWriter
2179
+ | WritableStream
2180
+ | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>,
2181
+ options?: ZipDirectoryEntryExportOptions
2182
+ ): Promise<unknown>;
2183
+ }
2184
+
2185
+ /**
2186
+ * Represents the options passed to {@link ZipDirectoryEntry#importHttpContent}.
2187
+ */
2188
+ export interface ZipDirectoryEntryImportHttpOptions
2189
+ extends ZipReaderConstructorOptions,
2190
+ HttpOptions {}
2191
+
2192
+ /**
2193
+ * Represents the options passed to `{@link ZipDirectoryEntry}#export*()`.
2194
+ */
2195
+ export interface ZipDirectoryEntryExportOptions
2196
+ extends ZipWriterConstructorOptions,
2197
+ EntryDataOnprogressOptions {
2198
+ /**
2199
+ * `true` to use filenames relative to the entry instead of full filenames.
2200
+ */
2201
+ relativePath?: boolean;
2202
+ /**
2203
+ * The MIME type of the exported data when relevant.
2204
+ */
2205
+ mimeType?: string;
2206
+ /**
2207
+ * The options passed to the Reader instances
2208
+ */
2209
+ readerOptions?: ZipReaderConstructorOptions;
2210
+ }
2211
+
2212
+ /**
2213
+ * Represents a Filesystem instance.
2214
+ *
2215
+ * @example
2216
+ * Here is an example showing how to create and read a zip file containing a compressed text file:
2217
+ * ```
2218
+ * const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.";
2219
+ * const FILENAME = "lorem.txt";
2220
+ * const BLOB = new Blob([TEXT_CONTENT], { type: zip.getMimeType(FILENAME) });
2221
+ * let zipFs = new zip.fs.FS();
2222
+ * zipFs.addBlob("lorem.txt", BLOB);
2223
+ * const zippedBlob = await zipFs.exportBlob();
2224
+ * zipFs = new zip.fs.FS();
2225
+ * await zipFs.importBlob(zippedBlob);
2226
+ * const firstEntry = zipFs.children[0];
2227
+ * const unzippedBlob = await firstEntry.getBlob(zip.getMimeType(firstEntry.name));
2228
+ * ```
2229
+ */
2230
+ export interface FS
2231
+ extends Pick<
2232
+ ZipDirectoryEntry,
2233
+ | "getChildByName"
2234
+ | "addDirectory"
2235
+ | "addText"
2236
+ | "addBlob"
2237
+ | "addData64URI"
2238
+ | "addUint8Array"
2239
+ | "addHttpContent"
2240
+ | "addReadable"
2241
+ | "addFile"
2242
+ | "addFileSystemEntry"
2243
+ | "addFileSystemHandle"
2244
+ | "importBlob"
2245
+ | "importData64URI"
2246
+ | "importUint8Array"
2247
+ | "importHttpContent"
2248
+ | "importReadable"
2249
+ | "importZip"
2250
+ | "exportBlob"
2251
+ | "exportData64URI"
2252
+ | "exportUint8Array"
2253
+ | "exportWritable"
2254
+ | "exportZip"
2255
+ | "isPasswordProtected"
2256
+ | "checkPassword"
2257
+ > {}
2258
+
2259
+ export class FS {
2260
+ /**
2261
+ * The root directory.
2262
+ */
2263
+ root: ZipDirectoryEntry;
2264
+ /**
2265
+ * The array of all the {@link ZipEntry} instances indexed by {@link ZipEntry#id}.
2266
+ */
2267
+ entries: (ZipEntry | null)[];
2268
+ /**
2269
+ * The children of the root directory.
2270
+ */
2271
+ readonly children: ZipEntry[];
2272
+ /**
2273
+ * Removes a {@link ZipEntry} instance and its children
2274
+ *
2275
+ * @param entry The {@link ZipEntry} instance to remove.
2276
+ */
2277
+ remove(entry: ZipEntry): void;
2278
+ /**
2279
+ * Moves a {@link ZipEntry} instance and its children into a {@link ZipDirectoryEntry} instance
2280
+ *
2281
+ * @param entry The {@link ZipEntry} instance to move.
2282
+ * @param destination The {@link ZipDirectoryEntry} instance.
2283
+ */
2284
+ move(entry: ZipEntry, destination: ZipDirectoryEntry): void;
2285
+ /**
2286
+ * Returns a {@link ZipEntry} instance from its full filename
2287
+ *
2288
+ * @param fullname The full filename.
2289
+ * @returns The {@link ZipEntry} instance.
2290
+ */
2291
+ find(fullname: string): ZipEntry | undefined;
2292
+ /**
2293
+ * Returns a {@link ZipEntry} instance from the value of {@link ZipEntry#id}
2294
+ *
2295
+ * @param id The id of the {@link ZipEntry} instance.
2296
+ * @returns The {@link ZipEntry} instance.
2297
+ */
2298
+ getById(id: number): ZipEntry | undefined;
2299
+ }
2300
+
2301
+ /**
2302
+ * The Filesystem API.
2303
+ */
2304
+ export const fs: {
2305
+ /**
2306
+ * The Filesystem constructor.
2307
+ *
2308
+ * @defaultValue {@link FS}
2309
+ */
2310
+ FS: typeof FS;
2311
+ /**
2312
+ * The {@link ZipDirectoryEntry} constructor.
2313
+ *
2314
+ * @defaultValue {@link ZipDirectoryEntry}
2315
+ */
2316
+ ZipDirectoryEntry: typeof ZipDirectoryEntry;
2317
+ /**
2318
+ * The {@link ZipFileEntry} constructor.
2319
+ *
2320
+ * @defaultValue {@link ZipFileEntry}
2321
+ */
2322
+ ZipFileEntry: typeof ZipFileEntry;
2323
+ };
2324
+
2325
+ // The error messages.
2326
+ /**
2327
+ * HTTP range error
2328
+ */
2329
+ export const ERR_HTTP_RANGE: string;
2330
+ /**
2331
+ * Zip format error
2332
+ */
2333
+ export const ERR_BAD_FORMAT: string;
2334
+ /**
2335
+ * End of Central Directory Record not found error
2336
+ */
2337
+ export const ERR_EOCDR_NOT_FOUND: string;
2338
+ /**
2339
+ * Zip64 End of Central Directory Locator not found error
2340
+ */
2341
+ export const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: string;
2342
+ /**
2343
+ * Central Directory not found error
2344
+ */
2345
+ export const ERR_CENTRAL_DIRECTORY_NOT_FOUND: string;
2346
+ /**
2347
+ * Local file header not found error
2348
+ */
2349
+ export const ERR_LOCAL_FILE_HEADER_NOT_FOUND: string;
2350
+ /**
2351
+ * Extra field Zip64 not found error
2352
+ */
2353
+ export const ERR_EXTRAFIELD_ZIP64_NOT_FOUND: string;
2354
+ /**
2355
+ * Encrypted entry error
2356
+ */
2357
+ export const ERR_ENCRYPTED: string;
2358
+ /**
2359
+ * Unsupported encryption error
2360
+ */
2361
+ export const ERR_UNSUPPORTED_ENCRYPTION: string;
2362
+ /**
2363
+ * Unsupported compression error
2364
+ */
2365
+ export const ERR_UNSUPPORTED_COMPRESSION: string;
2366
+ /**
2367
+ * Invalid signature error
2368
+ */
2369
+ export const ERR_INVALID_SIGNATURE: string;
2370
+ /**
2371
+ * Invalid uncompressed size error
2372
+ */
2373
+ export const ERR_INVALID_UNCOMPRESSED_SIZE: string;
2374
+ /**
2375
+ * Invalid compressed data error
2376
+ */
2377
+ export const ERR_INVALID_COMPRESSED_DATA: string;
2378
+ /**
2379
+ * Invalid password error
2380
+ */
2381
+ export const ERR_INVALID_PASSWORD: string;
2382
+ /**
2383
+ * Duplicate entry error
2384
+ */
2385
+ export const ERR_DUPLICATED_NAME: string;
2386
+ /**
2387
+ * Invalid comment error
2388
+ */
2389
+ export const ERR_INVALID_COMMENT: string;
2390
+ /**
2391
+ * Invalid entry name error
2392
+ */
2393
+ export const ERR_INVALID_ENTRY_NAME: string;
2394
+ /**
2395
+ * Invalid entry comment error
2396
+ */
2397
+ export const ERR_INVALID_ENTRY_COMMENT: string;
2398
+ /**
2399
+ * Invalid version error
2400
+ */
2401
+ export const ERR_INVALID_VERSION: string;
2402
+ /**
2403
+ * Invalid extra field type error
2404
+ */
2405
+ export const ERR_INVALID_EXTRAFIELD_TYPE: string;
2406
+ /**
2407
+ * Invalid extra field data error
2408
+ */
2409
+ export const ERR_INVALID_EXTRAFIELD_DATA: string;
2410
+ /**
2411
+ * Invalid encryption strength error
2412
+ */
2413
+ export const ERR_INVALID_ENCRYPTION_STRENGTH: string;
2414
+ /**
2415
+ * Invalid format error
2416
+ */
2417
+ export const ERR_UNSUPPORTED_FORMAT: string;
2418
+ /**
2419
+ * Split zip file error
2420
+ */
2421
+ export const ERR_SPLIT_ZIP_FILE: string;
2422
+ /**
2423
+ * Overlapping entry error
2424
+ */
2425
+ export const ERR_OVERLAPPING_ENTRY: string;
2426
+ /**
2427
+ * Ambiguous archive error
2428
+ *
2429
+ * @remarks The thrown error carries a `reason` property describing the ambiguity: `"appended data"`, `"prepended data"`, `"trailing central directory data"`, `"mismatched zip64 end of central directory record"`, or `"duplicate filename"`.
2430
+ */
2431
+ export const ERR_AMBIGUOUS_ARCHIVE: string;
2432
+ /**
2433
+ * Iteration completed too soon error
2434
+ */
2435
+ export const ERR_ITERATOR_COMPLETED_TOO_SOON: string;
2436
+ /**
2437
+ * Undefined uncompressed size error
2438
+ */
2439
+ export const ERR_UNDEFINED_UNCOMPRESSED_SIZE: string;
2440
+ /**
2441
+ * Undefined reader error
2442
+ */
2443
+ export const ERR_UNDEFINED_READER: string;
2444
+ /**
2445
+ * Writer not initialized error
2446
+ */
2447
+ export const ERR_WRITER_NOT_INITIALIZED: string;
2448
+ /**
2449
+ * Zip file not empty error
2450
+ */
2451
+ export const ERR_ZIP_NOT_EMPTY: string;