@zip.js/zip.js 2.8.30 → 2.8.32

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 (56) hide show
  1. package/BENCHMARKS.md +82 -1
  2. package/deno.json +5 -4
  3. package/dist/zip-core.js +403 -339
  4. package/dist/zip-core.min.js +1 -1
  5. package/dist/zip-fs-core.js +116 -278
  6. package/dist/zip-fs-core.min.js +1 -1
  7. package/dist/zip-fs-native.js +440 -378
  8. package/dist/zip-fs-native.min.js +1 -1
  9. package/dist/zip-fs.js +439 -377
  10. package/dist/zip-fs.min.js +1 -1
  11. package/dist/zip-legacy.js +408 -344
  12. package/dist/zip-legacy.min.js +1 -1
  13. package/dist/zip-module.wasm +0 -0
  14. package/dist/zip-native.js +411 -347
  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 +410 -346
  19. package/dist/zip.min.js +1 -1
  20. package/index-native.cjs +440 -378
  21. package/index-native.min.js +1 -1
  22. package/index.cjs +439 -377
  23. package/index.d.cts +2853 -0
  24. package/index.d.ts +278 -1
  25. package/index.min.js +1 -1
  26. package/lib/core/codec-worker.js +1 -11
  27. package/lib/core/configuration.js +21 -33
  28. package/lib/core/constants.js +3 -0
  29. package/lib/core/io.js +11 -19
  30. package/lib/core/streams/aes-crypto-stream.js +16 -20
  31. package/lib/core/streams/common-crypto.js +0 -2
  32. package/lib/core/streams/zip-crypto-stream.js +12 -16
  33. package/lib/core/streams/zip-entry-stream.js +2 -32
  34. package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
  35. package/lib/core/streams/zlib-wasm/zlib-streams-loader.js +1 -3
  36. package/lib/core/streams/zlib-wasm/zlib-streams.wasm +0 -0
  37. package/lib/core/util/base64.js +68 -0
  38. package/lib/core/util/blob-temp-stream.js +124 -0
  39. package/lib/core/util/decode-text.js +0 -1
  40. package/lib/core/util/default-mime-type.js +0 -3
  41. package/lib/core/util/inflate.js +194 -0
  42. package/lib/core/util/mime-type.js +26 -22
  43. package/lib/core/util/opfs-temp-stream.js +1 -37
  44. package/lib/core/util/sync-access-handle-temp-stream.js +147 -0
  45. package/lib/core/web-worker-inline-native.js +1 -1
  46. package/lib/core/web-worker-inline-template-native.js +5 -5
  47. package/lib/core/web-worker-inline-wasm.js +1 -1
  48. package/lib/core/zip-fs.js +6 -13
  49. package/lib/core/zip-reader.js +48 -127
  50. package/lib/core/zip-writer.js +27 -45
  51. package/lib/core/zlib-streams-inline-template.js +3 -2
  52. package/lib/core/zlib-streams-inline.js +1 -1
  53. package/lib/zip-core-base.js +10 -2
  54. package/package.json +9 -6
  55. package/reserved-property-names.js +50 -0
  56. package/lib/core/util/mini-lz.js +0 -198
package/index.d.cts ADDED
@@ -0,0 +1,2853 @@
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
+ * A `TransformStream`-like temporary buffer returned by a {@link ZipWriterConstructorOptions.createTempStream} factory.
332
+ */
333
+ export interface TempStream {
334
+ /**
335
+ * The writable side, receiving the compressed data of a buffered entry.
336
+ */
337
+ writable: WritableStream;
338
+ /**
339
+ * The readable side, replayed into the final zip stream once the entry is ready.
340
+ */
341
+ readable: ReadableStream;
342
+ /**
343
+ * Optional cleanup, called once the entry has been processed (on success, error, or abort) to release any backing resource.
344
+ */
345
+ dispose?: () => void | Promise<void>;
346
+ }
347
+
348
+ /**
349
+ * Options for {@link createOPFSTempStream}.
350
+ */
351
+ export interface OPFSTempStreamOptions {
352
+ /**
353
+ * Spill a buffered entry to a file once its buffered data exceeds this size, in bytes. Smaller entries stay in memory.
354
+ *
355
+ * @defaultValue 1048576
356
+ */
357
+ thresholdBytes?: number;
358
+ /**
359
+ * Name of the OPFS sub-directory holding the temporary files.
360
+ *
361
+ * @defaultValue ".zip.js-temp"
362
+ */
363
+ directoryName?: string;
364
+ /**
365
+ * Returns (or resolves to) the root `FileSystemDirectoryHandle`. Defaults to `navigator.storage.getDirectory()`.
366
+ *
367
+ * Provide it to run inside a worker with a pre-obtained handle, or to test against a mock.
368
+ */
369
+ getDirectory?: () => FileSystemDirectoryHandle | Promise<FileSystemDirectoryHandle>;
370
+ }
371
+
372
+ /**
373
+ * Builds a {@link ZipWriterConstructorOptions.createTempStream} factory that spills the data of buffered entries to the Origin Private File System (OPFS) instead of keeping it in memory.
374
+ *
375
+ * An entry stays in memory until it exceeds `thresholdBytes`, then spills to a temporary OPFS file that is streamed back and deleted afterwards, so peak memory stays bounded on large buffered entries.
376
+ *
377
+ * OPFS is a browser/worker feature; feature-detect `navigator.storage.getDirectory` (or pass `getDirectory`) before using it, and let the writer use its in-memory default elsewhere.
378
+ *
379
+ * @param options The options.
380
+ * @returns A factory suitable for {@link ZipWriterConstructorOptions.createTempStream}.
381
+ */
382
+ export function createOPFSTempStream(options?: OPFSTempStreamOptions): () => Promise<TempStream>;
383
+
384
+ /**
385
+ * Options for {@link createBlobTempStream}.
386
+ */
387
+ export interface BlobTempStreamOptions {
388
+ /**
389
+ * Spill a buffered entry to a `Blob` once its buffered data exceeds this size, in bytes. Smaller entries stay in memory.
390
+ *
391
+ * @defaultValue 1048576
392
+ */
393
+ thresholdBytes?: number;
394
+ }
395
+
396
+ /**
397
+ * Builds a {@link ZipWriterConstructorOptions.createTempStream} factory that spills the data of buffered entries into a `Blob` instead of keeping it in memory.
398
+ *
399
+ * An entry stays in memory until it exceeds `thresholdBytes`, then its data is transferred incrementally into a `Blob` built with `new Response(stream).blob()` and streamed back afterwards.
400
+ * In Chromium-based browsers, `Blob` data is managed outside the page and paged to disk under memory pressure, so peak memory stays bounded on large buffered entries without any storage permission or cleanup obligation.
401
+ * In Firefox, the `Blob` stays in memory but the helper still reduces peak memory usage moderately (roughly 30% on large entries) by releasing staged chunks earlier.
402
+ * In Safari, building the `Blob` retains several copies of the staged data (roughly 4 times the entry size at peak); do not use this helper there.
403
+ * In non-browser runtimes, the helper stays functional but roughly doubles peak memory usage (staged bytes plus their `Blob` copy).
404
+ * Outside Chromium-based browsers, prefer {@link createOPFSTempStream} or a file-backed implementation.
405
+ *
406
+ * @param options The options.
407
+ * @returns A factory suitable for {@link ZipWriterConstructorOptions.createTempStream}.
408
+ */
409
+ export function createBlobTempStream(options?: BlobTempStreamOptions): () => TempStream;
410
+
411
+ /**
412
+ * Builds a {@link ZipWriterConstructorOptions.createTempStream} factory that spills the data of buffered entries to the Origin Private File System (OPFS) via `FileSystemSyncAccessHandle` instead of keeping it in memory.
413
+ *
414
+ * This is the fastest disk-backed temporary storage on the web platform: it behaves like {@link createOPFSTempStream} (same options, same bounded-memory profile) but writes roughly 2.5 times faster in Chromium and Firefox and reads back several times faster in Firefox and Safari, making disk-backed staging nearly as fast as the in-memory default.
415
+ *
416
+ * `FileSystemSyncAccessHandle` is only exposed in dedicated workers, so this helper requires running the {@link ZipWriter} inside a worker; it throws when created in an unsupported context unless `getDirectory` is provided.
417
+ *
418
+ * @param options The options.
419
+ * @returns A factory suitable for {@link ZipWriterConstructorOptions.createTempStream}.
420
+ */
421
+ export function createSyncAccessHandleTempStream(options?: OPFSTempStreamOptions): () => TempStream;
422
+
423
+ /**
424
+ * Represents an instance used to read or write unknown type of data.
425
+ *
426
+ * 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}.
427
+ * 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.
428
+ */
429
+ export interface Initializable {
430
+ /**
431
+ * Initializes the instance asynchronously
432
+ */
433
+ init?(): Promise<void>;
434
+ /**
435
+ * `true` if the instance is initialized.
436
+ */
437
+ initialized?: boolean;
438
+ }
439
+
440
+ /**
441
+ * Represents an instance used to read data from a `ReadableStream` instance.
442
+ */
443
+ export interface ReadableReader {
444
+ /**
445
+ * The `ReadableStream` instance.
446
+ */
447
+ readable: ReadableStream;
448
+ }
449
+
450
+ /**
451
+ * Represents an instance used to read unknown type of data.
452
+ *
453
+ * @example
454
+ * Here is an example of custom {@link Reader} class used to read binary strings:
455
+ * ```
456
+ * class BinaryStringReader extends Reader {
457
+ *
458
+ * constructor(binaryString) {
459
+ * super();
460
+ * this.binaryString = binaryString;
461
+ * }
462
+ *
463
+ * init() {
464
+ * super.init();
465
+ * this.size = this.binaryString.length;
466
+ * }
467
+ *
468
+ * readUint8Array(offset, length) {
469
+ * const result = new Uint8Array(length);
470
+ * for (let indexCharacter = 0; indexCharacter < length; indexCharacter++) {
471
+ * result[indexCharacter] = this.binaryString.charCodeAt(indexCharacter + offset) & 0xFF;
472
+ * }
473
+ * return result;
474
+ * }
475
+ * }
476
+ * ```
477
+ */
478
+ export class Reader<Type> implements Initializable, ReadableReader {
479
+ /**
480
+ * Creates the {@link Reader} instance
481
+ *
482
+ * @param value The data to read.
483
+ */
484
+ constructor(value: Type);
485
+ /**
486
+ * The `ReadableStream` instance.
487
+ */
488
+ readable: ReadableStream;
489
+ /**
490
+ * The total size of the data in bytes.
491
+ */
492
+ size: number;
493
+ /**
494
+ * Initializes the instance asynchronously
495
+ */
496
+ init?(): Promise<void>;
497
+ /**
498
+ * Reads a chunk of data
499
+ *
500
+ * @param index The byte index of the data to read.
501
+ * @param length The length of the data to read in bytes.
502
+ * @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.
503
+ */
504
+ readUint8Array(index: number, length: number): Promise<Uint8Array>;
505
+ }
506
+
507
+ /**
508
+ * Represents a {@link Reader} instance used to read data provided as a `string`.
509
+ */
510
+ export class TextReader extends Reader<string> {}
511
+
512
+ /**
513
+ * Represents a {@link Reader} instance used to read data provided as a `Blob` instance.
514
+ */
515
+ export class BlobReader extends Reader<Blob> {}
516
+
517
+ /**
518
+ * Represents a {@link Reader} instance used to read data provided as a Data URI `string` encoded in Base64.
519
+ */
520
+ export class Data64URIReader extends Reader<string> {}
521
+
522
+ /**
523
+ * Represents a {@link Reader} instance used to read data provided as a `Uint8Array` instance.
524
+ */
525
+ export class Uint8ArrayReader extends Reader<Uint8Array> {}
526
+
527
+ /**
528
+ * Represents a {@link Reader} instance used to read data provided as an array of {@link ReadableReader} instances (e.g. split zip files).
529
+ */
530
+ export class SplitDataReader extends Reader<
531
+ Reader<unknown>[] | ReadableReader[] | ReadableStream[]
532
+ > {}
533
+
534
+ /**
535
+ * Represents a URL stored into a `string`.
536
+ */
537
+ type URLString = string;
538
+
539
+ /**
540
+ * Represents a {@link Reader} instance used to fetch data from a URL.
541
+ */
542
+ export class HttpReader extends Reader<URLString> {
543
+ /**
544
+ * Creates the {@link HttpReader} instance
545
+ *
546
+ * @param url The URL of the data.
547
+ * @param options The options.
548
+ */
549
+ constructor(url: URLString | URL, options?: HttpOptions);
550
+ }
551
+
552
+ /**
553
+ * Represents a {@link Reader} instance used to fetch data from servers returning `Accept-Ranges` headers.
554
+ */
555
+ export class HttpRangeReader extends HttpReader {
556
+ /**
557
+ * Creates the {@link HttpRangeReader} instance. It is particularly useful for reading ZIP files via HTTP.
558
+ * If you just want to add content retrieved via HTTP to a ZIP file, you can simply use
559
+ * `Response#body` {@link https://developer.mozilla.org/en-US/docs/Web/API/Response/body} instead.
560
+ *
561
+ * @param url The URL of the data.
562
+ * @param options The options.
563
+ */
564
+ constructor(url: URLString | URL, options?: HttpRangeOptions);
565
+ }
566
+
567
+ /**
568
+ * Represents the options passed to the constructor of {@link HttpReader}.
569
+ */
570
+ export interface HttpOptions extends HttpRangeOptions {
571
+ /**
572
+ * `true` to use `Range` headers when fetching data from servers returning `Accept-Ranges` headers.
573
+ *
574
+ * @defaultValue false
575
+ */
576
+ useRangeHeader?: boolean;
577
+ /**
578
+ * `true` to always use `Range` headers when fetching data.
579
+ *
580
+ * @defaultValue false
581
+ */
582
+ forceRangeRequests?: boolean;
583
+ /**
584
+ * `true` to prevent using `HEAD` HTTP request in order the get the size of the content.
585
+ * `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.
586
+ *
587
+ * @defaultValue false
588
+ */
589
+ preventHeadRequest?: boolean;
590
+ /**
591
+ * `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.
592
+ *
593
+ * @defaultValue false
594
+ */
595
+ combineSizeEocd?: boolean;
596
+ }
597
+
598
+ /**
599
+ * Represents options passed to the constructor of {@link HttpRangeReader} and {@link HttpReader}.
600
+ */
601
+ export interface HttpRangeOptions {
602
+ /**
603
+ * `true` to rely `XMLHttpRequest` instead of `fetch` to fetch data.
604
+ *
605
+ * @defaultValue false
606
+ */
607
+ useXHR?: boolean;
608
+ /**
609
+ * The function used to fetch the data. It takes precedence over {@link HttpRangeOptions#useXHR}
610
+ * when set. The returned object must expose the `status`, `statusText` and `headers` properties,
611
+ * and the `arrayBuffer()` method of the `Response` class.
612
+ *
613
+ * @defaultValue `fetch`
614
+ */
615
+ fetch?(input: string, init?: RequestInit): Promise<Response>;
616
+ /**
617
+ * The HTTP headers.
618
+ */
619
+ headers?: Iterable<[string, string]> | Map<string, string>;
620
+ }
621
+
622
+ /**
623
+ * Represents an instance used to write data into a `WritableStream` instance.
624
+ */
625
+ export interface WritableWriter {
626
+ /**
627
+ * The `WritableStream` instance.
628
+ */
629
+ writable: WritableStream;
630
+ /**
631
+ * 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.
632
+ */
633
+ maxSize?: number;
634
+ }
635
+
636
+ /**
637
+ * Represents an instance used to write unknown type of data.
638
+ *
639
+ * @example
640
+ * Here is an example of custom {@link Writer} class used to write binary strings:
641
+ * ```
642
+ * class BinaryStringWriter extends Writer {
643
+ *
644
+ * constructor() {
645
+ * super();
646
+ * this.binaryString = "";
647
+ * }
648
+ *
649
+ * writeUint8Array(array) {
650
+ * for (let indexCharacter = 0; indexCharacter < array.length; indexCharacter++) {
651
+ * this.binaryString += String.fromCharCode(array[indexCharacter]);
652
+ * }
653
+ * }
654
+ *
655
+ * getData() {
656
+ * return this.binaryString;
657
+ * }
658
+ * }
659
+ * ```
660
+ */
661
+ export class Writer<Type> implements Initializable, WritableWriter {
662
+ /**
663
+ * The `WritableStream` instance.
664
+ */
665
+ writable: WritableStream;
666
+ /**
667
+ * Initializes the instance asynchronously
668
+ *
669
+ * @param size the total size of the written data in bytes.
670
+ */
671
+ init?(size?: number): Promise<void>;
672
+ /**
673
+ * Appends a chunk of data
674
+ *
675
+ * @param array The chunk data to append.
676
+ *
677
+ * @virtual
678
+ */
679
+ writeUint8Array(array: Uint8Array): Promise<void>;
680
+ /**
681
+ * Retrieves all the written data
682
+ *
683
+ * @returns A promise resolving to the written data.
684
+ */
685
+ getData(): Promise<Type>;
686
+ }
687
+
688
+ /**
689
+ * Represents a {@link Writer} instance used to retrieve the written data as a `string`.
690
+ */
691
+ export class TextWriter extends Writer<string> {
692
+ /**
693
+ * Creates the {@link TextWriter} instance
694
+ *
695
+ * @param encoding The encoding of the text.
696
+ */
697
+ constructor(encoding?: string);
698
+ }
699
+
700
+ /**
701
+ * Represents a {@link WritableWriter} instance used to retrieve the written data as a `Blob` instance.
702
+ */
703
+ export class BlobWriter implements Initializable, WritableWriter {
704
+ /**
705
+ * The `WritableStream` instance.
706
+ */
707
+ writable: WritableStream;
708
+ /**
709
+ * Initializes the instance asynchronously
710
+ */
711
+ init(): Promise<void>;
712
+ /**
713
+ * Creates the {@link BlobWriter} instance
714
+ *
715
+ * @param mimeString The MIME type of the content.
716
+ */
717
+ constructor(mimeString?: string);
718
+ /**
719
+ * Retrieves all the written data
720
+ *
721
+ * @returns A promise resolving to the written data.
722
+ */
723
+ getData(): Promise<Blob>;
724
+ }
725
+
726
+ /**
727
+ * Represents a {@link Writer} instance used to retrieve the written data as a Data URI `string` encoded in Base64.
728
+ */
729
+ export class Data64URIWriter extends Writer<string> {
730
+ /**
731
+ * Creates the {@link Data64URIWriter} instance
732
+ *
733
+ * @param mimeString The MIME type of the content.
734
+ */
735
+ constructor(mimeString?: string);
736
+ }
737
+
738
+ /**
739
+ * Represents a {@link Writer} instance used to retrieve the written data from a generator of {@link WritableWriter} instances (i.e. split zip files).
740
+ */
741
+ export class SplitDataWriter implements Initializable, WritableWriter {
742
+ /**
743
+ * The `WritableStream` instance.
744
+ */
745
+ writable: WritableStream;
746
+ /**
747
+ * The number of the disk being written.
748
+ */
749
+ diskNumber: number;
750
+ /**
751
+ * The byte offset of the disk being written.
752
+ */
753
+ diskOffset: number;
754
+ /**
755
+ * The maximum size of each disk in bytes.
756
+ */
757
+ maxSize: number;
758
+ /**
759
+ * The number of bytes still available on the disk being written.
760
+ */
761
+ availableSize: number;
762
+ /**
763
+ * Initializes the instance asynchronously
764
+ */
765
+ init(): Promise<void>;
766
+ /**
767
+ * Creates the {@link SplitDataWriter} instance
768
+ *
769
+ * @param writerGenerator A generator of Writer instances.
770
+ * @param maxSize The maximum size of the data written into {@link Writer} instances (default: 4GB).
771
+ */
772
+ constructor(
773
+ writerGenerator: AsyncGenerator<
774
+ Writer<unknown> | WritableWriter | WritableStream,
775
+ boolean
776
+ >,
777
+ maxSize?: number
778
+ );
779
+ }
780
+
781
+ /**
782
+ * Represents a {@link Writer} instance used to retrieve the written data as a `Uint8Array` instance.
783
+ */
784
+ export class Uint8ArrayWriter extends Writer<Uint8Array<ArrayBuffer>> {
785
+ /**
786
+ * Creates the {@link Uint8ArrayWriter} instance
787
+ *
788
+ * @param defaultBufferSize The initial size of the internal buffer (default: 256KB).
789
+ */
790
+ constructor(defaultBufferSize?: number);
791
+ }
792
+
793
+ /**
794
+ * Represents an instance used to create an unzipped stream.
795
+ *
796
+ * @example
797
+ * This example will take a zip file, decompress it and then save its files and directories to disk.
798
+ * ```
799
+ * import {resolve} from "https://deno.land/std/path/mod.ts";
800
+ * import {ensureDir, ensureFile} from "https://deno.land/std/fs/mod.ts";
801
+ *
802
+ * for await (const entry of (await fetch(urlToZippedFile)).body.pipeThrough(new ZipReaderStream())) {
803
+ * const fullPath = resolve(destination, entry.filename);
804
+ * if (entry.directory) {
805
+ * await ensureDir(fullPath);
806
+ * continue;
807
+ * }
808
+ *
809
+ * await ensureFile(fullPath);
810
+ * await entry.readable?.pipeTo((await Deno.create(fullPath)).writable);
811
+ * }
812
+ * ```
813
+ */
814
+ export class ZipReaderStream<T> {
815
+ /**
816
+ * Creates the stream.
817
+ *
818
+ * @param options The options.
819
+ */
820
+ constructor(options?: ZipReaderConstructorOptions);
821
+
822
+ /**
823
+ * The readable stream.
824
+ */
825
+ readable: ReadableStream<
826
+ Omit<Entry, "getData"> & { readable?: ReadableStream<Uint8Array> }
827
+ >;
828
+
829
+ /**
830
+ * The writable stream.
831
+ */
832
+ writable: WritableStream<T>;
833
+ }
834
+
835
+ /**
836
+ * Represents an instance used to read a zip file.
837
+ *
838
+ * @example
839
+ * Here is an example showing how to read the text data of the first entry from a zip file:
840
+ * ```
841
+ * // create a BlobReader to read with a ZipReader the zip from a Blob object
842
+ * const reader = new zip.ZipReader(new zip.BlobReader(blob));
843
+ *
844
+ * // get all entries from the zip
845
+ * const entries = await reader.getEntries();
846
+ * if (entries.length) {
847
+ *
848
+ * // get first entry content as text by using a TextWriter
849
+ * const text = await entries[0].getData(
850
+ * // writer
851
+ * new zip.TextWriter(),
852
+ * // options
853
+ * {
854
+ * onprogress: (index, max) => {
855
+ * // onprogress callback
856
+ * }
857
+ * }
858
+ * );
859
+ * // text contains the entry data as a String
860
+ * console.log(text);
861
+ * }
862
+ *
863
+ * // close the ZipReader
864
+ * await reader.close();
865
+ * ```
866
+ */
867
+ export class ZipReader<Type> {
868
+ /**
869
+ * Creates the instance
870
+ *
871
+ * @param reader The {@link Reader} instance used to read data.
872
+ * @param options The options.
873
+ */
874
+ constructor(
875
+ reader:
876
+ | Reader<Type>
877
+ | ReadableReader
878
+ | ReadableStream
879
+ | Reader<unknown>[]
880
+ | ReadableReader[]
881
+ | ReadableStream[],
882
+ options?: ZipReaderConstructorOptions
883
+ );
884
+ /**
885
+ * The global comment of the zip file.
886
+ */
887
+ comment: Uint8Array;
888
+ /**
889
+ * The data prepended before the zip file.
890
+ */
891
+ prependedData?: Uint8Array;
892
+ /**
893
+ * The data appended after the zip file.
894
+ */
895
+ appendedData?: Uint8Array;
896
+ /**
897
+ * Returns all the entries in the zip file
898
+ *
899
+ * @param options The options.
900
+ * @returns A promise resolving to an `array` of {@link Entry} instances.
901
+ */
902
+ getEntries(options?: ZipReaderGetEntriesOptions): Promise<Entry[]>;
903
+ /**
904
+ * Returns a generator used to iterate on all the entries in the zip file
905
+ *
906
+ * @param options The options.
907
+ * @returns An asynchronous generator of {@link Entry} instances.
908
+ */
909
+ getEntriesGenerator(
910
+ options?: ZipReaderGetEntriesOptions
911
+ ): AsyncGenerator<Entry, boolean>;
912
+ /**
913
+ * Closes the zip file
914
+ */
915
+ close(): Promise<void>;
916
+ }
917
+
918
+ /**
919
+ * Represents the options passed to the constructor of {@link ZipReader}, and `{@link ZipDirectory}#import*`.
920
+ */
921
+ export interface ZipReaderConstructorOptions
922
+ extends ZipReaderOptions,
923
+ GetEntriesOptions,
924
+ WorkerConfiguration {
925
+ /**
926
+ * `true` to extract the prepended data into {@link ZipReader#prependedData}.
927
+ *
928
+ * @defaultValue false
929
+ */
930
+ extractPrependedData?: boolean;
931
+ /**
932
+ * `true` to extract the appended data into {@link ZipReader#appendedData}.
933
+ *
934
+ * @defaultValue false
935
+ */
936
+ extractAppendedData?: boolean;
937
+ }
938
+
939
+ /**
940
+ * Represents the options passed to {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
941
+ */
942
+ export interface ZipReaderGetEntriesOptions
943
+ extends GetEntriesOptions,
944
+ EntryOnprogressOptions {}
945
+
946
+ /**
947
+ * Represents options passed to the constructor of {@link ZipReader}, {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
948
+ */
949
+ export interface GetEntriesOptions {
950
+ /**
951
+ * The encoding of the filename of the entry.
952
+ */
953
+ filenameEncoding?: string;
954
+ /**
955
+ * The encoding of the comment of the entry.
956
+ */
957
+ commentEncoding?: string;
958
+ /**
959
+ * The function called for decoding the filename and the comment of the entry.
960
+ *
961
+ * @param value The raw text value.
962
+ * @param encoding The encoding of the text.
963
+ * @returns The decoded text value or `undefined` if the raw text value should be decoded by zip.js.
964
+ */
965
+ decodeText?(value: Uint8Array, encoding: string): string | undefined;
966
+ /**
967
+ * `true` to throw an {@link ERR_AMBIGUOUS_ARCHIVE} error when the archive could be parsed differently by other
968
+ * tools. This detects data before or after the zip structure (e.g. a self-extracting archive stub or a
969
+ * concatenated archive), central directory records not accounted for by the end of central directory record, an
970
+ * end of central directory record disagreeing with its zip64 counterpart, and duplicate filenames. When reading
971
+ * the content of an entry, it also validates the local file header against the central directory record (see
972
+ * {@link ZipReaderOptions#checkAmbiguity}).
973
+ *
974
+ * @defaultValue false
975
+ */
976
+ checkAmbiguity?: boolean;
977
+ /**
978
+ * How tolerant the reader should be when the archive can be parsed in more than one way.
979
+ *
980
+ * - `"strict"`: reject anything another tool could interpret differently. The end of central directory
981
+ * record must sit exactly at the end of the file, no data may precede the zip structure, and the local file
982
+ * headers must agree with the central directory records. Equivalent to {@link GetEntriesOptions#checkAmbiguity}
983
+ * set to `true`.
984
+ * - `"balanced"`: select the last end of central directory record whose comment reaches the end of the file
985
+ * and that points to a central directory, ignore stale records left by in-place updates as well as records
986
+ * forged inside a comment, and tolerate a self-extracting stub or up to
987
+ * {@link GetEntriesOptions#maxAppendedDataSize} bytes of appended data. Throw an {@link ERR_AMBIGUOUS_ARCHIVE}
988
+ * error only when two or more records reach the end of the file and each points to a central directory, which
989
+ * cannot be disambiguated. A record that reaches the end of the file but points to no central directory (an
990
+ * empty archive) is only selected when no record points to one.
991
+ * - `"tolerant"`: never reject a parseable archive, except when {@link GetEntriesOptions#maxAppendedDataSize}
992
+ * is set explicitly and exceeded; recover by selecting the last end of central directory record that reaches
993
+ * the end of the file and points to a central directory (or, failing that, the last one that reaches the end
994
+ * of the file).
995
+ *
996
+ * @defaultValue "balanced"
997
+ */
998
+ strictness?: "strict" | "balanced" | "tolerant";
999
+ /**
1000
+ * The maximum number of bytes tolerated after the zip structure before the archive is rejected. Defaults to
1001
+ * `0` when {@link GetEntriesOptions#strictness} is `"strict"`, `65535` when it is `"balanced"`, and `Infinity`
1002
+ * when it is `"tolerant"`.
1003
+ *
1004
+ * An explicit value takes precedence over the strictness default at every level, so it can loosen `"strict"`
1005
+ * or reintroduce a rejection under `"tolerant"`. It also bounds how far back the end of central directory
1006
+ * record is searched for, so a value smaller than the amount of data actually appended surfaces an
1007
+ * {@link ERR_EOCDR_NOT_FOUND} error when the record lies beyond the searched region and an
1008
+ * {@link ERR_AMBIGUOUS_ARCHIVE} error otherwise.
1009
+ */
1010
+ maxAppendedDataSize?: number;
1011
+ }
1012
+
1013
+ /**
1014
+ * Represents options passed to the constructor of {@link ZipReader} and {@link FileEntry#getData}.
1015
+ */
1016
+ export interface ZipReaderOptions {
1017
+ /**
1018
+ * How tolerant the reader should be when the local file header of an entry disagrees with its central
1019
+ * directory record. `"strict"` throws an {@link ERR_AMBIGUOUS_ARCHIVE} error (equivalent to
1020
+ * {@link ZipReaderOptions#checkAmbiguity} set to `true`); `"balanced"` and `"tolerant"` trust the central
1021
+ * directory record.
1022
+ *
1023
+ * @defaultValue "balanced"
1024
+ */
1025
+ strictness?: "strict" | "balanced" | "tolerant";
1026
+ /**
1027
+ * `true` to throw an {@link ERR_AMBIGUOUS_ARCHIVE} error when calling {@link FileEntry#getData} if the local
1028
+ * file header of the entry disagrees with its central directory record in a way that could make other tools
1029
+ * (e.g. streaming readers based on local file headers) interpret the entry differently. This detects mismatched
1030
+ * filenames, general purpose bit flags (encryption, data descriptor and language encoding flags), compression
1031
+ * methods, signatures and sizes. The extra fields are not compared because the zip specification allows them
1032
+ * to differ.
1033
+ *
1034
+ * @defaultValue false
1035
+ */
1036
+ checkAmbiguity?: boolean;
1037
+ /**
1038
+ * `true` to check only if the password is valid.
1039
+ *
1040
+ * @defaultValue false
1041
+ */
1042
+ checkPasswordOnly?: boolean;
1043
+ /**
1044
+ * `true` to check the signature of the entry.
1045
+ *
1046
+ * @defaultValue false
1047
+ */
1048
+ checkSignature?: boolean;
1049
+ /**
1050
+ * `true` to throw an {@link ERR_OVERLAPPING_ENTRY} error when calling {@link FileEntry#getData} if the entry
1051
+ * overlaps with another entry on which {@link FileEntry#getData} has already been called (with the option
1052
+ * `checkOverlappingEntry` or `checkOverlappingEntryOnly` set to `true`).
1053
+ *
1054
+ * @defaultValue false
1055
+ */
1056
+ checkOverlappingEntry?: boolean;
1057
+ /**
1058
+ * `true` to throw an {@link ERR_OVERLAPPING_ENTRY} error when calling {@link FileEntry#getData} if the entry
1059
+ * overlaps with another entry on which {@link FileEntry#getData} has already been called (with the option
1060
+ * `checkOverlappingEntry` or `checkOverlappingEntryOnly` set to `true`) without trying to read the content of the
1061
+ * entry.
1062
+ *
1063
+ * @defaultValue false
1064
+ */
1065
+ checkOverlappingEntryOnly?: boolean;
1066
+ /**
1067
+ * The password used to decrypt the content of the entry.
1068
+ */
1069
+ password?: string;
1070
+ /**
1071
+ * `true` to read the data as-is without decompressing it and without decrypting it.
1072
+ */
1073
+ passThrough?: boolean;
1074
+ /**
1075
+ * The password used to encrypt the content of the entry (raw).
1076
+ */
1077
+ rawPassword?: Uint8Array;
1078
+ /**
1079
+ * The `AbortSignal` instance used to cancel the decompression.
1080
+ */
1081
+ signal?: AbortSignal;
1082
+ /**
1083
+ * `true` to prevent closing of {@link Writer#writable} when calling {@link FileEntry#getData}.
1084
+ *
1085
+ * @defaultValue false
1086
+ */
1087
+ preventClose?: boolean;
1088
+ }
1089
+
1090
+ /**
1091
+ * Represents the parsed general purpose bit flag of an entry.
1092
+ */
1093
+ export interface EntryBitFlag {
1094
+ /**
1095
+ * The compression option bits.
1096
+ */
1097
+ level: number;
1098
+ /**
1099
+ * `true` if the entry data is followed by a data descriptor.
1100
+ */
1101
+ dataDescriptor: boolean;
1102
+ /**
1103
+ * `true` if the filename and the comment are encoded in UTF-8 (EFS).
1104
+ */
1105
+ languageEncodingFlag: boolean;
1106
+ }
1107
+ /**
1108
+ * Represents an extra field record of an entry.
1109
+ */
1110
+ export interface EntryExtraField {
1111
+ /**
1112
+ * The type (header id) of the extra field.
1113
+ */
1114
+ type: number;
1115
+ /**
1116
+ * The data of the extra field.
1117
+ */
1118
+ data: Uint8Array;
1119
+ }
1120
+ /**
1121
+ * Represents the AES extra field record of an entry.
1122
+ */
1123
+ export interface EntryExtraFieldAES extends EntryExtraField {
1124
+ /**
1125
+ * The encryption strength (1, 2 or 3).
1126
+ */
1127
+ strength?: number;
1128
+ /**
1129
+ * The compression method stored in the AES extra field.
1130
+ */
1131
+ originalCompressionMethod?: number;
1132
+ }
1133
+ /**
1134
+ * Represents a Unicode path or comment extra field record of an entry.
1135
+ */
1136
+ export interface EntryExtraFieldUnicode extends EntryExtraField {
1137
+ /**
1138
+ * `true` if the extra field is consistent with the entry metadata.
1139
+ */
1140
+ valid?: boolean;
1141
+ }
1142
+ /**
1143
+ * Represents the local file header fields of an entry, read when getting the entry data.
1144
+ */
1145
+ export interface LocalDirectory {
1146
+ /**
1147
+ * The "Version" field.
1148
+ */
1149
+ version: number;
1150
+ /**
1151
+ * `true` if the entry is encrypted.
1152
+ */
1153
+ encrypted: boolean;
1154
+ /**
1155
+ * The general purpose bit flag (raw).
1156
+ */
1157
+ rawBitFlag: number;
1158
+ /**
1159
+ * The general purpose bit flag.
1160
+ */
1161
+ bitFlag: EntryBitFlag;
1162
+ /**
1163
+ * The last modification date (raw).
1164
+ */
1165
+ rawLastModDate: number;
1166
+ /**
1167
+ * The last modification date.
1168
+ */
1169
+ lastModDate: Date;
1170
+ /**
1171
+ * The length of the filename in bytes.
1172
+ */
1173
+ filenameLength: number;
1174
+ /**
1175
+ * The length of the extra field in bytes.
1176
+ */
1177
+ extraFieldLength: number;
1178
+ /**
1179
+ * The extra field (raw).
1180
+ */
1181
+ rawExtraField: Uint8Array;
1182
+ /**
1183
+ * The extra field.
1184
+ */
1185
+ extraField?: Map<number, EntryExtraField>;
1186
+ /**
1187
+ * The signature (CRC32 checksum) of the content.
1188
+ */
1189
+ signature?: number;
1190
+ /**
1191
+ * The compressed size of the content.
1192
+ */
1193
+ compressedSize?: number;
1194
+ /**
1195
+ * The uncompressed size of the content.
1196
+ */
1197
+ uncompressedSize?: number;
1198
+ /**
1199
+ * The compression method.
1200
+ */
1201
+ compressionMethod?: number;
1202
+ /**
1203
+ * The Zip64 extra field.
1204
+ */
1205
+ extraFieldZip64?: EntryExtraField;
1206
+ /**
1207
+ * The AES extra field.
1208
+ */
1209
+ extraFieldAES?: EntryExtraFieldAES;
1210
+ /**
1211
+ * The NTFS extra field.
1212
+ */
1213
+ extraFieldNTFS?: EntryExtraField;
1214
+ /**
1215
+ * The Unix extra field.
1216
+ */
1217
+ extraFieldUnix?: EntryExtraField;
1218
+ /**
1219
+ * The Info-ZIP Unix extra field.
1220
+ */
1221
+ extraFieldInfoZip?: EntryExtraField;
1222
+ /**
1223
+ * The extended timestamp extra field.
1224
+ */
1225
+ extraFieldExtendedTimestamp?: EntryExtraField;
1226
+ /**
1227
+ * The Unicode path extra field.
1228
+ */
1229
+ extraFieldUnicodePath?: EntryExtraFieldUnicode;
1230
+ /**
1231
+ * The Unicode comment extra field.
1232
+ */
1233
+ extraFieldUnicodeComment?: EntryExtraFieldUnicode;
1234
+ /**
1235
+ * The USDZ extra field.
1236
+ */
1237
+ extraFieldUSDZ?: EntryExtraField;
1238
+ }
1239
+ /**
1240
+ * Represents an error raised while processing an entry, decorated with entry context.
1241
+ */
1242
+ export interface EntryError extends Error {
1243
+ /**
1244
+ * `true` if the zip file is corrupted because the entry data could not be written entirely.
1245
+ */
1246
+ corruptedEntry?: boolean;
1247
+ /**
1248
+ * The id of the related {@link ZipEntry} (filesystem API).
1249
+ */
1250
+ entryId?: number;
1251
+ }
1252
+ /**
1253
+ * Represents the metadata of an entry in a zip file (Core API).
1254
+ */
1255
+ export interface EntryMetaData {
1256
+ /**
1257
+ * The byte offset of the entry.
1258
+ */
1259
+ offset: number;
1260
+ /**
1261
+ * The filename of the entry.
1262
+ */
1263
+ filename: string;
1264
+ /**
1265
+ * The filename of the entry (raw).
1266
+ */
1267
+ rawFilename: Uint8Array;
1268
+ /**
1269
+ * `true` if the filename is encoded in UTF-8.
1270
+ */
1271
+ filenameUTF8: boolean;
1272
+ /**
1273
+ * `true` if the entry is an executable file
1274
+ */
1275
+ executable: boolean;
1276
+ /**
1277
+ * `true` if the content of the entry is encrypted.
1278
+ */
1279
+ encrypted: boolean;
1280
+ /**
1281
+ * `true` if the content of the entry is encrypted with the ZipCrypto algorithm.
1282
+ */
1283
+ zipCrypto: boolean;
1284
+ /**
1285
+ * The size of the compressed data in bytes.
1286
+ */
1287
+ compressedSize: number;
1288
+ /**
1289
+ * The size of the decompressed data in bytes.
1290
+ */
1291
+ uncompressedSize: number;
1292
+ /**
1293
+ * The last modification date.
1294
+ */
1295
+ lastModDate: Date;
1296
+ /**
1297
+ * The last access date.
1298
+ */
1299
+ lastAccessDate?: Date;
1300
+ /**
1301
+ * The creation date.
1302
+ */
1303
+ creationDate?: Date;
1304
+ /**
1305
+ * The last modification date (raw).
1306
+ */
1307
+ rawLastModDate: number | bigint;
1308
+ /**
1309
+ * The last access date (raw).
1310
+ */
1311
+ rawLastAccessDate?: number | bigint;
1312
+ /**
1313
+ * The creation date (raw).
1314
+ */
1315
+ rawCreationDate?: number | bigint;
1316
+ /**
1317
+ * The comment of the entry.
1318
+ */
1319
+ comment: string;
1320
+ /**
1321
+ * The comment of the entry (raw).
1322
+ */
1323
+ rawComment: Uint8Array;
1324
+ /**
1325
+ * `true` if the comment is encoded in UTF-8.
1326
+ */
1327
+ commentUTF8: boolean;
1328
+ /**
1329
+ * The signature (CRC32 checksum) of the content.
1330
+ */
1331
+ signature: number;
1332
+ /**
1333
+ * The extra field.
1334
+ */
1335
+ extraField?: Map<number, { type: number; data: Uint8Array }>;
1336
+ /**
1337
+ * The extra field (raw).
1338
+ */
1339
+ rawExtraField: Uint8Array;
1340
+ /**
1341
+ * `true` if the entry is using Zip64.
1342
+ */
1343
+ zip64: boolean;
1344
+ /**
1345
+ * The "Version" field.
1346
+ */
1347
+ version: number;
1348
+ /**
1349
+ * The "Version made by" field.
1350
+ */
1351
+ versionMadeBy: number;
1352
+ /**
1353
+ * `true` if `internalFileAttributes` and `externalFileAttributes` are compatible with MS-DOS format.
1354
+ */
1355
+ msDosCompatible: boolean;
1356
+ /**
1357
+ * Note (MS-DOS / Unix attributes):
1358
+ *
1359
+ * - The single source of truth for on-disk metadata is the 32-bit `externalFileAttributes` value stored in
1360
+ * the ZIP headers. The upper 16 bits are commonly used for Unix `st_mode` (type/permissions/special bits)
1361
+ * and the low 8 bits for MS-DOS attribute flags.
1362
+ *
1363
+ * - Writer vs Reader:
1364
+ * - The writer composes `externalFileAttributes` from the provided options (`externalFileAttributes`,
1365
+ * `unixMode`/special flags, `msdosAttributesRaw`/`msdosAttributes`).
1366
+ * - The reader decodes the stored `externalFileAttributes` and exposes convenience fields such as
1367
+ * `msdosAttributesRaw`, `msdosAttributes`, `unixExternalUpper`, and `unixMode`.
1368
+ *
1369
+ * - Practical rule: treat `externalFileAttributes` as authoritative; other fields are conveniences derived
1370
+ * from it. If you need a specific on-disk value, set `externalFileAttributes` explicitly.
1371
+ */
1372
+ /**
1373
+ * The MS-DOS attributes low byte (raw).
1374
+ * This is the low 8 bits of {@link EntryMetaData#externalFileAttributes} when present.
1375
+ */
1376
+ msdosAttributesRaw?: number;
1377
+ /**
1378
+ * The MS-DOS attribute flags exposed as booleans.
1379
+ */
1380
+ msdosAttributes?: {
1381
+ readOnly: boolean;
1382
+ hidden: boolean;
1383
+ system: boolean;
1384
+ directory: boolean;
1385
+ archive: boolean;
1386
+ };
1387
+ /**
1388
+ * Unix owner id when available.
1389
+ */
1390
+ uid?: number;
1391
+ /**
1392
+ * Unix group id when available.
1393
+ */
1394
+ gid?: number;
1395
+ /**
1396
+ * Unix mode (st_mode) when available.
1397
+ */
1398
+ unixMode?: number;
1399
+ /**
1400
+ * `true` if the setuid bit is set on the entry.
1401
+ */
1402
+ setuid?: boolean;
1403
+ /**
1404
+ * `true` if the setgid bit is set on the entry.
1405
+ */
1406
+ setgid?: boolean;
1407
+ /**
1408
+ * `true` if the sticky bit is set on the entry.
1409
+ */
1410
+ sticky?: boolean;
1411
+ /**
1412
+ * The internal file attributes (raw).
1413
+ */
1414
+ internalFileAttributes: number;
1415
+ /**
1416
+ * The 32-bit `externalFileAttributes` field is the authoritative on-disk metadata for each entry.
1417
+ * - Upper 16 bits: Unix mode/type (e.g., permissions, file type)
1418
+ * - Low 8 bits: MS-DOS file attributes (e.g., directory, read-only)
1419
+ *
1420
+ * When writing, all provided options are merged into this field. When reading, convenience fields are decoded from it.
1421
+ * For most use cases, prefer the high-level options and fields; only advanced users need to manipulate the raw value directly.
1422
+ */
1423
+ externalFileAttributes: number;
1424
+ /**
1425
+ * The upper 16-bit portion of {@link EntryMetaData#externalFileAttributes} when it represents Unix mode bits.
1426
+ */
1427
+ unixExternalUpper?: number;
1428
+ /**
1429
+ * The number of the disk where the entry data starts.
1430
+ */
1431
+ /**
1432
+ * The internal file attribute (raw).
1433
+ * @deprecated Use {@link EntryMetaData#internalFileAttributes} instead.
1434
+ */
1435
+ internalFileAttribute: number;
1436
+ /**
1437
+ * The external file attribute (raw).
1438
+ * @deprecated Use {@link EntryMetaData#externalFileAttributes} instead.
1439
+ */
1440
+ externalFileAttribute: number;
1441
+ /**
1442
+ * The number of the disk where the entry data starts.
1443
+ */
1444
+ diskNumberStart: number;
1445
+ /**
1446
+ * The compression method.
1447
+ */
1448
+ compressionMethod: number;
1449
+ /**
1450
+ * The general purpose bit flag (raw).
1451
+ */
1452
+ rawBitFlag?: number;
1453
+ /**
1454
+ * The general purpose bit flag.
1455
+ */
1456
+ bitFlag?: EntryBitFlag;
1457
+ /**
1458
+ * The length of the filename in bytes.
1459
+ */
1460
+ filenameLength?: number;
1461
+ /**
1462
+ * The length of the extra field in bytes.
1463
+ */
1464
+ extraFieldLength?: number;
1465
+ /**
1466
+ * The Zip64 extra field.
1467
+ */
1468
+ extraFieldZip64?: EntryExtraField;
1469
+ /**
1470
+ * The AES extra field.
1471
+ */
1472
+ extraFieldAES?: EntryExtraFieldAES;
1473
+ /**
1474
+ * The NTFS extra field.
1475
+ */
1476
+ extraFieldNTFS?: EntryExtraField;
1477
+ /**
1478
+ * The Unix extra field.
1479
+ */
1480
+ extraFieldUnix?: EntryExtraField;
1481
+ /**
1482
+ * The Info-ZIP Unix extra field.
1483
+ */
1484
+ extraFieldInfoZip?: EntryExtraField;
1485
+ /**
1486
+ * The extended timestamp extra field.
1487
+ */
1488
+ extraFieldExtendedTimestamp?: EntryExtraField;
1489
+ /**
1490
+ * The Unicode path extra field.
1491
+ */
1492
+ extraFieldUnicodePath?: EntryExtraFieldUnicode;
1493
+ /**
1494
+ * The Unicode comment extra field.
1495
+ */
1496
+ extraFieldUnicodeComment?: EntryExtraFieldUnicode;
1497
+ /**
1498
+ * The USDZ extra field.
1499
+ */
1500
+ extraFieldUSDZ?: EntryExtraField;
1501
+ /**
1502
+ * The local file header fields, set when the entry data has been read.
1503
+ */
1504
+ localDirectory?: LocalDirectory;
1505
+ }
1506
+ export interface DirectoryEntry extends EntryMetaData {
1507
+ /**
1508
+ * `true` if the entry is a directory.
1509
+ */
1510
+ directory: true;
1511
+ }
1512
+
1513
+ export interface FileEntry extends EntryMetaData {
1514
+ /**
1515
+ * `false` if the entry is a file.
1516
+ */
1517
+ directory: false;
1518
+ /**
1519
+ * Returns the content of the entry
1520
+ *
1521
+ * @param writer The {@link Writer} instance used to write the content of the entry.
1522
+ * @param options The options.
1523
+ * @returns A promise resolving to the type to data associated to `writer`.
1524
+ */
1525
+ getData<Type>(
1526
+ writer:
1527
+ | Writer<Type>
1528
+ | WritableWriter
1529
+ | WritableStream
1530
+ | AsyncGenerator<
1531
+ Writer<unknown> | WritableWriter | WritableStream,
1532
+ boolean
1533
+ >,
1534
+ options?: EntryGetDataCheckPasswordOptions
1535
+ ): Promise<Type>;
1536
+ /**
1537
+ * Retrieves the content of the entry as an `ArrayBuffer` instance
1538
+ *
1539
+ * @param options The options.
1540
+ * @returns A promise resolving to an `ArrayBuffer` instance.
1541
+ */
1542
+ arrayBuffer(options?: EntryGetDataOptions): Promise<ArrayBuffer>;
1543
+ }
1544
+
1545
+ /**
1546
+ * Represents an entry with its data and metadata in a zip file (Core API).
1547
+ * This is a union type of {@link DirectoryEntry} and {@link FileEntry}.
1548
+ *
1549
+ * Before using getData, you should check if the entry is a file.
1550
+ *
1551
+ * @example
1552
+ *
1553
+ * ```ts
1554
+ * for await (const entry of reader.getEntriesGenerator()) {
1555
+ * if (entry.directory) continue;
1556
+ *
1557
+ * // entry is a FileEntry
1558
+ * const plainTextData = await entry.getData(new TextWriter());
1559
+ *
1560
+ * // Do something with the plainTextData
1561
+ * }
1562
+ * ```
1563
+ */
1564
+ export type Entry = DirectoryEntry | FileEntry;
1565
+
1566
+ /**
1567
+ * Represents the options passed to {@link FileEntry#getData} and `{@link ZipFileEntry}.get*`.
1568
+ */
1569
+ export interface EntryGetDataOptions
1570
+ extends EntryDataOnprogressOptions,
1571
+ ZipReaderOptions,
1572
+ WorkerConfiguration {}
1573
+
1574
+ /**
1575
+ * Represents the options passed to {@link FileEntry#getData} and `{@link ZipFileEntry}.get*`.
1576
+ */
1577
+ export interface EntryGetDataCheckPasswordOptions extends EntryGetDataOptions {}
1578
+
1579
+ /**
1580
+ * Represents an instance used to create a zipped stream.
1581
+ *
1582
+ * @example
1583
+ * This example creates a zipped file called numbers.txt.zip containing the numbers 0 - 1000 each on their own line.
1584
+ * ```
1585
+ * const readable = ReadableStream.from((function* () {
1586
+ * for (let i = 0; i < 1000; ++i)
1587
+ * yield i + '\n'
1588
+ * })())
1589
+ *
1590
+ * readable
1591
+ * .pipeThrough(new ZipWriterStream().transform('numbers.txt'))
1592
+ * .pipeTo((await Deno.create('numbers.txt.zip')).writable)
1593
+ * ```
1594
+ *
1595
+ * @example
1596
+ * This example creates a zipped file called Archive.zip containing two files called numbers.txt and letters.txt
1597
+ * ```
1598
+ * const readable1 = ReadableStream.from((function* () {
1599
+ * for (let i = 0; i < 1000; ++i)
1600
+ * yield i + '\n'
1601
+ * })())
1602
+ * const readable2 = ReadableStream.from((function* () {
1603
+ * const letters = 'abcdefghijklmnopqrstuvwxyz'.split('')
1604
+ * while (letters.length)
1605
+ * yield letters.shift() + '\n'
1606
+ * })())
1607
+ *
1608
+ * const zipper = new ZipWriterStream()
1609
+ * zipper.readable.pipeTo((await Deno.create('Archive.zip')).writable)
1610
+ * readable1.pipeTo(zipper.writable('numbers.txt'))
1611
+ * readable2.pipeTo(zipper.writable('letters.txt'))
1612
+ * zipper.close()
1613
+ * ```
1614
+ */
1615
+ export class ZipWriterStream {
1616
+ /**
1617
+ * Creates the stream.
1618
+ *
1619
+ * @param options The options.
1620
+ */
1621
+ constructor(options?: ZipWriterConstructorOptions);
1622
+
1623
+ /**
1624
+ * The readable stream.
1625
+ */
1626
+ readable: ReadableStream<Uint8Array>;
1627
+
1628
+ /**
1629
+ * The ZipWriter property.
1630
+ */
1631
+ zipWriter: ZipWriter<unknown>;
1632
+
1633
+ /**
1634
+ * Returns an object containing a readable and writable property for the .pipeThrough method
1635
+ *
1636
+ * @param path The name of the stream when unzipped. Paths must use forward slashes ("/") as
1637
+ * separator (see {@link ZipWriter#add}).
1638
+ * @returns An object containing readable and writable properties
1639
+ */
1640
+ transform<T>(path: string): {
1641
+ readable: ReadableStream<T>;
1642
+ writable: WritableStream<T>;
1643
+ };
1644
+
1645
+ /**
1646
+ * Returns a WritableStream for the .pipeTo method
1647
+ *
1648
+ * @param path The directory path of where the stream should exist in the zipped stream. Paths
1649
+ * must use forward slashes ("/") as separator (see {@link ZipWriter#add}).
1650
+ * @returns A WritableStream.
1651
+ */
1652
+ writable<T>(path: string): WritableStream<T>;
1653
+
1654
+ /**
1655
+ * Writes the entries directory, writes the global comment, and returns the content of the zipped file.
1656
+ *
1657
+ * @param comment The global comment of the zip file.
1658
+ * @param options The options.
1659
+ * @returns The content of the zip file.
1660
+ */
1661
+ close(
1662
+ comment?: Uint8Array,
1663
+ options?: ZipWriterCloseOptions
1664
+ ): Promise<unknown>;
1665
+ }
1666
+
1667
+ /**
1668
+ * Represents an instance used to create a zip file.
1669
+ *
1670
+ * @example
1671
+ * Here is an example showing how to create a zip file containing a compressed text file:
1672
+ * ```
1673
+ * // use a BlobWriter to store with a ZipWriter the zip into a Blob object
1674
+ * const blobWriter = new zip.BlobWriter("application/zip");
1675
+ * const writer = new zip.ZipWriter(blobWriter);
1676
+ *
1677
+ * // use a TextReader to read the String to add
1678
+ * await writer.add("filename.txt", new zip.TextReader("test!"));
1679
+ *
1680
+ * // close the ZipReader
1681
+ * await writer.close();
1682
+ *
1683
+ * // get the zip file as a Blob
1684
+ * const blob = await blobWriter.getData();
1685
+ * ```
1686
+ */
1687
+ export class ZipWriter<Type> {
1688
+ /**
1689
+ * Creates the {@link ZipWriter} instance
1690
+ *
1691
+ * @param writer The {@link Writer} instance where the zip content will be written.
1692
+ * @param options The options.
1693
+ */
1694
+ constructor(
1695
+ writer:
1696
+ | Writer<Type>
1697
+ | WritableWriter
1698
+ | WritableStream
1699
+ | AsyncGenerator<
1700
+ Writer<unknown> | WritableWriter | WritableStream,
1701
+ boolean
1702
+ >,
1703
+ options?: ZipWriterConstructorOptions
1704
+ );
1705
+ /**
1706
+ * `true` if the zip contains at least one entry that has been partially written.
1707
+ */
1708
+ readonly hasCorruptedEntries?: boolean;
1709
+
1710
+ /**
1711
+ * Adds an existing zip file at the beginning of the current zip. This method
1712
+ * cannot be called after the first call to {@link ZipWriter#add}.
1713
+ *
1714
+ * @param reader The {@link Reader} instance used to read the content of the zip file.
1715
+ * @returns A promise resolving when the zip file has been added.
1716
+ */
1717
+ prependZip<ReaderType>(
1718
+ reader:
1719
+ | Reader<ReaderType>
1720
+ | ReadableReader
1721
+ | ReadableStream
1722
+ | Reader<unknown>[]
1723
+ | ReadableReader[]
1724
+ | ReadableStream[]
1725
+ ): Promise<void>;
1726
+
1727
+ /**
1728
+ * Adds an entry into the zip file
1729
+ *
1730
+ * @param filename The filename of the entry. Paths must use forward slashes ("/") as separator,
1731
+ * as required by section 4.4.17.1 of the zip specification. The value is stored as-is; in
1732
+ * particular, Windows path separators ("\\") are not converted and become part of the filename,
1733
+ * which is interpreted inconsistently by zip tools.
1734
+ * @param reader The {@link Reader} instance used to read the content of the entry.
1735
+ * @param options The options.
1736
+ * @returns A promise resolving to an {@link EntryMetaData} instance.
1737
+ */
1738
+ add<ReaderType>(
1739
+ filename: string,
1740
+ reader?:
1741
+ | Reader<ReaderType>
1742
+ | ReadableReader
1743
+ | ReadableStream
1744
+ | Reader<unknown>[]
1745
+ | ReadableReader[]
1746
+ | ReadableStream[],
1747
+ options?: ZipWriterAddDataOptions
1748
+ ): Promise<EntryMetaData>;
1749
+
1750
+ /**
1751
+ * Removes an entry from the central directory that will be written for the zip file. The entry
1752
+ * data itself cannot be removed because it has already been streamed to the output.
1753
+ *
1754
+ * @param entry The entry to remove. This can be an {@link Entry} instance or the filename of the entry.
1755
+ * @returns `true` if the entry has been removed, `false` otherwise.
1756
+ */
1757
+ remove(entry: Entry | string): boolean;
1758
+
1759
+ /**
1760
+ * Writes the entries directory, writes the global comment, and returns the content of the zip file
1761
+ *
1762
+ * @param comment The global comment of the zip file.
1763
+ * @param options The options.
1764
+ * @returns The content of the zip file.
1765
+ */
1766
+ close(comment?: Uint8Array, options?: ZipWriterCloseOptions): Promise<Type>;
1767
+ }
1768
+
1769
+ /**
1770
+ * Represents the options passed to {@link ZipWriter#add}.
1771
+ */
1772
+ export interface ZipWriterAddDataOptions
1773
+ extends ZipWriterConstructorOptions,
1774
+ EntryDataOnprogressOptions,
1775
+ WorkerConfiguration {
1776
+ /**
1777
+ * `true` if the entry is a directory.
1778
+ *
1779
+ * @defaultValue false
1780
+ */
1781
+ directory?: boolean;
1782
+ /**
1783
+ * `true` if the entry is an executable file.
1784
+ *
1785
+ * @defaultValue false
1786
+ */
1787
+ executable?: boolean;
1788
+ /**
1789
+ * The comment of the entry.
1790
+ */
1791
+ comment?: string;
1792
+ /**
1793
+ * The extra field of the entry.
1794
+ */
1795
+ extraField?: Map<number, Uint8Array>;
1796
+ /**
1797
+ * The uncompressed size of the entry. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
1798
+ */
1799
+ uncompressedSize?: number;
1800
+ /**
1801
+ * The signature (CRC32 checksum) of the content. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
1802
+ */
1803
+ signature?: number;
1804
+ }
1805
+
1806
+ /**
1807
+ * Represents the options passed to {@link ZipWriter#close}.
1808
+ */
1809
+ export interface ZipWriterCloseOptions extends EntryOnprogressOptions {
1810
+ /**
1811
+ * `true` to use Zip64 to write the entries directory.
1812
+ *
1813
+ * @defaultValue false
1814
+ */
1815
+ zip64?: boolean;
1816
+ /**
1817
+ * `true` to prevent closing of {@link WritableWriter#writable}.
1818
+ *
1819
+ * @defaultValue false
1820
+ */
1821
+ preventClose?: boolean;
1822
+ }
1823
+
1824
+ /**
1825
+ * Represents options passed to the constructor of {@link ZipWriter}, {@link ZipWriter#add} and `{@link ZipDirectoryEntry}#export*`.
1826
+ */
1827
+ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
1828
+ /**
1829
+ * `true` to use Zip64 to store the entry.
1830
+ *
1831
+ * `zip64` is automatically set to `true` when necessary (e.g. compressed data larger than 4GB or with unknown size).
1832
+ *
1833
+ * @defaultValue false
1834
+ */
1835
+ zip64?: boolean;
1836
+ /**
1837
+ * `true` to prevent closing of {@link WritableWriter#writable}.
1838
+ *
1839
+ * @defaultValue false
1840
+ */
1841
+ preventClose?: boolean;
1842
+ /**
1843
+ * The level of compression.
1844
+ *
1845
+ * The minimum value is 0 and means that no compression is applied. The maximum value is 9.
1846
+ *
1847
+ * @defaultValue 6
1848
+ */
1849
+ level?: number;
1850
+ /**
1851
+ * `true` to write entry data in a buffer before appending it to the zip file.
1852
+ *
1853
+ * `bufferedWrite` is automatically set to `true` when compressing more than one entry in parallel.
1854
+ *
1855
+ * @defaultValue false
1856
+ */
1857
+ bufferedWrite?: boolean;
1858
+ /**
1859
+ * An async factory function that returns a `TransformStream`-like object (`{ writable, readable }`) used as a temporary buffer when entries are written in parallel.
1860
+ *
1861
+ * When provided, this replaces the default in-memory `TransformStream` buffer, allowing data to be stored externally (e.g. filesystem, OPFS, network).
1862
+ * The `writable` side receives compressed entry data. The `readable` side is consumed when the entry is replayed into the final zip stream.
1863
+ * The optional `dispose` method is called once the entry has been processed (on success, error, or abort) so a resource-backed buffer can release its resource.
1864
+ *
1865
+ * See {@link createOPFSTempStream} for a ready-made OPFS-backed implementation, {@link createSyncAccessHandleTempStream} for a faster worker-only variant, and {@link createBlobTempStream} for a `Blob`-backed one.
1866
+ */
1867
+ createTempStream?: () => TempStream | Promise<TempStream>;
1868
+ /**
1869
+ * `true` to keep the order of the entry physically in the zip file.
1870
+ *
1871
+ * When set to `true`, the use of web workers will be improved.
1872
+ *
1873
+ * @defaultValue true
1874
+ */
1875
+ keepOrder?: boolean;
1876
+ /**
1877
+ * The password used to encrypt the content of the entry.
1878
+ */
1879
+ password?: string;
1880
+ /**
1881
+ * The password used to encrypt the content of the entry (raw).
1882
+ */
1883
+ rawPassword?: Uint8Array;
1884
+ /**
1885
+ * The encryption strength (AES):
1886
+ * - 1: 128-bit encryption key
1887
+ * - 2: 192-bit encryption key
1888
+ * - 3: 256-bit encryption key
1889
+ *
1890
+ * @defaultValue 3
1891
+ */
1892
+ encryptionStrength?: 1 | 2 | 3;
1893
+ /**
1894
+ * The `AbortSignal` instance used to cancel the compression.
1895
+ */
1896
+ signal?: AbortSignal;
1897
+ /**
1898
+ * The last modification date.
1899
+ *
1900
+ * @defaultValue The current date.
1901
+ */
1902
+ lastModDate?: Date;
1903
+ /**
1904
+ * The last access date.
1905
+ *
1906
+ * This option is ignored if the {@link ZipWriterConstructorOptions#extendedTimestamp} option is set to `false`.
1907
+ *
1908
+ * @defaultValue The current date.
1909
+ */
1910
+ lastAccessDate?: Date;
1911
+ /**
1912
+ * The creation date.
1913
+ *
1914
+ * This option is ignored if the {@link ZipWriterConstructorOptions#extendedTimestamp} option is set to `false`.
1915
+ *
1916
+ * @defaultValue The current date.
1917
+ */
1918
+ creationDate?: Date;
1919
+ /**
1920
+ * `true` to store extended timestamp extra fields.
1921
+ *
1922
+ * When set to `false`, the maximum last modification date cannot exceed November 31, 2107 and the maximum accuracy is 2 seconds.
1923
+ *
1924
+ * @defaultValue true
1925
+ */
1926
+ extendedTimestamp?: boolean;
1927
+ /**
1928
+ * `true` to use the ZipCrypto algorithm to encrypt the content of the entry. Setting it to `true` will also
1929
+ * set the {@link ZipWriterConstructorOptions#dataDescriptor} to `true`.
1930
+ *
1931
+ * It is not recommended to set `zipCrypto` to `true` because the ZipCrypto encryption can be easily broken.
1932
+ *
1933
+ * @defaultValue false
1934
+ */
1935
+ zipCrypto?: boolean;
1936
+ /**
1937
+ * The "Version" field.
1938
+ */
1939
+ version?: number;
1940
+ /**
1941
+ * The "Version made by" field.
1942
+ *
1943
+ * @defaultValue 20
1944
+ */
1945
+ versionMadeBy?: number;
1946
+ /**
1947
+ * `true` to mark the file names as UTF-8 setting the general purpose bit 11 in the header (see Appendix D -
1948
+ * Language Encoding (EFS)), `false` to mark the names as compliant with the original IBM Code Page 437.
1949
+ *
1950
+ * Note that this does not ensure that the file names are in the correct encoding.
1951
+ *
1952
+ * @defaultValue true
1953
+ */
1954
+ useUnicodeFileNames?: boolean;
1955
+ /**
1956
+ * `true` to add a data descriptor.
1957
+ *
1958
+ * When set to `false`, the {@link ZipWriterConstructorOptions#bufferedWrite} option will automatically be
1959
+ * set to `true`. It will be automatically set to `false` when it is `undefined` and the
1960
+ * {@link ZipWriterConstructorOptions#bufferedWrite} option is set to `true`, or when the
1961
+ * {@link ZipWriterConstructorOptions#zipCrypto} option is set to `true`. Otherwise, the default value is `true`.
1962
+ */
1963
+ dataDescriptor?: boolean;
1964
+ /**
1965
+ * `true` to add the signature of the data descriptor.
1966
+ *
1967
+ * @defaultValue true
1968
+ */
1969
+ dataDescriptorSignature?: boolean;
1970
+ /**
1971
+ * `true` to write {@link EntryMetaData#externalFileAttributes} in MS-DOS format for folder entries.
1972
+ *
1973
+ * @defaultValue false
1974
+ */
1975
+ msDosCompatible?: boolean;
1976
+ /**
1977
+ * The external file attribute.
1978
+ *
1979
+ * @defaultValue 0
1980
+ */
1981
+ externalFileAttributes?: number;
1982
+ /**
1983
+ * The Unix owner id to write in the Unix extra field or as part of the external attributes.
1984
+ */
1985
+ uid?: number;
1986
+ /**
1987
+ * The Unix group id to write in the Unix extra field or as part of the external attributes.
1988
+ */
1989
+ gid?: number;
1990
+ /**
1991
+ * The Unix mode (st_mode bits) to use when writing external attributes.
1992
+ */
1993
+ unixMode?: number;
1994
+ /**
1995
+ * `true` to set the setuid bit when writing the Unix mode.
1996
+ */
1997
+ setuid?: boolean;
1998
+ /**
1999
+ * `true` to set the setgid bit when writing the Unix mode.
2000
+ */
2001
+ setgid?: boolean;
2002
+ /**
2003
+ * `true` to set the sticky bit when writing the Unix mode.
2004
+ */
2005
+ sticky?: boolean;
2006
+ /**
2007
+ * Which Unix extra field format to write when creating entries that include Unix metadata.
2008
+ * - "infozip": Info-ZIP New Unix extra field (0x7875), storing variable-length uid/gid up to 32 bits.
2009
+ * - "unix": Info-ZIP Unix extra field type 2 (0x7855), storing fixed 2-byte uid/gid (0..65535); a
2010
+ * larger uid or gid is rejected. The Unix mode is not part of this field; it is written to the
2011
+ * external file attributes.
2012
+ */
2013
+ unixExtraFieldType?: "infozip" | "unix";
2014
+ /**
2015
+ * The internal file attribute.
2016
+ *
2017
+ * @defaultValue 0
2018
+ */
2019
+ internalFileAttributes?: number;
2020
+ /**
2021
+ * When provided, the low 8-bit MS-DOS attributes to write into external file attributes.
2022
+ * Must be an integer between 0 and 255.
2023
+ */
2024
+ msdosAttributesRaw?: number;
2025
+ /**
2026
+ * When provided, MS-DOS attribute flags (boolean object) to write into external file attributes low byte.
2027
+ */
2028
+ msdosAttributes?: {
2029
+ readOnly?: boolean;
2030
+ hidden?: boolean;
2031
+ system?: boolean;
2032
+ directory?: boolean;
2033
+ archive?: boolean;
2034
+ };
2035
+ /**
2036
+ * `false` to never write disk numbers in zip64 data.
2037
+ *
2038
+ * @defaultValue true
2039
+ */
2040
+ supportZip64SplitFile?: boolean;
2041
+ /**
2042
+ * `true`to produce zip files compatible with the USDZ specification.
2043
+ *
2044
+ * @defaultValue false
2045
+ */
2046
+ usdz?: boolean;
2047
+ /**
2048
+ * `true` to write the data as-is without compressing it and without crypting it.
2049
+ */
2050
+ passThrough?: boolean;
2051
+ /**
2052
+ * `true` to write encrypted data when `passThrough` is set to `true`.
2053
+ */
2054
+ encrypted?: boolean;
2055
+ /**
2056
+ * The offset of the first entry in the zip file.
2057
+ */
2058
+ offset?: number;
2059
+ /**
2060
+ * The compression method (e.g. 8 for DEFLATE, 0 for STORE).
2061
+ */
2062
+ compressionMethod?: number;
2063
+ /**
2064
+ * The function called for encoding the filename and the comment of the entry.
2065
+ *
2066
+ * @param text The text to encode.
2067
+ * @returns The encoded text or `undefined` if the text should be encoded by zip.js.
2068
+ */
2069
+ encodeText?(text: string): Uint8Array | undefined;
2070
+ }
2071
+
2072
+ /**
2073
+ * Represents options passed to {@link FileEntry#getData}, {@link ZipWriter.add} and `{@link ZipDirectory}.export*`.
2074
+ */
2075
+ export interface EntryDataOnprogressOptions {
2076
+ /**
2077
+ * The function called when starting compression/decompression.
2078
+ *
2079
+ * @param total The total number of bytes.
2080
+ * @returns An empty promise or `undefined`.
2081
+ */
2082
+ onstart?(total: number): Promise<void> | void;
2083
+ /**
2084
+ * The function called during compression/decompression.
2085
+ *
2086
+ * @param progress The current progress in bytes.
2087
+ * @param total The total number of bytes.
2088
+ * @returns An empty promise or `undefined`.
2089
+ */
2090
+ onprogress?(progress: number, total: number): Promise<void> | void;
2091
+ /**
2092
+ * The function called when ending compression/decompression.
2093
+ *
2094
+ * @param computedSize The total number of bytes (computed).
2095
+ * @returns An empty promise or `undefined`.
2096
+ */
2097
+ onend?(computedSize: number): Promise<void> | void;
2098
+ }
2099
+
2100
+ /**
2101
+ * Represents options passed to {@link ZipReader#getEntries}, {@link ZipReader#getEntriesGenerator}, and {@link ZipWriter#close}.
2102
+ */
2103
+ export interface EntryOnprogressOptions {
2104
+ /**
2105
+ * The function called each time an entry is read/written.
2106
+ *
2107
+ * @param progress The entry index.
2108
+ * @param total The total number of entries.
2109
+ * @param entry The entry being read/written.
2110
+ * @returns An empty promise or `undefined`.
2111
+ */
2112
+ onprogress?(
2113
+ progress: number,
2114
+ total: number,
2115
+ entry: EntryMetaData
2116
+ ): Promise<void> | void;
2117
+ }
2118
+
2119
+ /**
2120
+ * Represents an entry in a zip file (Filesystem API).
2121
+ */
2122
+ declare class ZipEntry {
2123
+ /**
2124
+ * The relative filename of the entry.
2125
+ */
2126
+ name: string;
2127
+ /**
2128
+ * The underlying {@link EntryMetaData} instance.
2129
+ */
2130
+ data?: EntryMetaData;
2131
+ /**
2132
+ * The ID of the instance.
2133
+ */
2134
+ id: number;
2135
+ /**
2136
+ * The parent directory of the entry.
2137
+ */
2138
+ parent?: ZipEntry;
2139
+ /**
2140
+ * The uncompressed size of the content.
2141
+ */
2142
+ uncompressedSize: number;
2143
+ /**
2144
+ * The children of the entry.
2145
+ */
2146
+ children: ZipEntry[];
2147
+ /**
2148
+ * Clones the entry
2149
+ *
2150
+ * @param deepClone `true` to clone all the descendants.
2151
+ */
2152
+ clone(deepClone?: boolean): ZipEntry;
2153
+ /**
2154
+ * Returns the full filename of the entry
2155
+ */
2156
+ getFullname(): string;
2157
+ /**
2158
+ * Returns the filename of the entry relative to a parent directory
2159
+ */
2160
+ getRelativeName(ancestor: ZipDirectoryEntry): string;
2161
+ /**
2162
+ * Tests if a {@link ZipDirectoryEntry} instance is an ancestor of the entry
2163
+ *
2164
+ * @param ancestor The {@link ZipDirectoryEntry} instance.
2165
+ */
2166
+ isDescendantOf(ancestor: ZipDirectoryEntry): boolean;
2167
+ /**
2168
+ * Tests if the entry or any of its children is password protected
2169
+ */
2170
+ isPasswordProtected(): boolean;
2171
+ /**
2172
+ * Tests the password on the entry and all children if any, returns `true` if the entry is not password protected
2173
+ */
2174
+ checkPassword(
2175
+ password: string,
2176
+ options?: EntryGetDataOptions
2177
+ ): Promise<boolean>;
2178
+ /**
2179
+ * Set the name of the entry
2180
+ *
2181
+ * @param name The new name of the entry.
2182
+ */
2183
+ rename(name: string): void;
2184
+ }
2185
+
2186
+ /**
2187
+ * Represents a file entry in the zip (Filesystem API).
2188
+ */
2189
+ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
2190
+ /**
2191
+ * `void` for {@link ZipFileEntry} instances.
2192
+ */
2193
+ directory: void;
2194
+ /**
2195
+ * The {@link Reader} instance used to read the content of the entry.
2196
+ */
2197
+ reader:
2198
+ | Reader<ReaderType>
2199
+ | ReadableReader
2200
+ | ReadableStream
2201
+ | Reader<unknown>[]
2202
+ | ReadableReader[]
2203
+ | ReadableStream[];
2204
+ /**
2205
+ * The {@link Writer} instance used to write the content of the entry.
2206
+ */
2207
+ writer:
2208
+ | Writer<WriterType>
2209
+ | WritableWriter
2210
+ | WritableStream
2211
+ | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>;
2212
+ /**
2213
+ * Retrieves the text content of the entry as a `string`
2214
+ *
2215
+ * @param encoding The encoding of the text.
2216
+ * @param options The options.
2217
+ * @returns A promise resolving to a `string`.
2218
+ */
2219
+ getText(encoding?: string, options?: EntryGetDataOptions): Promise<string>;
2220
+ /**
2221
+ * Retrieves the content of the entry as a `Blob` instance
2222
+ *
2223
+ * @param mimeType The MIME type of the content.
2224
+ * @param options The options.
2225
+ * @returns A promise resolving to a `Blob` instance.
2226
+ */
2227
+ getBlob(mimeType?: string, options?: EntryGetDataOptions): Promise<Blob>;
2228
+ /**
2229
+ * Retrieves the content of the entry as as a Data URI `string` encoded in Base64
2230
+ *
2231
+ * @param mimeType The MIME type of the content.
2232
+ * @param options The options.
2233
+ * @returns A promise resolving to a Data URI `string` encoded in Base64.
2234
+ */
2235
+ getData64URI(
2236
+ mimeType?: string,
2237
+ options?: EntryGetDataOptions
2238
+ ): Promise<string>;
2239
+ /**
2240
+ * Retrieves the content of the entry as a `Uint8Array` instance
2241
+ *
2242
+ * @param options The options.
2243
+ * @returns A promise resolving to a `Uint8Array` instance.
2244
+ */
2245
+ getUint8Array(options?: EntryGetDataOptions): Promise<Uint8Array>;
2246
+ /**
2247
+ * Retrieves the content of the entry via a `WritableStream` instance
2248
+ *
2249
+ * @param writable The `WritableStream` instance.
2250
+ * @param options The options.
2251
+ * @returns A promise resolving to the `WritableStream` instance.
2252
+ */
2253
+ getWritable(
2254
+ writable?: WritableStream,
2255
+ options?: EntryGetDataOptions
2256
+ ): Promise<WritableStream>;
2257
+ /**
2258
+ * Retrieves the content of the entry via a {@link Writer} instance
2259
+ *
2260
+ * @param writer The {@link Writer} instance.
2261
+ * @param options The options.
2262
+ * @returns A promise resolving to data associated to the {@link Writer} instance.
2263
+ */
2264
+ getData<Type>(
2265
+ writer:
2266
+ | Writer<unknown>
2267
+ | WritableWriter
2268
+ | WritableStream
2269
+ | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>,
2270
+ options?: EntryGetDataOptions
2271
+ ): Promise<Type>;
2272
+ /**
2273
+ * Retrieves the content of the entry as an `ArrayBuffer` instance
2274
+ *
2275
+ * @param options The options.
2276
+ * @returns A promise resolving to an `ArrayBuffer` instance.
2277
+ */
2278
+ getArrayBuffer(options?: EntryGetDataOptions): Promise<ArrayBuffer>;
2279
+ /**
2280
+ * Replaces the content of the entry with a `Blob` instance
2281
+ *
2282
+ * @param blob The `Blob` instance.
2283
+ */
2284
+ replaceBlob(blob: Blob): void;
2285
+ /**
2286
+ * Replaces the content of the entry with a `string`
2287
+ *
2288
+ * @param text The `string`.
2289
+ */
2290
+ replaceText(text: string): void;
2291
+ /**
2292
+ * Replaces the content of the entry with a Data URI `string` encoded in Base64
2293
+ *
2294
+ * @param dataURI The Data URI `string` encoded in Base64.
2295
+ */
2296
+ replaceData64URI(dataURI: string): void;
2297
+ /**
2298
+ * Replaces the content of the entry with a `Uint8Array` instance
2299
+ *
2300
+ * @param array The `Uint8Array` instance.
2301
+ */
2302
+ replaceUint8Array(array: Uint8Array): void;
2303
+ /**
2304
+ * Replaces the content of the entry with a `ReadableStream` instance
2305
+ *
2306
+ * @param readable The `ReadableStream` instance.
2307
+ */
2308
+ replaceReadable(readable: ReadableStream): void;
2309
+ }
2310
+
2311
+ /**
2312
+ * Represents a directory entry in the zip (Filesystem API).
2313
+ */
2314
+ export class ZipDirectoryEntry extends ZipEntry {
2315
+ /**
2316
+ * `true` for {@link ZipDirectoryEntry} instances.
2317
+ */
2318
+ directory: true;
2319
+ /**
2320
+ * Gets a {@link ZipEntry} child instance from its relative filename
2321
+ *
2322
+ * @param name The relative filename.
2323
+ * @returns A {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance (use the {@link ZipFileEntry#directory} and {@link ZipDirectoryEntry#directory} properties to differentiate entries).
2324
+ */
2325
+ getChildByName(name: string): ZipEntry | undefined;
2326
+ /**
2327
+ * Adds a directory
2328
+ *
2329
+ * @param name The relative filename of the directory.
2330
+ * @param options The options.
2331
+ * @returns A {@link ZipDirectoryEntry} instance.
2332
+ */
2333
+ addDirectory(
2334
+ name: string,
2335
+ options?: ZipWriterAddDataOptions
2336
+ ): ZipDirectoryEntry;
2337
+ /**
2338
+ * Adds an entry with content provided as text
2339
+ *
2340
+ * @param name The relative filename of the entry.
2341
+ * @param text The text.
2342
+ * @param options The options.
2343
+ * @returns A {@link ZipFileEntry} instance.
2344
+ */
2345
+ addText(
2346
+ name: string,
2347
+ text: string,
2348
+ options?: ZipWriterAddDataOptions
2349
+ ): ZipFileEntry<string, string>;
2350
+ /**
2351
+ * Adds a entry entry with content provided as a `Blob` instance
2352
+ *
2353
+ * @param name The relative filename of the entry.
2354
+ * @param blob The `Blob` instance.
2355
+ * @param options The options.
2356
+ * @returns A {@link ZipFileEntry} instance.
2357
+ */
2358
+ addBlob(
2359
+ name: string,
2360
+ blob: Blob,
2361
+ options?: ZipWriterAddDataOptions
2362
+ ): ZipFileEntry<Blob, Blob>;
2363
+ /**
2364
+ * Adds a entry entry with content provided as a Data URI `string` encoded in Base64
2365
+ *
2366
+ * @param name The relative filename of the entry.
2367
+ * @param dataURI The Data URI `string` encoded in Base64.
2368
+ * @param options The options.
2369
+ * @returns A {@link ZipFileEntry} instance.
2370
+ */
2371
+ addData64URI(
2372
+ name: string,
2373
+ dataURI: string,
2374
+ options?: ZipWriterAddDataOptions
2375
+ ): ZipFileEntry<string, string>;
2376
+ /**
2377
+ * Adds an entry with content provided as a `Uint8Array` instance
2378
+ *
2379
+ * @param name The relative filename of the entry.
2380
+ * @param array The `Uint8Array` instance.
2381
+ * @param options The options.
2382
+ * @returns A {@link ZipFileEntry} instance.
2383
+ */
2384
+ addUint8Array(
2385
+ name: string,
2386
+ array: Uint8Array,
2387
+ options?: ZipWriterAddDataOptions
2388
+ ): ZipFileEntry<Uint8Array, Uint8Array>;
2389
+ /**
2390
+ * Adds an entry with content fetched from a URL
2391
+ *
2392
+ * @param name The relative filename of the entry.
2393
+ * @param url The URL.
2394
+ * @param options The options.
2395
+ * @returns A {@link ZipFileEntry} instance.
2396
+ */
2397
+ addHttpContent(
2398
+ name: string,
2399
+ url: string,
2400
+ options?: HttpOptions & ZipWriterAddDataOptions
2401
+ ): ZipFileEntry<string, void>;
2402
+ /**
2403
+ * Adds a entry entry with content provided via a `ReadableStream` instance
2404
+ *
2405
+ * @param name The relative filename of the entry.
2406
+ * @param readable The `ReadableStream` instance.
2407
+ * @param options The options.
2408
+ * @returns A {@link ZipFileEntry} instance.
2409
+ */
2410
+ addReadable(
2411
+ name: string,
2412
+ readable: ReadableStream,
2413
+ options?: ZipWriterAddDataOptions
2414
+ ): ZipFileEntry<ReadableStream, void>;
2415
+ /**
2416
+ * Adds an entry with content provided via a `File` instance
2417
+ *
2418
+ * @param file The `File` instance.
2419
+ * @param options The options.
2420
+ * @returns A promise resolving to a {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance.
2421
+ */
2422
+ addFile(file: File, options?: ZipWriterAddDataOptions): Promise<ZipEntry>;
2423
+ /**
2424
+ * Adds an entry with content provided via a `FileSystemEntry` instance
2425
+ *
2426
+ * @param fileSystemEntry The `FileSystemEntry` instance.
2427
+ * @param options The options.
2428
+ * @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
2429
+ */
2430
+ addFileSystemEntry(
2431
+ fileSystemEntry: FileSystemEntryLike,
2432
+ options?: ZipWriterAddDataOptions
2433
+ ): Promise<ZipEntry[]>;
2434
+ /**
2435
+ * Adds an entry with content provided via a `FileSystemHandle` instance
2436
+ *
2437
+ * @param fileSystemHandle The `fileSystemHandle` instance.
2438
+ * @param options The options.
2439
+ * @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
2440
+ */
2441
+ addFileSystemHandle(
2442
+ fileSystemHandle: FileSystemHandleLike,
2443
+ options?: ZipWriterAddDataOptions
2444
+ ): Promise<ZipEntry[]>;
2445
+ /**
2446
+ * Extracts a zip file provided as a `Blob` instance into the entry
2447
+ *
2448
+ * @param blob The `Blob` instance.
2449
+ * @param options The options.
2450
+ */
2451
+ importBlob(
2452
+ blob: Blob,
2453
+ options?: ZipReaderConstructorOptions
2454
+ ): Promise<[ZipEntry]>;
2455
+ /**
2456
+ * Extracts a zip file provided as a Data URI `string` encoded in Base64 into the entry
2457
+ *
2458
+ * @param dataURI The Data URI `string` encoded in Base64.
2459
+ * @param options The options.
2460
+ */
2461
+ importData64URI(
2462
+ dataURI: string,
2463
+ options?: ZipReaderConstructorOptions
2464
+ ): Promise<[ZipEntry]>;
2465
+ /**
2466
+ * Extracts a zip file provided as a `Uint8Array` instance into the entry
2467
+ *
2468
+ * @param array The `Uint8Array` instance.
2469
+ * @param options The options.
2470
+ */
2471
+ importUint8Array(
2472
+ array: Uint8Array,
2473
+ options?: ZipReaderConstructorOptions
2474
+ ): Promise<[ZipEntry]>;
2475
+ /**
2476
+ * Extracts a zip file fetched from a URL into the entry
2477
+ *
2478
+ * @param url The URL.
2479
+ * @param options The options.
2480
+ */
2481
+ importHttpContent(
2482
+ url: string,
2483
+ options?: ZipDirectoryEntryImportHttpOptions
2484
+ ): Promise<[ZipEntry]>;
2485
+ /**
2486
+ * Extracts a zip file provided via a `ReadableStream` instance into the entry
2487
+ *
2488
+ * @param readable The `ReadableStream` instance.
2489
+ * @param options The options.
2490
+ */
2491
+ importReadable(
2492
+ readable: ReadableStream,
2493
+ options?: ZipReaderConstructorOptions
2494
+ ): Promise<[ZipEntry]>;
2495
+ /**
2496
+ * Extracts a zip file provided via a custom {@link Reader} instance into the entry
2497
+ *
2498
+ * @param reader The {@link Reader} instance.
2499
+ * @param options The options.
2500
+ */
2501
+ importZip(
2502
+ reader:
2503
+ | Reader<unknown>
2504
+ | ReadableReader
2505
+ | ReadableStream
2506
+ | Reader<unknown>[]
2507
+ | ReadableReader[]
2508
+ | ReadableStream[],
2509
+ options?: ZipReaderConstructorOptions
2510
+ ): Promise<[ZipEntry]>;
2511
+ /**
2512
+ * Returns a `Blob` instance containing a zip file of the entry and its descendants
2513
+ *
2514
+ * @param options The options.
2515
+ * @returns A promise resolving to the `Blob` instance.
2516
+ */
2517
+ exportBlob(options?: ZipDirectoryEntryExportOptions): Promise<Blob>;
2518
+ /**
2519
+ * Returns a Data URI `string` encoded in Base64 containing a zip file of the entry and its descendants
2520
+ *
2521
+ * @param options The options.
2522
+ * @returns A promise resolving to the Data URI `string` encoded in Base64.
2523
+ */
2524
+ exportData64URI(options?: ZipDirectoryEntryExportOptions): Promise<string>;
2525
+ /**
2526
+ * Returns a `Uint8Array` instance containing a zip file of the entry and its descendants
2527
+ *
2528
+ * @param options The options.
2529
+ * @returns A promise resolving to the `Uint8Array` instance.
2530
+ */
2531
+ exportUint8Array(
2532
+ options?: ZipDirectoryEntryExportOptions
2533
+ ): Promise<Uint8Array>;
2534
+ /**
2535
+ * Creates a zip file via a `WritableStream` instance containing the entry and its descendants
2536
+ *
2537
+ * @param writable The `WritableStream` instance.
2538
+ * @param options The options.
2539
+ * @returns A promise resolving to the `Uint8Array` instance.
2540
+ */
2541
+ exportWritable(
2542
+ writable?: WritableStream,
2543
+ options?: ZipDirectoryEntryExportOptions
2544
+ ): Promise<WritableStream>;
2545
+ /**
2546
+ * Writes the entry and its descendants into a directory as files and sub-directories via the File System Access API (e.g. the Origin Private File System). Files are streamed and directories are merged into the target; colliding files are overwritten. This is the inverse of {@link ZipDirectoryEntry#addFileSystemHandle}.
2547
+ *
2548
+ * @param directoryHandle The target `FileSystemDirectoryHandle` instance.
2549
+ * @param options The options.
2550
+ * @returns A promise resolving to the target `FileSystemDirectoryHandle` instance.
2551
+ */
2552
+ exportFileSystemHandle(
2553
+ directoryHandle: FileSystemDirectoryHandle,
2554
+ options?: ZipDirectoryEntryExportFileSystemHandleOptions
2555
+ ): Promise<FileSystemDirectoryHandle>;
2556
+ /**
2557
+ * Creates a zip file via a custom {@link Writer} instance containing the entry and its descendants
2558
+ *
2559
+ * @param writer The {@link Writer} instance.
2560
+ * @param options The options.
2561
+ * @returns A promise resolving to the data.
2562
+ */
2563
+ exportZip(
2564
+ writer:
2565
+ | Writer<unknown>
2566
+ | WritableWriter
2567
+ | WritableStream
2568
+ | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>,
2569
+ options?: ZipDirectoryEntryExportOptions
2570
+ ): Promise<unknown>;
2571
+ }
2572
+
2573
+ /**
2574
+ * Represents the options passed to {@link ZipDirectoryEntry#importHttpContent}.
2575
+ */
2576
+ export interface ZipDirectoryEntryImportHttpOptions
2577
+ extends ZipReaderConstructorOptions,
2578
+ HttpOptions {}
2579
+
2580
+ /**
2581
+ * Represents the options passed to `{@link ZipDirectoryEntry}#export*()`.
2582
+ */
2583
+ export interface ZipDirectoryEntryExportOptions
2584
+ extends ZipWriterConstructorOptions,
2585
+ EntryDataOnprogressOptions {
2586
+ /**
2587
+ * `true` to use filenames relative to the entry instead of full filenames.
2588
+ */
2589
+ relativePath?: boolean;
2590
+ /**
2591
+ * The MIME type of the exported data when relevant.
2592
+ */
2593
+ mimeType?: string;
2594
+ /**
2595
+ * The options passed to the Reader instances
2596
+ */
2597
+ readerOptions?: ZipReaderConstructorOptions;
2598
+ }
2599
+
2600
+ /**
2601
+ * Represents the options passed to {@link ZipDirectoryEntry#exportFileSystemHandle} and {@link FS#exportFileSystemHandle}.
2602
+ */
2603
+ export interface ZipDirectoryEntryExportFileSystemHandleOptions
2604
+ extends EntryGetDataOptions {
2605
+ /**
2606
+ * `true` to write independent files concurrently instead of one after another.
2607
+ *
2608
+ * @defaultValue false
2609
+ */
2610
+ concurrent?: boolean;
2611
+ }
2612
+
2613
+ /**
2614
+ * Represents a Filesystem instance.
2615
+ *
2616
+ * @example
2617
+ * Here is an example showing how to create and read a zip file containing a compressed text file:
2618
+ * ```
2619
+ * const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.";
2620
+ * const FILENAME = "lorem.txt";
2621
+ * const BLOB = new Blob([TEXT_CONTENT], { type: zip.getMimeType(FILENAME) });
2622
+ * let zipFs = new zip.fs.FS();
2623
+ * zipFs.addBlob("lorem.txt", BLOB);
2624
+ * const zippedBlob = await zipFs.exportBlob();
2625
+ * zipFs = new zip.fs.FS();
2626
+ * await zipFs.importBlob(zippedBlob);
2627
+ * const firstEntry = zipFs.children[0];
2628
+ * const unzippedBlob = await firstEntry.getBlob(zip.getMimeType(firstEntry.name));
2629
+ * ```
2630
+ */
2631
+ export interface FS
2632
+ extends Pick<
2633
+ ZipDirectoryEntry,
2634
+ | "getChildByName"
2635
+ | "addDirectory"
2636
+ | "addText"
2637
+ | "addBlob"
2638
+ | "addData64URI"
2639
+ | "addUint8Array"
2640
+ | "addHttpContent"
2641
+ | "addReadable"
2642
+ | "addFile"
2643
+ | "addFileSystemEntry"
2644
+ | "addFileSystemHandle"
2645
+ | "importBlob"
2646
+ | "importData64URI"
2647
+ | "importUint8Array"
2648
+ | "importHttpContent"
2649
+ | "importReadable"
2650
+ | "importZip"
2651
+ | "exportBlob"
2652
+ | "exportData64URI"
2653
+ | "exportUint8Array"
2654
+ | "exportWritable"
2655
+ | "exportFileSystemHandle"
2656
+ | "exportZip"
2657
+ | "isPasswordProtected"
2658
+ | "checkPassword"
2659
+ > {}
2660
+
2661
+ export class FS {
2662
+ /**
2663
+ * The root directory.
2664
+ */
2665
+ root: ZipDirectoryEntry;
2666
+ /**
2667
+ * The array of all the {@link ZipEntry} instances indexed by {@link ZipEntry#id}.
2668
+ */
2669
+ entries: (ZipEntry | null)[];
2670
+ /**
2671
+ * The children of the root directory.
2672
+ */
2673
+ readonly children: ZipEntry[];
2674
+ /**
2675
+ * Removes a {@link ZipEntry} instance and its children
2676
+ *
2677
+ * @param entry The {@link ZipEntry} instance to remove.
2678
+ */
2679
+ remove(entry: ZipEntry): void;
2680
+ /**
2681
+ * Moves a {@link ZipEntry} instance and its children into a {@link ZipDirectoryEntry} instance
2682
+ *
2683
+ * @param entry The {@link ZipEntry} instance to move.
2684
+ * @param destination The {@link ZipDirectoryEntry} instance.
2685
+ */
2686
+ move(entry: ZipEntry, destination: ZipDirectoryEntry): void;
2687
+ /**
2688
+ * Returns a {@link ZipEntry} instance from its full filename
2689
+ *
2690
+ * @param fullname The full filename.
2691
+ * @returns The {@link ZipEntry} instance.
2692
+ */
2693
+ find(fullname: string): ZipEntry | undefined;
2694
+ /**
2695
+ * Returns a {@link ZipEntry} instance from the value of {@link ZipEntry#id}
2696
+ *
2697
+ * @param id The id of the {@link ZipEntry} instance.
2698
+ * @returns The {@link ZipEntry} instance.
2699
+ */
2700
+ getById(id: number): ZipEntry | undefined;
2701
+ }
2702
+
2703
+ /**
2704
+ * The Filesystem API.
2705
+ */
2706
+ export const fs: {
2707
+ /**
2708
+ * The Filesystem constructor.
2709
+ *
2710
+ * @defaultValue {@link FS}
2711
+ */
2712
+ FS: typeof FS;
2713
+ /**
2714
+ * The {@link ZipDirectoryEntry} constructor.
2715
+ *
2716
+ * @defaultValue {@link ZipDirectoryEntry}
2717
+ */
2718
+ ZipDirectoryEntry: typeof ZipDirectoryEntry;
2719
+ /**
2720
+ * The {@link ZipFileEntry} constructor.
2721
+ *
2722
+ * @defaultValue {@link ZipFileEntry}
2723
+ */
2724
+ ZipFileEntry: typeof ZipFileEntry;
2725
+ };
2726
+
2727
+ // The error messages.
2728
+ /**
2729
+ * HTTP range error
2730
+ */
2731
+ export const ERR_HTTP_RANGE: string;
2732
+ /**
2733
+ * Zip format error
2734
+ */
2735
+ export const ERR_BAD_FORMAT: string;
2736
+ /**
2737
+ * End of Central Directory Record not found error
2738
+ */
2739
+ export const ERR_EOCDR_NOT_FOUND: string;
2740
+ /**
2741
+ * Zip64 End of Central Directory Locator not found error
2742
+ */
2743
+ export const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: string;
2744
+ /**
2745
+ * Central Directory not found error
2746
+ */
2747
+ export const ERR_CENTRAL_DIRECTORY_NOT_FOUND: string;
2748
+ /**
2749
+ * Local file header not found error
2750
+ */
2751
+ export const ERR_LOCAL_FILE_HEADER_NOT_FOUND: string;
2752
+ /**
2753
+ * Extra field Zip64 not found error
2754
+ */
2755
+ export const ERR_EXTRAFIELD_ZIP64_NOT_FOUND: string;
2756
+ /**
2757
+ * Encrypted entry error
2758
+ */
2759
+ export const ERR_ENCRYPTED: string;
2760
+ /**
2761
+ * Unsupported encryption error
2762
+ */
2763
+ export const ERR_UNSUPPORTED_ENCRYPTION: string;
2764
+ /**
2765
+ * Unsupported compression error
2766
+ */
2767
+ export const ERR_UNSUPPORTED_COMPRESSION: string;
2768
+ /**
2769
+ * Invalid signature error
2770
+ */
2771
+ export const ERR_INVALID_SIGNATURE: string;
2772
+ /**
2773
+ * Invalid uncompressed size error
2774
+ */
2775
+ export const ERR_INVALID_UNCOMPRESSED_SIZE: string;
2776
+ /**
2777
+ * Invalid compressed data error
2778
+ */
2779
+ export const ERR_INVALID_COMPRESSED_DATA: string;
2780
+ /**
2781
+ * Invalid password error
2782
+ */
2783
+ export const ERR_INVALID_PASSWORD: string;
2784
+ /**
2785
+ * Duplicate entry error
2786
+ */
2787
+ export const ERR_DUPLICATED_NAME: string;
2788
+ /**
2789
+ * Invalid comment error
2790
+ */
2791
+ export const ERR_INVALID_COMMENT: string;
2792
+ /**
2793
+ * Invalid entry name error
2794
+ */
2795
+ export const ERR_INVALID_ENTRY_NAME: string;
2796
+ /**
2797
+ * Invalid entry comment error
2798
+ */
2799
+ export const ERR_INVALID_ENTRY_COMMENT: string;
2800
+ /**
2801
+ * Invalid version error
2802
+ */
2803
+ export const ERR_INVALID_VERSION: string;
2804
+ /**
2805
+ * Invalid extra field type error
2806
+ */
2807
+ export const ERR_INVALID_EXTRAFIELD_TYPE: string;
2808
+ /**
2809
+ * Invalid extra field data error
2810
+ */
2811
+ export const ERR_INVALID_EXTRAFIELD_DATA: string;
2812
+ /**
2813
+ * Invalid encryption strength error
2814
+ */
2815
+ export const ERR_INVALID_ENCRYPTION_STRENGTH: string;
2816
+ /**
2817
+ * Invalid format error
2818
+ */
2819
+ export const ERR_UNSUPPORTED_FORMAT: string;
2820
+ /**
2821
+ * Split zip file error
2822
+ */
2823
+ export const ERR_SPLIT_ZIP_FILE: string;
2824
+ /**
2825
+ * Overlapping entry error
2826
+ */
2827
+ export const ERR_OVERLAPPING_ENTRY: string;
2828
+ /**
2829
+ * Ambiguous archive error
2830
+ *
2831
+ * @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"`.
2832
+ */
2833
+ export const ERR_AMBIGUOUS_ARCHIVE: string;
2834
+ /**
2835
+ * Iteration completed too soon error
2836
+ */
2837
+ export const ERR_ITERATOR_COMPLETED_TOO_SOON: string;
2838
+ /**
2839
+ * Undefined uncompressed size error
2840
+ */
2841
+ export const ERR_UNDEFINED_UNCOMPRESSED_SIZE: string;
2842
+ /**
2843
+ * Undefined reader error
2844
+ */
2845
+ export const ERR_UNDEFINED_READER: string;
2846
+ /**
2847
+ * Writer not initialized error
2848
+ */
2849
+ export const ERR_WRITER_NOT_INITIALIZED: string;
2850
+ /**
2851
+ * Zip file not empty error
2852
+ */
2853
+ export const ERR_ZIP_NOT_EMPTY: string;