@helloao/cli 0.0.1

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 (110) hide show
  1. package/actions.d.ts +57 -0
  2. package/actions.js +262 -0
  3. package/cli.d.ts +2 -0
  4. package/cli.js +139 -0
  5. package/db.d.ts +110 -0
  6. package/db.js +754 -0
  7. package/downloads.d.ts +2 -0
  8. package/downloads.js +12 -0
  9. package/files.d.ts +56 -0
  10. package/files.js +232 -0
  11. package/index.d.ts +8 -0
  12. package/index.js +38 -0
  13. package/migrations/20240420231455_initial/migration.sql +66 -0
  14. package/migrations/20240623183848_add_book_order/migration.sql +26 -0
  15. package/migrations/20240629194121_add_chapter_links/migration.sql +45 -0
  16. package/migrations/20240629194513_add_chapter_content/migration.sql +30 -0
  17. package/migrations/20240705221833_remove_unused_columns/migration.sql +27 -0
  18. package/migrations/20240711173108_add_chapter_audio/migration.sql +13 -0
  19. package/migrations/20240724212651_add_hashing/migration.sql +25 -0
  20. package/node_modules/@zip.js/zip.js/LICENSE +28 -0
  21. package/node_modules/@zip.js/zip.js/README.md +173 -0
  22. package/node_modules/@zip.js/zip.js/deno.json +8 -0
  23. package/node_modules/@zip.js/zip.js/dist/README.md +28 -0
  24. package/node_modules/@zip.js/zip.js/dist/z-worker-fflate.js +1 -0
  25. package/node_modules/@zip.js/zip.js/dist/z-worker-pako.js +1 -0
  26. package/node_modules/@zip.js/zip.js/dist/z-worker.js +1 -0
  27. package/node_modules/@zip.js/zip.js/dist/zip-fs-full.js +11935 -0
  28. package/node_modules/@zip.js/zip.js/dist/zip-fs-full.min.js +1 -0
  29. package/node_modules/@zip.js/zip.js/dist/zip-fs.js +6079 -0
  30. package/node_modules/@zip.js/zip.js/dist/zip-fs.min.js +1 -0
  31. package/node_modules/@zip.js/zip.js/dist/zip-full.js +9463 -0
  32. package/node_modules/@zip.js/zip.js/dist/zip-full.min.js +1 -0
  33. package/node_modules/@zip.js/zip.js/dist/zip-no-worker-deflate.min.js +1 -0
  34. package/node_modules/@zip.js/zip.js/dist/zip-no-worker-inflate.min.js +1 -0
  35. package/node_modules/@zip.js/zip.js/dist/zip-no-worker.min.js +1 -0
  36. package/node_modules/@zip.js/zip.js/dist/zip.js +5240 -0
  37. package/node_modules/@zip.js/zip.js/dist/zip.min.js +1 -0
  38. package/node_modules/@zip.js/zip.js/index-fflate.js +82 -0
  39. package/node_modules/@zip.js/zip.js/index.cjs +11927 -0
  40. package/node_modules/@zip.js/zip.js/index.d.ts +2048 -0
  41. package/node_modules/@zip.js/zip.js/index.js +87 -0
  42. package/node_modules/@zip.js/zip.js/index.min.js +1 -0
  43. package/node_modules/@zip.js/zip.js/lib/core/codec-pool.js +127 -0
  44. package/node_modules/@zip.js/zip.js/lib/core/codec-worker.js +348 -0
  45. package/node_modules/@zip.js/zip.js/lib/core/configuration.js +127 -0
  46. package/node_modules/@zip.js/zip.js/lib/core/constants.js +114 -0
  47. package/node_modules/@zip.js/zip.js/lib/core/io.js +749 -0
  48. package/node_modules/@zip.js/zip.js/lib/core/streams/aes-crypto-stream.js +326 -0
  49. package/node_modules/@zip.js/zip.js/lib/core/streams/codec-stream.js +154 -0
  50. package/node_modules/@zip.js/zip.js/lib/core/streams/codecs/crc32.js +63 -0
  51. package/node_modules/@zip.js/zip.js/lib/core/streams/codecs/deflate.js +2063 -0
  52. package/node_modules/@zip.js/zip.js/lib/core/streams/codecs/inflate.js +2167 -0
  53. package/node_modules/@zip.js/zip.js/lib/core/streams/codecs/sjcl.js +827 -0
  54. package/node_modules/@zip.js/zip.js/lib/core/streams/common-crypto.js +55 -0
  55. package/node_modules/@zip.js/zip.js/lib/core/streams/crc32-stream.js +56 -0
  56. package/node_modules/@zip.js/zip.js/lib/core/streams/stream-adapter.js +55 -0
  57. package/node_modules/@zip.js/zip.js/lib/core/streams/zip-crypto-stream.js +162 -0
  58. package/node_modules/@zip.js/zip.js/lib/core/streams/zip-entry-stream.js +165 -0
  59. package/node_modules/@zip.js/zip.js/lib/core/util/cp437-decode.js +48 -0
  60. package/node_modules/@zip.js/zip.js/lib/core/util/decode-text.js +43 -0
  61. package/node_modules/@zip.js/zip.js/lib/core/util/default-mime-type.js +38 -0
  62. package/node_modules/@zip.js/zip.js/lib/core/util/encode-text.js +48 -0
  63. package/node_modules/@zip.js/zip.js/lib/core/util/mime-type.js +1639 -0
  64. package/node_modules/@zip.js/zip.js/lib/core/util/stream-codec-shim.js +91 -0
  65. package/node_modules/@zip.js/zip.js/lib/core/z-worker-core.js +176 -0
  66. package/node_modules/@zip.js/zip.js/lib/core/zip-entry.js +86 -0
  67. package/node_modules/@zip.js/zip.js/lib/core/zip-fs-core.js +865 -0
  68. package/node_modules/@zip.js/zip.js/lib/core/zip-reader.js +757 -0
  69. package/node_modules/@zip.js/zip.js/lib/core/zip-writer.js +1186 -0
  70. package/node_modules/@zip.js/zip.js/lib/z-worker-bootstrap-fflate.js +40 -0
  71. package/node_modules/@zip.js/zip.js/lib/z-worker-bootstrap-pako.js +39 -0
  72. package/node_modules/@zip.js/zip.js/lib/z-worker-fflate.js +40 -0
  73. package/node_modules/@zip.js/zip.js/lib/z-worker-inline-template.js +42 -0
  74. package/node_modules/@zip.js/zip.js/lib/z-worker-inline.js +1 -0
  75. package/node_modules/@zip.js/zip.js/lib/z-worker.js +38 -0
  76. package/node_modules/@zip.js/zip.js/lib/zip-data-uri.js +53 -0
  77. package/node_modules/@zip.js/zip.js/lib/zip-fflate-shim.js +37 -0
  78. package/node_modules/@zip.js/zip.js/lib/zip-fs.js +53 -0
  79. package/node_modules/@zip.js/zip.js/lib/zip-full-fflate.js +53 -0
  80. package/node_modules/@zip.js/zip.js/lib/zip-full.js +54 -0
  81. package/node_modules/@zip.js/zip.js/lib/zip-no-worker-deflate.js +42 -0
  82. package/node_modules/@zip.js/zip.js/lib/zip-no-worker-fflate-deflate.js +42 -0
  83. package/node_modules/@zip.js/zip.js/lib/zip-no-worker-fflate-inflate.js +42 -0
  84. package/node_modules/@zip.js/zip.js/lib/zip-no-worker-fflate.js +43 -0
  85. package/node_modules/@zip.js/zip.js/lib/zip-no-worker-inflate.js +42 -0
  86. package/node_modules/@zip.js/zip.js/lib/zip-no-worker.js +44 -0
  87. package/node_modules/@zip.js/zip.js/lib/zip.js +52 -0
  88. package/node_modules/@zip.js/zip.js/package.json +86 -0
  89. package/package.json +43 -0
  90. package/prisma-gen/default.d.ts +1 -0
  91. package/prisma-gen/default.js +1 -0
  92. package/prisma-gen/edge.d.ts +1 -0
  93. package/prisma-gen/edge.js +242 -0
  94. package/prisma-gen/index-browser.js +236 -0
  95. package/prisma-gen/index.d.ts +13248 -0
  96. package/prisma-gen/index.js +265 -0
  97. package/prisma-gen/runtime/edge-esm.js +28 -0
  98. package/prisma-gen/runtime/edge.js +28 -0
  99. package/prisma-gen/runtime/index-browser.d.ts +365 -0
  100. package/prisma-gen/runtime/index-browser.js +13 -0
  101. package/prisma-gen/runtime/library.d.ts +3168 -0
  102. package/prisma-gen/runtime/library.js +140 -0
  103. package/prisma-gen/runtime/wasm.js +29 -0
  104. package/prisma-gen/wasm.d.ts +1 -0
  105. package/prisma-gen/wasm.js +236 -0
  106. package/s3.d.ts +14 -0
  107. package/s3.js +76 -0
  108. package/schema.prisma +154 -0
  109. package/uploads.d.ts +54 -0
  110. package/uploads.js +141 -0
@@ -0,0 +1,2048 @@
1
+ /**
2
+ * Represents the `FileSystemEntry` class.
3
+ *
4
+ * @see {@link https://wicg.github.io/entries-api/#api-entry|specification}
5
+ */
6
+ // deno-lint-ignore no-empty-interface
7
+ interface FileSystemEntryLike { }
8
+
9
+ /**
10
+ * Represents the `FileSystemHandle` class.
11
+ *
12
+ * @see {@link https://fs.spec.whatwg.org/#api-filesystemhandle}
13
+ */
14
+ // deno-lint-ignore no-empty-interface
15
+ interface FileSystemHandleLike { }
16
+
17
+ /**
18
+ * Represents a generic `TransformStream` class.
19
+ *
20
+ * @see {@link https://streams.spec.whatwg.org/#generictransformstream|specification}
21
+ */
22
+ declare class TransformStreamLike {
23
+ /**
24
+ * The readable stream.
25
+ */
26
+ readable: ReadableStream;
27
+ /**
28
+ * The writable stream.
29
+ */
30
+ writable: WritableStream;
31
+ }
32
+
33
+ /**
34
+ * Configures zip.js
35
+ *
36
+ * @param configuration The configuration.
37
+ */
38
+ export function configure(configuration: Configuration): void;
39
+
40
+ /**
41
+ * Represents the configuration passed to {@link configure}.
42
+ */
43
+ export interface Configuration extends WorkerConfiguration {
44
+ /**
45
+ * The maximum number of web workers used to compress/decompress data simultaneously.
46
+ *
47
+ * @defaultValue `navigator.hardwareConcurrency`
48
+ */
49
+ maxWorkers?: number;
50
+ /**
51
+ * The delay in milliseconds before idle web workers are automatically terminated. You can call `terminateWorkers()` to terminate idle workers.
52
+ *
53
+ * @defaultValue 5000
54
+ */
55
+ terminateWorkerTimeout?: number;
56
+ /**
57
+ * The URIs of the compression/decompression scripts run in web workers.
58
+ *
59
+ * It allows using alternative deflate implementations or specifying a URL to the worker script if the CSP of the page blocks scripts imported from a Blob URI.
60
+ * The properties `deflate` and `inflate` must specify arrays of URLs to import the deflate/inflate web workers, respectively.
61
+ * The first URL is relative to the base URI of the document. The other URLs are relative to the URL of the first script. Scripts in the array are executed in order.
62
+ * If you only use deflation or inflation, the unused `deflate`/`inflate` property can be omitted.
63
+ *
64
+ * Here is an example:
65
+ * ```
66
+ * configure({
67
+ * workerScripts: {
68
+ * deflate: ["library_path/custom-worker.js", "./custom-deflate.js"],
69
+ * inflate: ["library_path/custom-worker.js", "./custom-inflate.js"]
70
+ * }
71
+ * });
72
+ * ```
73
+ *
74
+ * If the CSP of the page blocks scripts imported from a Blob URI you can use `z-worker.js` from https://github.com/gildas-lormeau/zip.js/tree/master/dist and specify the URL where it can be found.
75
+ *
76
+ * Here is an example:
77
+ * ```
78
+ * configure({
79
+ * workerScripts: {
80
+ * deflate: ["library_path/z-worker.js"],
81
+ * inflate: ["library_path/z-worker.js"]
82
+ * }
83
+ * });
84
+ * ```
85
+ */
86
+ workerScripts?: {
87
+ /**
88
+ * The URIs of the scripts implementing used for compression.
89
+ */
90
+ deflate?: string[];
91
+ /**
92
+ * The URIs of the scripts implementing used for decompression.
93
+ */
94
+ inflate?: string[];
95
+ };
96
+ /**
97
+ * The size of the chunks in bytes during data compression/decompression.
98
+ *
99
+ * @defaultValue 524288
100
+ */
101
+ chunkSize?: number;
102
+ /**
103
+ * The codec implementation used to compress data.
104
+ *
105
+ * @defaultValue {@link ZipDeflate}
106
+ */
107
+ Deflate?: typeof ZipDeflate;
108
+ /**
109
+ * The codec implementation used to decompress data.
110
+ *
111
+ * @defaultValue {@link ZipInflate}
112
+ */
113
+ Inflate?: typeof ZipInflate;
114
+ /**
115
+ * The stream implementation used to compress data when `useCompressionStream` is set to `false`.
116
+ *
117
+ * @defaultValue {@link CodecStream}
118
+ */
119
+ CompressionStream?: typeof TransformStreamLike;
120
+ /**
121
+ * The stream implementation used to decompress data when `useCompressionStream` is set to `false`.
122
+ *
123
+ * @defaultValue {@link CodecStream}
124
+ */
125
+ DecompressionStream?: typeof TransformStreamLike;
126
+ }
127
+
128
+ /**
129
+ * Represents configuration passed to {@link configure}, the constructor of {@link ZipReader}, {@link Entry#getData}, the constructor of {@link ZipWriter}, and {@link ZipWriter#add}.
130
+ */
131
+ export interface WorkerConfiguration {
132
+ /**
133
+ * `true` to use web workers to compress/decompress data in non-blocking background processes.
134
+ *
135
+ * @defaultValue true
136
+ */
137
+ useWebWorkers?: boolean;
138
+ /**
139
+ * `true` to use the native API `CompressionStream`/`DecompressionStream` to compress/decompress data.
140
+ *
141
+ * @defaultValue true
142
+ */
143
+ useCompressionStream?: boolean;
144
+ }
145
+
146
+ /**
147
+ * Transforms event-based third-party codec implementations into implementations compatible with zip.js
148
+ *
149
+ * @param library The third-party codec implementations.
150
+ * @param constructorOptions The options passed to the third-party implementations when building instances.
151
+ * @param registerDataHandler The function called to handle the `data` events triggered by a third-party codec implementation.
152
+ * @returns An instance containing classes compatible with {@link ZipDeflate} and {@link ZipInflate}.
153
+ */
154
+ export function initShimAsyncCodec(
155
+ library: EventBasedZipLibrary,
156
+ constructorOptions: unknown | null,
157
+ registerDataHandler: registerDataHandler,
158
+ ): ZipLibrary;
159
+
160
+ /**
161
+ * Represents the callback function used to register the `data` event handler.
162
+ */
163
+ export interface registerDataHandler {
164
+ /**
165
+ * @param codec The third-party codec instance.
166
+ * @param onData The `data` event handler.
167
+ */
168
+ (codec: EventBasedCodec, onData: dataHandler): void;
169
+ }
170
+
171
+ /**
172
+ * Represents the callback function used to handle `data` events.
173
+ */
174
+ export interface dataHandler {
175
+ /**
176
+ * @param data The processed chunk of data.
177
+ */
178
+ (data: Uint8Array): void;
179
+ }
180
+
181
+ /**
182
+ * Terminates all the web workers
183
+ */
184
+ export function terminateWorkers(): Promise<void>;
185
+
186
+ /**
187
+ * Represents event-based implementations used to compress/decompress data.
188
+ */
189
+ export interface EventBasedZipLibrary {
190
+ /**
191
+ * The class used to compress data.
192
+ */
193
+ Deflate: typeof EventBasedCodec;
194
+ /**
195
+ * The class used to decompress data.
196
+ */
197
+ Inflate: typeof EventBasedCodec;
198
+ }
199
+
200
+ /**
201
+ * Represents an event-based implementation of a third-party codec.
202
+ */
203
+ declare class EventBasedCodec {
204
+ /**
205
+ * Appends a chunk of data to compress/decompress
206
+ *
207
+ * @param data The chunk of data to append.
208
+ */
209
+ push(data: Uint8Array): void;
210
+ /**
211
+ * The function called when a chunk of data has been compressed/decompressed.
212
+ *
213
+ * @param data The chunk of compressed/decompressed data.
214
+ */
215
+ ondata(data?: Uint8Array): void;
216
+ }
217
+
218
+ /**
219
+ * Represents the implementations zip.js uses to compress/decompress data.
220
+ */
221
+ export interface ZipLibrary {
222
+ /**
223
+ * The class used to compress data.
224
+ *
225
+ * @defaultValue {@link ZipDeflate}
226
+ */
227
+ Deflate: typeof ZipDeflate;
228
+ /**
229
+ * The class used to decompress data.
230
+ *
231
+ * @defaultValue {@link ZipInflate}
232
+ */
233
+ Inflate: typeof ZipInflate;
234
+ }
235
+
236
+ declare class SyncCodec {
237
+ /**
238
+ * Appends a chunk of decompressed data to compress
239
+ *
240
+ * @param data The chunk of decompressed data to append.
241
+ * @returns A chunk of compressed data.
242
+ */
243
+ append(data: Uint8Array): Uint8Array;
244
+ }
245
+
246
+ /**
247
+ * Represents an instance used to compress data.
248
+ */
249
+ declare class ZipDeflate extends SyncCodec {
250
+ /**
251
+ * Flushes the data
252
+ *
253
+ * @returns A chunk of compressed data.
254
+ */
255
+ flush(): Uint8Array;
256
+ }
257
+
258
+ /**
259
+ * Represents a codec used to decompress data.
260
+ */
261
+ declare class ZipInflate extends SyncCodec {
262
+ /**
263
+ * Flushes the data
264
+ */
265
+ flush(): void;
266
+ }
267
+
268
+ /**
269
+ * Represents a class implementing `CompressionStream` or `DecompressionStream` interfaces.
270
+ */
271
+ declare class CodecStream extends TransformStream { }
272
+
273
+ /**
274
+ * Returns the MIME type corresponding to a filename extension.
275
+ *
276
+ * @param fileExtension the extension of the filename.
277
+ * @returns The corresponding MIME type.
278
+ */
279
+ export function getMimeType(fileExtension: string): string;
280
+
281
+ /**
282
+ * Represents an instance used to read or write unknown type of data.
283
+ *
284
+ * 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}.
285
+ * 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.
286
+ */
287
+ export interface Initializable {
288
+ /**
289
+ * Initializes the instance asynchronously
290
+ */
291
+ init?(): Promise<void>;
292
+ }
293
+
294
+ /**
295
+ * Represents an instance used to read data from a `ReadableStream` instance.
296
+ */
297
+ export interface ReadableReader {
298
+ /**
299
+ * The `ReadableStream` instance.
300
+ */
301
+ readable: ReadableStream;
302
+ }
303
+
304
+ /**
305
+ * Represents an instance used to read unknown type of data.
306
+ *
307
+ * @example
308
+ * Here is an example of custom {@link Reader} class used to read binary strings:
309
+ * ```
310
+ * class BinaryStringReader extends Reader {
311
+ *
312
+ * constructor(binaryString) {
313
+ * super();
314
+ * this.binaryString = binaryString;
315
+ * }
316
+ *
317
+ * init() {
318
+ * super.init();
319
+ * this.size = this.binaryString.length;
320
+ * }
321
+ *
322
+ * readUint8Array(offset, length) {
323
+ * const result = new Uint8Array(length);
324
+ * for (let indexCharacter = 0; indexCharacter < length; indexCharacter++) {
325
+ * result[indexCharacter] = this.binaryString.charCodeAt(indexCharacter + offset) & 0xFF;
326
+ * }
327
+ * return result;
328
+ * }
329
+ * }
330
+ * ```
331
+ */
332
+ export class Reader<Type> implements Initializable, ReadableReader {
333
+ /**
334
+ * Creates the {@link Reader} instance
335
+ *
336
+ * @param value The data to read.
337
+ */
338
+ constructor(value: Type);
339
+ /**
340
+ * The `ReadableStream` instance.
341
+ */
342
+ readable: ReadableStream;
343
+ /**
344
+ * The total size of the data in bytes.
345
+ */
346
+ size: number;
347
+ /**
348
+ * Initializes the instance asynchronously
349
+ */
350
+ init?(): Promise<void>;
351
+ /**
352
+ * Reads a chunk of data
353
+ *
354
+ * @param index The byte index of the data to read.
355
+ * @param length The length of the data to read in bytes.
356
+ * @returns A promise resolving to a chunk of data.
357
+ */
358
+ readUint8Array(index: number, length: number): Promise<Uint8Array>;
359
+ }
360
+
361
+ /**
362
+ * Represents a {@link Reader} instance used to read data provided as a `string`.
363
+ */
364
+ export class TextReader extends Reader<string> { }
365
+
366
+ /**
367
+ * Represents a {@link Reader} instance used to read data provided as a `Blob` instance.
368
+ */
369
+ export class BlobReader extends Reader<Blob> { }
370
+
371
+ /**
372
+ * Represents a {@link Reader} instance used to read data provided as a Data URI `string` encoded in Base64.
373
+ */
374
+ export class Data64URIReader extends Reader<string> { }
375
+
376
+ /**
377
+ * Represents a {@link Reader} instance used to read data provided as a `Uint8Array` instance.
378
+ */
379
+ export class Uint8ArrayReader extends Reader<Uint8Array> { }
380
+
381
+ /**
382
+ * Represents a {@link Reader} instance used to read data provided as an array of {@link ReadableReader} instances (e.g. split zip files).
383
+ *
384
+ * @deprecated Use {@link SplitDataReader} instead.
385
+ */
386
+ export class SplitZipReader extends SplitDataReader { }
387
+
388
+ /**
389
+ * Represents a {@link Reader} instance used to read data provided as an array of {@link ReadableReader} instances (e.g. split zip files).
390
+ */
391
+ export class SplitDataReader
392
+ extends Reader<Reader<unknown>[] | ReadableReader[] | ReadableStream[]> { }
393
+
394
+ /**
395
+ * Represents a URL stored into a `string`.
396
+ */
397
+ // deno-lint-ignore no-empty-interface
398
+ interface URLString extends String { }
399
+
400
+ /**
401
+ * Represents a {@link Reader} instance used to fetch data from a URL.
402
+ */
403
+ export class HttpReader extends Reader<URLString> {
404
+ /**
405
+ * Creates the {@link HttpReader} instance
406
+ *
407
+ * @param url The URL of the data.
408
+ * @param options The options.
409
+ */
410
+ constructor(url: URLString, options?: HttpOptions);
411
+ }
412
+
413
+ /**
414
+ * Represents a {@link Reader} instance used to fetch data from servers returning `Accept-Ranges` headers.
415
+ */
416
+ export class HttpRangeReader extends HttpReader {
417
+ /**
418
+ * Creates the {@link HttpRangeReader} instance
419
+ *
420
+ * @param url The URL of the data.
421
+ * @param options The options.
422
+ */
423
+ constructor(url: URLString, options?: HttpRangeOptions);
424
+ }
425
+
426
+ /**
427
+ * Represents the options passed to the constructor of {@link HttpReader}.
428
+ */
429
+ export interface HttpOptions extends HttpRangeOptions {
430
+ /**
431
+ * `true` to use `Range` headers when fetching data from servers returning `Accept-Ranges` headers.
432
+ *
433
+ * @defaultValue false
434
+ */
435
+ useRangeHeader?: boolean;
436
+ /**
437
+ * `true` to always use `Range` headers when fetching data.
438
+ *
439
+ * @defaultValue false
440
+ */
441
+ forceRangeRequests?: boolean;
442
+ /**
443
+ * `true` to prevent using `HEAD` HTTP request in order the get the size of the content.
444
+ * `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.
445
+ *
446
+ * @defaultValue false
447
+ */
448
+ preventHeadRequest?: boolean;
449
+ /**
450
+ * `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.
451
+ *
452
+ * @defaultValue false
453
+ */
454
+ combineSizeEocd?: boolean;
455
+ }
456
+
457
+ /**
458
+ * Represents options passed to the constructor of {@link HttpRangeReader} and {@link HttpReader}.
459
+ */
460
+ export interface HttpRangeOptions {
461
+ /**
462
+ * `true` to rely `XMLHttpRequest` instead of `fetch` to fetch data.
463
+ *
464
+ * @defaultValue false
465
+ */
466
+ useXHR?: boolean;
467
+ /**
468
+ * The HTTP headers.
469
+ */
470
+ headers?: Iterable<[string, string]> | Map<string, string>;
471
+ }
472
+
473
+ /**
474
+ * Represents an instance used to write data into a `WritableStream` instance.
475
+ */
476
+ export interface WritableWriter {
477
+ /**
478
+ * The `WritableStream` instance.
479
+ */
480
+ writable: WritableStream;
481
+ /**
482
+ * The maximum size of split data when creating a {@link ZipWriter} instance or when calling {@link Entry#getData} with a generator of {@link WritableWriter} instances.
483
+ */
484
+ maxSize?: number;
485
+ }
486
+
487
+ /**
488
+ * Represents an instance used to write unknown type of data.
489
+ *
490
+ * @example
491
+ * Here is an example of custom {@link Writer} class used to write binary strings:
492
+ * ```
493
+ * class BinaryStringWriter extends Writer {
494
+ *
495
+ * constructor() {
496
+ * super();
497
+ * this.binaryString = "";
498
+ * }
499
+ *
500
+ * writeUint8Array(array) {
501
+ * for (let indexCharacter = 0; indexCharacter < array.length; indexCharacter++) {
502
+ * this.binaryString += String.fromCharCode(array[indexCharacter]);
503
+ * }
504
+ * }
505
+ *
506
+ * getData() {
507
+ * return this.binaryString;
508
+ * }
509
+ * }
510
+ * ```
511
+ */
512
+ export class Writer<Type> implements Initializable, WritableWriter {
513
+ /**
514
+ * The `WritableStream` instance.
515
+ */
516
+ writable: WritableStream;
517
+ /**
518
+ * Initializes the instance asynchronously
519
+ *
520
+ * @param size the total size of the written data in bytes.
521
+ */
522
+ init?(size?: number): Promise<void>;
523
+ /**
524
+ * Appends a chunk of data
525
+ *
526
+ * @param array The chunk data to append.
527
+ *
528
+ * @virtual
529
+ */
530
+ writeUint8Array(array: Uint8Array): Promise<void>;
531
+ /**
532
+ * Retrieves all the written data
533
+ *
534
+ * @returns A promise resolving to the written data.
535
+ */
536
+ getData(): Promise<Type>;
537
+ }
538
+
539
+ /**
540
+ * Represents a {@link Writer} instance used to retrieve the written data as a `string`.
541
+ */
542
+ export class TextWriter extends Writer<string> {
543
+ /**
544
+ * Creates the {@link TextWriter} instance
545
+ *
546
+ * @param encoding The encoding of the text.
547
+ */
548
+ constructor(encoding?: string);
549
+ }
550
+
551
+ /**
552
+ * Represents a {@link WritableWriter} instance used to retrieve the written data as a `Blob` instance.
553
+ */
554
+ export class BlobWriter implements Initializable, WritableWriter {
555
+ /**
556
+ * The `WritableStream` instance.
557
+ */
558
+ writable: WritableStream;
559
+ /**
560
+ * Initializes the instance asynchronously
561
+ */
562
+ init(): Promise<void>;
563
+ /**
564
+ * Creates the {@link BlobWriter} instance
565
+ *
566
+ * @param mimeString The MIME type of the content.
567
+ */
568
+ constructor(mimeString?: string);
569
+ /**
570
+ * Retrieves all the written data
571
+ *
572
+ * @returns A promise resolving to the written data.
573
+ */
574
+ getData(): Promise<Blob>;
575
+ }
576
+
577
+ /**
578
+ * Represents a {@link Writer} instance used to retrieve the written data as a Data URI `string` encoded in Base64.
579
+ */
580
+ export class Data64URIWriter extends Writer<string> {
581
+ /**
582
+ * Creates the {@link Data64URIWriter} instance
583
+ *
584
+ * @param mimeString The MIME type of the content.
585
+ */
586
+ constructor(mimeString?: string);
587
+ }
588
+
589
+ /**
590
+ * Represents a {@link Writer} instance used to retrieve the written data from a generator of {@link WritableWriter} instances (i.e. split zip files).
591
+ *
592
+ * @deprecated Use {@link SplitDataWriter} instead.
593
+ */
594
+ export class SplitZipWriter extends SplitDataWriter { }
595
+
596
+ /**
597
+ * Represents a {@link Writer} instance used to retrieve the written data from a generator of {@link WritableWriter} instances (i.e. split zip files).
598
+ */
599
+ export class SplitDataWriter implements Initializable, WritableWriter {
600
+ /**
601
+ * The `WritableStream` instance.
602
+ */
603
+ writable: WritableStream;
604
+ /**
605
+ * Initializes the instance asynchronously
606
+ */
607
+ init(): Promise<void>;
608
+ /**
609
+ * Creates the {@link SplitDataWriter} instance
610
+ *
611
+ * @param writerGenerator A generator of Writer instances.
612
+ * @param maxSize The maximum size of the data written into {@link Writer} instances (default: 4GB).
613
+ */
614
+ constructor(
615
+ writerGenerator: AsyncGenerator<
616
+ Writer<unknown> | WritableWriter | WritableStream,
617
+ boolean
618
+ >,
619
+ maxSize?: number,
620
+ );
621
+ }
622
+
623
+ /**
624
+ * Represents a {@link Writer} instance used to retrieve the written data as a `Uint8Array` instance.
625
+ */
626
+ export class Uint8ArrayWriter extends Writer<Uint8Array> { }
627
+
628
+ /**
629
+ * Represents an instance used to create an unzipped stream.
630
+ *
631
+ * @example
632
+ * This example will take a zip file, decompress it and then save its files and directories to disk.
633
+ * ```
634
+ * import {resolve} from "https://deno.land/std/path/mod.ts";
635
+ * import {ensureDir, ensureFile} from "https://deno.land/std/fs/mod.ts";
636
+ *
637
+ * for await (const entry of (await fetch(urlToZippedFile)).body.pipeThrough(new ZipReaderStream())) {
638
+ * const fullPath = resolve(destination, entry.filename);
639
+ * if (entry.directory) {
640
+ * await ensureDir(fullPath);
641
+ * continue;
642
+ * }
643
+ *
644
+ * await ensureFile(fullPath);
645
+ * await entry.readable?.pipeTo((await Deno.create(fullPath)).writable);
646
+ * }
647
+ * ```
648
+ */
649
+ export class ZipReaderStream<T> {
650
+ /**
651
+ * Creates the stream.
652
+ *
653
+ * @param options The options.
654
+ */
655
+ constructor(options?: ZipReaderConstructorOptions);
656
+
657
+ /**
658
+ * The readable stream.
659
+ */
660
+ readable: ReadableStream<
661
+ Omit<Entry, "getData"> & { readable?: ReadableStream<Uint8Array> }
662
+ >;
663
+
664
+ /**
665
+ * The writable stream.
666
+ */
667
+ writable: WritableStream<T>;
668
+ }
669
+
670
+ /**
671
+ * Represents an instance used to read a zip file.
672
+ *
673
+ * @example
674
+ * Here is an example showing how to read the text data of the first entry from a zip file:
675
+ * ```
676
+ * // create a BlobReader to read with a ZipReader the zip from a Blob object
677
+ * const reader = new zip.ZipReader(new zip.BlobReader(blob));
678
+ *
679
+ * // get all entries from the zip
680
+ * const entries = await reader.getEntries();
681
+ * if (entries.length) {
682
+ *
683
+ * // get first entry content as text by using a TextWriter
684
+ * const text = await entries[0].getData(
685
+ * // writer
686
+ * new zip.TextWriter(),
687
+ * // options
688
+ * {
689
+ * onprogress: (index, max) => {
690
+ * // onprogress callback
691
+ * }
692
+ * }
693
+ * );
694
+ * // text contains the entry data as a String
695
+ * console.log(text);
696
+ * }
697
+ *
698
+ * // close the ZipReader
699
+ * await reader.close();
700
+ * ```
701
+ */
702
+ export class ZipReader<Type> {
703
+ /**
704
+ * Creates the instance
705
+ *
706
+ * @param reader The {@link Reader} instance used to read data.
707
+ * @param options The options.
708
+ */
709
+ constructor(
710
+ reader:
711
+ | Reader<Type>
712
+ | ReadableReader
713
+ | ReadableStream
714
+ | Reader<unknown>[]
715
+ | ReadableReader[]
716
+ | ReadableStream[],
717
+ options?: ZipReaderConstructorOptions,
718
+ );
719
+ /**
720
+ * The global comment of the zip file.
721
+ */
722
+ comment: Uint8Array;
723
+ /**
724
+ * The data prepended before the zip file.
725
+ */
726
+ prependedData?: Uint8Array;
727
+ /**
728
+ * The data appended after the zip file.
729
+ */
730
+ appendedData?: Uint8Array;
731
+ /**
732
+ * Returns all the entries in the zip file
733
+ *
734
+ * @param options The options.
735
+ * @returns A promise resolving to an `array` of {@link Entry} instances.
736
+ */
737
+ getEntries(options?: ZipReaderGetEntriesOptions): Promise<Entry[]>;
738
+ /**
739
+ * Returns a generator used to iterate on all the entries in the zip file
740
+ *
741
+ * @param options The options.
742
+ * @returns An asynchronous generator of {@link Entry} instances.
743
+ */
744
+ getEntriesGenerator(
745
+ options?: ZipReaderGetEntriesOptions,
746
+ ): AsyncGenerator<Entry, boolean>;
747
+ /**
748
+ * Closes the zip file
749
+ */
750
+ close(): Promise<void>;
751
+ }
752
+
753
+ /**
754
+ * Represents the options passed to the constructor of {@link ZipReader}, and `{@link ZipDirectory}#import*`.
755
+ */
756
+ export interface ZipReaderConstructorOptions
757
+ extends ZipReaderOptions, GetEntriesOptions, WorkerConfiguration {
758
+ /**
759
+ * `true` to extract the prepended data into {@link ZipReader#prependedData}.
760
+ *
761
+ * @defaultValue false
762
+ */
763
+ extractPrependedData?: boolean;
764
+ /**
765
+ * `true` to extract the appended data into {@link ZipReader#appendedData}.
766
+ *
767
+ * @defaultValue false
768
+ */
769
+ extractAppendedData?: boolean;
770
+ }
771
+
772
+ /**
773
+ * Represents the options passed to {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
774
+ */
775
+ export interface ZipReaderGetEntriesOptions
776
+ extends GetEntriesOptions, EntryOnprogressOptions { }
777
+
778
+ /**
779
+ * Represents options passed to the constructor of {@link ZipReader}, {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
780
+ */
781
+ export interface GetEntriesOptions {
782
+ /**
783
+ * The encoding of the filename of the entry.
784
+ */
785
+ filenameEncoding?: string;
786
+ /**
787
+ * The encoding of the comment of the entry.
788
+ */
789
+ commentEncoding?: string;
790
+ /**
791
+ * Decodes the filename and the comment of the entry.
792
+ *
793
+ * @param value The raw text value.
794
+ * @param encoding The encoding of the text.
795
+ * @returns The decoded text value or `undefined` if the raw text value should be decoded by zip.js.
796
+ */
797
+ decodeText?(value: Uint8Array, encoding: string): string | undefined;
798
+ }
799
+
800
+ /**
801
+ * Represents options passed to the constructor of {@link ZipReader} and {@link Entry#getData}.
802
+ */
803
+ export interface ZipReaderCheckPasswordOptions {
804
+ /**
805
+ * `true` to check only if the password is valid.
806
+ *
807
+ * @defaultValue false
808
+ */
809
+ checkPasswordOnly: boolean;
810
+ }
811
+
812
+ /**
813
+ * Represents options passed to the constructor of {@link ZipReader} and {@link Entry#getData}.
814
+ */
815
+ export interface ZipReaderOptions {
816
+ /**
817
+ * `true` to check the signature of the entry.
818
+ *
819
+ * @defaultValue false
820
+ */
821
+ checkSignature?: boolean;
822
+ /**
823
+ * The password used to decrypt the content of the entry.
824
+ */
825
+ password?: string;
826
+ /**
827
+ * The password used to encrypt the content of the entry (raw).
828
+ */
829
+ rawPassword?: Uint8Array;
830
+ /**
831
+ * The `AbortSignal` instance used to cancel the decompression.
832
+ */
833
+ signal?: AbortSignal;
834
+ /**
835
+ * `true` to prevent closing of {@link Writer#writable} when calling {@link Entry#getData}.
836
+ *
837
+ * @defaultValue false
838
+ */
839
+ preventClose?: boolean;
840
+ /**
841
+ * `true` to transfer streams to web workers when decompressing data.
842
+ *
843
+ * @defaultValue true
844
+ */
845
+ transferStreams?: boolean;
846
+ }
847
+
848
+ /**
849
+ * Represents the metadata of an entry in a zip file (Core API).
850
+ */
851
+ export interface EntryMetaData {
852
+ /**
853
+ * The byte offset of the entry.
854
+ */
855
+ offset: number;
856
+ /**
857
+ * The filename of the entry.
858
+ */
859
+ filename: string;
860
+ /**
861
+ * The filename of the entry (raw).
862
+ */
863
+ rawFilename: Uint8Array;
864
+ /**
865
+ * `true` if the filename is encoded in UTF-8.
866
+ */
867
+ filenameUTF8: boolean;
868
+ /**
869
+ * `true` if the entry is a directory.
870
+ */
871
+ directory: boolean;
872
+ /**
873
+ * `true` if the content of the entry is encrypted.
874
+ */
875
+ encrypted: boolean;
876
+ /**
877
+ * The size of the compressed data in bytes.
878
+ */
879
+ compressedSize: number;
880
+ /**
881
+ * The size of the decompressed data in bytes.
882
+ */
883
+ uncompressedSize: number;
884
+ /**
885
+ * The last modification date.
886
+ */
887
+ lastModDate: Date;
888
+ /**
889
+ * The last access date.
890
+ */
891
+ lastAccessDate?: Date;
892
+ /**
893
+ * The creation date.
894
+ */
895
+ creationDate?: Date;
896
+ /**
897
+ * The last modification date (raw).
898
+ */
899
+ rawLastModDate: number | bigint;
900
+ /**
901
+ * The last access date (raw).
902
+ */
903
+ rawLastAccessDate?: number | bigint;
904
+ /**
905
+ * The creation date (raw).
906
+ */
907
+ rawCreationDate?: number | bigint;
908
+ /**
909
+ * The comment of the entry.
910
+ */
911
+ comment: string;
912
+ /**
913
+ * The comment of the entry (raw).
914
+ */
915
+ rawComment: Uint8Array;
916
+ /**
917
+ * `true` if the comment is encoded in UTF-8.
918
+ */
919
+ commentUTF8: boolean;
920
+ /**
921
+ * The signature (CRC32 checksum) of the content.
922
+ */
923
+ signature: number;
924
+ /**
925
+ * The extra field.
926
+ */
927
+ extraField?: Map<number, Uint8Array>;
928
+ /**
929
+ * The extra field (raw).
930
+ */
931
+ rawExtraField: Uint8Array;
932
+ /**
933
+ * `true` if the entry is using Zip64.
934
+ */
935
+ zip64: boolean;
936
+ /**
937
+ * The "Version" field.
938
+ */
939
+ version: number;
940
+ /**
941
+ * The "Version made by" field.
942
+ */
943
+ versionMadeBy: number;
944
+ /**
945
+ * `true` if `internalFileAttribute` and `externalFileAttribute` are compatible with MS-DOS format.
946
+ */
947
+ msDosCompatible: boolean;
948
+ /**
949
+ * The internal file attribute (raw).
950
+ */
951
+ internalFileAttribute: number;
952
+ /**
953
+ * The external file attribute (raw).
954
+ */
955
+ externalFileAttribute: number;
956
+ /**
957
+ * The number of the disk where the entry data starts.
958
+ */
959
+ diskNumberStart: number;
960
+ }
961
+
962
+ /**
963
+ * Represents an entry with its data and metadata in a zip file (Core API).
964
+ */
965
+ export interface Entry extends EntryMetaData {
966
+ /**
967
+ * Returns the content of the entry
968
+ *
969
+ * @param writer The {@link Writer} instance used to write the content of the entry.
970
+ * @param options The options.
971
+ * @returns A promise resolving to the type to data associated to `writer`.
972
+ */
973
+ getData?<Type>(
974
+ writer:
975
+ | Writer<Type>
976
+ | WritableWriter
977
+ | WritableStream
978
+ | AsyncGenerator<
979
+ Writer<unknown> | WritableWriter | WritableStream,
980
+ boolean
981
+ >,
982
+ options?: EntryGetDataOptions,
983
+ ): Promise<Type>;
984
+
985
+ /**
986
+ * Tests if the password is valid.
987
+ *
988
+ * @param writer `undefined` or `null`.
989
+ * @param options The options with `checkPasswordOnly` set to `true`.
990
+ */
991
+ getData?(
992
+ writer: undefined | null,
993
+ options: EntryGetDataCheckPasswordOptions,
994
+ ): Promise<void>;
995
+ }
996
+
997
+ /**
998
+ * Represents the options passed to {@link Entry#getData} and `{@link ZipFileEntry}.get*`.
999
+ */
1000
+ export interface EntryGetDataOptions
1001
+ extends EntryDataOnprogressOptions, ZipReaderOptions, WorkerConfiguration { }
1002
+
1003
+ /**
1004
+ * Represents the options passed to {@link Entry#getData} and `{@link ZipFileEntry}.get*`.
1005
+ */
1006
+ export interface EntryGetDataCheckPasswordOptions
1007
+ extends EntryGetDataOptions, ZipReaderCheckPasswordOptions { }
1008
+
1009
+ /**
1010
+ * Represents an instance used to create a zipped stream.
1011
+ *
1012
+ * @example
1013
+ * This example creates a zipped file called numbers.txt.zip containing the numbers 0 - 1000 each on their own line.
1014
+ * ```
1015
+ * const readable = ReadableStream.from((function* () {
1016
+ * for (let i = 0; i < 1000; ++i)
1017
+ * yield i + '\n'
1018
+ * })())
1019
+ *
1020
+ * readable
1021
+ * .pipeThrough(new ZipWriterStream().transform('numbers.txt'))
1022
+ * .pipeTo((await Deno.create('numbers.txt.zip')).writable)
1023
+ * ```
1024
+ *
1025
+ * @example
1026
+ * This example creates a zipped file called Archive.zip containing two files called numbers.txt and letters.txt
1027
+ * ```
1028
+ * const readable1 = ReadableStream.from((function* () {
1029
+ * for (let i = 0; i < 1000; ++i)
1030
+ * yield i + '\n'
1031
+ * })())
1032
+ * const readable2 = ReadableStream.from((function* () {
1033
+ * const letters = 'abcdefghijklmnopqrstuvwxyz'.split('')
1034
+ * while (letters.length)
1035
+ * yield letters.shift() + '\n'
1036
+ * })())
1037
+ *
1038
+ * const zipper = new ZipWriterStream()
1039
+ * zipper.readable.pipeTo((await Deno.create('Archive.zip')).writable)
1040
+ * readable1.pipeTo(zipper.writable('numbers.txt'))
1041
+ * readable2.pipeTo(zipper.writable('letters.txt'))
1042
+ * zipper.close()
1043
+ * ```
1044
+ */
1045
+ export class ZipWriterStream {
1046
+ /**
1047
+ * Creates the stream.
1048
+ *
1049
+ * @param options The options.
1050
+ */
1051
+ constructor(options?: ZipWriterConstructorOptions);
1052
+
1053
+ /**
1054
+ * The readable stream.
1055
+ */
1056
+ readable: ReadableStream<Uint8Array>;
1057
+
1058
+ /**
1059
+ * The ZipWriter property.
1060
+ */
1061
+ zipWriter: ZipWriter<unknown>;
1062
+
1063
+ /**
1064
+ * Returns an object containing a readable and writable property for the .pipeThrough method
1065
+ *
1066
+ * @param path The name of the stream when unzipped.
1067
+ * @returns An object containing readable and writable properties
1068
+ */
1069
+ transform<T>(
1070
+ path: string,
1071
+ ): { readable: ReadableStream<T>; writable: WritableStream<T> };
1072
+
1073
+ /**
1074
+ * Returns a WritableStream for the .pipeTo method
1075
+ *
1076
+ * @param path The directory path of where the stream should exist in the zipped stream.
1077
+ * @returns A WritableStream.
1078
+ */
1079
+ writable<T>(path: string): WritableStream<T>;
1080
+
1081
+ /**
1082
+ * Writes the entries directory, writes the global comment, and returns the content of the zipped file.
1083
+ *
1084
+ * @param comment The global comment of the zip file.
1085
+ * @param options The options.
1086
+ * @returns The content of the zip file.
1087
+ */
1088
+ close(
1089
+ comment?: Uint8Array,
1090
+ options?: ZipWriterCloseOptions,
1091
+ ): Promise<unknown>;
1092
+ }
1093
+
1094
+ /**
1095
+ * Represents an instance used to create a zip file.
1096
+ *
1097
+ * @example
1098
+ * Here is an example showing how to create a zip file containing a compressed text file:
1099
+ * ```
1100
+ * // use a BlobWriter to store with a ZipWriter the zip into a Blob object
1101
+ * const blobWriter = new zip.BlobWriter("application/zip");
1102
+ * const writer = new zip.ZipWriter(blobWriter);
1103
+ *
1104
+ * // use a TextReader to read the String to add
1105
+ * await writer.add("filename.txt", new zip.TextReader("test!"));
1106
+ *
1107
+ * // close the ZipReader
1108
+ * await writer.close();
1109
+ *
1110
+ * // get the zip file as a Blob
1111
+ * const blob = await blobWriter.getData();
1112
+ * ```
1113
+ */
1114
+ export class ZipWriter<Type> {
1115
+ /**
1116
+ * Creates the {@link ZipWriter} instance
1117
+ *
1118
+ * @param writer The {@link Writer} instance where the zip content will be written.
1119
+ * @param options The options.
1120
+ */
1121
+ constructor(
1122
+ writer:
1123
+ | Writer<Type>
1124
+ | WritableWriter
1125
+ | WritableStream
1126
+ | AsyncGenerator<
1127
+ Writer<unknown> | WritableWriter | WritableStream,
1128
+ boolean
1129
+ >,
1130
+ options?: ZipWriterConstructorOptions,
1131
+ );
1132
+ /**
1133
+ * `true` if the zip contains at least one entry that has been partially written.
1134
+ */
1135
+ readonly hasCorruptedEntries?: boolean;
1136
+ /**
1137
+ * Adds an entry into the zip file
1138
+ *
1139
+ * @param filename The filename of the entry.
1140
+ * @param reader The {@link Reader} instance used to read the content of the entry.
1141
+ * @param options The options.
1142
+ * @returns A promise resolving to an {@link EntryMetaData} instance.
1143
+ */
1144
+ add<ReaderType>(
1145
+ filename: string,
1146
+ reader?:
1147
+ | Reader<ReaderType>
1148
+ | ReadableReader
1149
+ | ReadableStream
1150
+ | Reader<unknown>[]
1151
+ | ReadableReader[]
1152
+ | ReadableStream[],
1153
+ options?: ZipWriterAddDataOptions,
1154
+ ): Promise<EntryMetaData>;
1155
+ /**
1156
+ * Writes the entries directory, writes the global comment, and returns the content of the zip file
1157
+ *
1158
+ * @param comment The global comment of the zip file.
1159
+ * @param options The options.
1160
+ * @returns The content of the zip file.
1161
+ */
1162
+ close(comment?: Uint8Array, options?: ZipWriterCloseOptions): Promise<Type>;
1163
+ }
1164
+
1165
+ /**
1166
+ * Represents the options passed to {@link ZipWriter#add}.
1167
+ */
1168
+ export interface ZipWriterAddDataOptions
1169
+ extends
1170
+ ZipWriterConstructorOptions,
1171
+ EntryDataOnprogressOptions,
1172
+ WorkerConfiguration {
1173
+ /**
1174
+ * `true` if the entry is a directory.
1175
+ *
1176
+ * @defaultValue false
1177
+ */
1178
+ directory?: boolean;
1179
+ /**
1180
+ * The comment of the entry.
1181
+ */
1182
+ comment?: string;
1183
+ /**
1184
+ * The extra field of the entry.
1185
+ */
1186
+ extraField?: Map<number, Uint8Array>;
1187
+ }
1188
+
1189
+ /**
1190
+ * Represents the options passed to {@link ZipWriter#close}.
1191
+ */
1192
+ export interface ZipWriterCloseOptions extends EntryOnprogressOptions {
1193
+ /**
1194
+ * `true` to use Zip64 to write the entries directory.
1195
+ *
1196
+ * @defaultValue false
1197
+ */
1198
+ zip64?: boolean;
1199
+ /**
1200
+ * `true` to prevent closing of {@link WritableWriter#writable}.
1201
+ *
1202
+ * @defaultValue false
1203
+ */
1204
+ preventClose?: boolean;
1205
+ }
1206
+
1207
+ /**
1208
+ * Represents options passed to the constructor of {@link ZipWriter}, {@link ZipWriter#add} and `{@link ZipDirectoryEntry}#export*`.
1209
+ */
1210
+ export interface ZipWriterConstructorOptions {
1211
+ /**
1212
+ * `true` to use Zip64 to store the entry.
1213
+ *
1214
+ * `zip64` is automatically set to `true` when necessary (e.g. compressed data larger than 4GB or with unknown size).
1215
+ *
1216
+ * @defaultValue false
1217
+ */
1218
+ zip64?: boolean;
1219
+ /**
1220
+ * `true` to prevent closing of {@link WritableWriter#writable}.
1221
+ *
1222
+ * @defaultValue false
1223
+ */
1224
+ preventClose?: boolean;
1225
+ /**
1226
+ * The level of compression.
1227
+ *
1228
+ * The minimum value is 0 and means that no compression is applied. The maximum value is 9.
1229
+ *
1230
+ * @defaultValue 5
1231
+ */
1232
+ level?: number;
1233
+ /**
1234
+ * `true` to write entry data in a buffer before appending it to the zip file.
1235
+ *
1236
+ * `bufferedWrite` is automatically set to `true` when compressing more than one entry in parallel.
1237
+ *
1238
+ * @defaultValue false
1239
+ */
1240
+ bufferedWrite?: boolean;
1241
+ /**
1242
+ * `true` to keep the order of the entry physically in the zip file.
1243
+ *
1244
+ * When set to `true`, the use of web workers will be improved. However, it also prevents files larger than 4GB from being created without setting the `zip64` option to `true` explicitly.
1245
+ * Another solution to improve the use of web workers is to add entries from smallest to largest in uncompressed size.
1246
+ *
1247
+ * @defaultValue true
1248
+ */
1249
+ keepOrder?: boolean;
1250
+ /**
1251
+ * The password used to encrypt the content of the entry.
1252
+ */
1253
+ password?: string;
1254
+ /**
1255
+ * The password used to encrypt the content of the entry (raw).
1256
+ */
1257
+ rawPassword?: Uint8Array;
1258
+ /**
1259
+ * The encryption strength (AES).
1260
+ *
1261
+ * @defaultValue 3
1262
+ */
1263
+ encryptionStrength?: 1 | 2 | 3;
1264
+ /**
1265
+ * The `AbortSignal` instance used to cancel the compression.
1266
+ */
1267
+ signal?: AbortSignal;
1268
+ /**
1269
+ * The last modification date.
1270
+ *
1271
+ * @defaultValue The current date.
1272
+ */
1273
+ lastModDate?: Date;
1274
+ /**
1275
+ * The last access date.
1276
+ *
1277
+ * This option is ignored if the {@link ZipWriterConstructorOptions#extendedTimestamp} option is set to `false`.
1278
+ *
1279
+ * @defaultValue The current date.
1280
+ */
1281
+ lastAccessDate?: Date;
1282
+ /**
1283
+ * The creation date.
1284
+ *
1285
+ * This option is ignored if the {@link ZipWriterConstructorOptions#extendedTimestamp} option is set to `false`.
1286
+ *
1287
+ * @defaultValue The current date.
1288
+ */
1289
+ creationDate?: Date;
1290
+ /**
1291
+ * `true` to store extended timestamp extra fields.
1292
+ *
1293
+ * When set to `false`, the maximum last modification date cannot exceed November 31, 2107 and the maximum accuracy is 2 seconds.
1294
+ *
1295
+ * @defaultValue true
1296
+ */
1297
+ extendedTimestamp?: boolean;
1298
+ /**
1299
+ * `true` to use the ZipCrypto algorithm to encrypt the content of the entry.
1300
+ *
1301
+ * It is not recommended to set `zipCrypto` to `true` because the ZipCrypto encryption can be easily broken.
1302
+ *
1303
+ * @defaultValue false
1304
+ */
1305
+ zipCrypto?: boolean;
1306
+ /**
1307
+ * The "Version" field.
1308
+ */
1309
+ version?: number;
1310
+ /**
1311
+ * The "Version made by" field.
1312
+ *
1313
+ * @defaultValue 20
1314
+ */
1315
+ versionMadeBy?: number;
1316
+ /**
1317
+ * `true` to to add a data descriptor.
1318
+ *
1319
+ * When set to `false`, the {@link ZipWriterConstructorOptions#bufferedWrite} option will automatically be set to `true`.
1320
+ *
1321
+ * @defaultValue true
1322
+ */
1323
+ dataDescriptor?: boolean;
1324
+ /**
1325
+ * `true` to add the signature of the data descriptor.
1326
+ *
1327
+ * @defaultValue false
1328
+ */
1329
+ dataDescriptorSignature?: boolean;
1330
+ /**
1331
+ * `true` to write {@link EntryMetaData#externalFileAttribute} in MS-DOS format for folder entries.
1332
+ *
1333
+ * @defaultValue true
1334
+ */
1335
+ msDosCompatible?: boolean;
1336
+ /**
1337
+ * The external file attribute.
1338
+ *
1339
+ * @defaultValue 0
1340
+ */
1341
+ externalFileAttribute?: number;
1342
+ /**
1343
+ * The internal file attribute.
1344
+ *
1345
+ * @defaultValue 0
1346
+ */
1347
+ internalFileAttribute?: number;
1348
+ /**
1349
+ * `false` to never write disk numbers in zip64 data.
1350
+ *
1351
+ * @defaultValue true
1352
+ */
1353
+ supportZip64SplitFile?: boolean;
1354
+ /**
1355
+ * `true`to produce zip files compatible with the USDZ specification.
1356
+ *
1357
+ * @defaultValue false
1358
+ */
1359
+ usdz?: boolean;
1360
+ /**
1361
+ * Encode the filename and the comment of the entry.
1362
+ *
1363
+ * @param text The text to encode.
1364
+ * @returns The encoded text or `undefined` if the text should be encoded by zip.js.
1365
+ */
1366
+ encodeText?(text: string): Uint8Array | undefined;
1367
+ }
1368
+
1369
+ /**
1370
+ * Represents options passed to {@link Entry#getData}, {@link ZipWriter.add} and `{@link ZipDirectory}.export*`.
1371
+ */
1372
+ export interface EntryDataOnprogressOptions {
1373
+ /**
1374
+ * The function called when starting compression/decompression.
1375
+ *
1376
+ * @param total The total number of bytes.
1377
+ * @returns An empty promise or `undefined`.
1378
+ */
1379
+ onstart?(total: number): Promise<void> | undefined;
1380
+ /**
1381
+ * The function called during compression/decompression.
1382
+ *
1383
+ * @param progress The current progress in bytes.
1384
+ * @param total The total number of bytes.
1385
+ * @returns An empty promise or `undefined`.
1386
+ */
1387
+ onprogress?(progress: number, total: number): Promise<void> | undefined;
1388
+ /**
1389
+ * The function called when ending compression/decompression.
1390
+ *
1391
+ * @param computedSize The total number of bytes (computed).
1392
+ * @returns An empty promise or `undefined`.
1393
+ */
1394
+ onend?(computedSize: number): Promise<void> | undefined;
1395
+ }
1396
+
1397
+ /**
1398
+ * Represents options passed to {@link ZipReader#getEntries}, {@link ZipReader#getEntriesGenerator}, and {@link ZipWriter#close}.
1399
+ */
1400
+ export interface EntryOnprogressOptions {
1401
+ /**
1402
+ * The function called each time an entry is read/written.
1403
+ *
1404
+ * @param progress The entry index.
1405
+ * @param total The total number of entries.
1406
+ * @param entry The entry being read/written.
1407
+ * @returns An empty promise or `undefined`.
1408
+ */
1409
+ onprogress?(
1410
+ progress: number,
1411
+ total: number,
1412
+ entry: EntryMetaData,
1413
+ ): Promise<void> | undefined;
1414
+ }
1415
+
1416
+ /**
1417
+ * Represents an entry in a zip file (Filesystem API).
1418
+ */
1419
+ declare class ZipEntry {
1420
+ /**
1421
+ * The relative filename of the entry.
1422
+ */
1423
+ name: string;
1424
+ /**
1425
+ * The underlying {@link EntryMetaData} instance.
1426
+ */
1427
+ data?: EntryMetaData;
1428
+ /**
1429
+ * The ID of the instance.
1430
+ */
1431
+ id: number;
1432
+ /**
1433
+ * The parent directory of the entry.
1434
+ */
1435
+ parent?: ZipEntry;
1436
+ /**
1437
+ * The uncompressed size of the content.
1438
+ */
1439
+ uncompressedSize: number;
1440
+ /**
1441
+ * The children of the entry.
1442
+ */
1443
+ children: ZipEntry[];
1444
+ /**
1445
+ * Clones the entry
1446
+ *
1447
+ * @param deepClone `true` to clone all the descendants.
1448
+ */
1449
+ clone(deepClone?: boolean): ZipEntry;
1450
+ /**
1451
+ * Returns the full filename of the entry
1452
+ */
1453
+ getFullname(): string;
1454
+ /**
1455
+ * Returns the filename of the entry relative to a parent directory
1456
+ */
1457
+ getRelativeName(ancestor: ZipDirectoryEntry): string;
1458
+ /**
1459
+ * Tests if a {@link ZipDirectoryEntry} instance is an ancestor of the entry
1460
+ *
1461
+ * @param ancestor The {@link ZipDirectoryEntry} instance.
1462
+ */
1463
+ isDescendantOf(ancestor: ZipDirectoryEntry): boolean;
1464
+ /**
1465
+ * Tests if the entry or any of its children is password protected
1466
+ */
1467
+ isPasswordProtected(): boolean;
1468
+ /**
1469
+ * Tests the password on the entry and all children if any, returns `true` if the entry is not password protected
1470
+ */
1471
+ checkPassword(
1472
+ password: string,
1473
+ options?: EntryGetDataOptions,
1474
+ ): Promise<boolean>;
1475
+ /**
1476
+ * Set the name of the entry
1477
+ *
1478
+ * @param name The new name of the entry.
1479
+ */
1480
+ rename(name: string): void;
1481
+ }
1482
+
1483
+ /**
1484
+ * Represents a file entry in the zip (Filesystem API).
1485
+ */
1486
+ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
1487
+ /**
1488
+ * `void` for {@link ZipFileEntry} instances.
1489
+ */
1490
+ directory: void;
1491
+ /**
1492
+ * The {@link Reader} instance used to read the content of the entry.
1493
+ */
1494
+ reader:
1495
+ | Reader<ReaderType>
1496
+ | ReadableReader
1497
+ | ReadableStream
1498
+ | Reader<unknown>[]
1499
+ | ReadableReader[]
1500
+ | ReadableStream[];
1501
+ /**
1502
+ * The {@link Writer} instance used to write the content of the entry.
1503
+ */
1504
+ writer:
1505
+ | Writer<WriterType>
1506
+ | WritableWriter
1507
+ | WritableStream
1508
+ | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>;
1509
+ /**
1510
+ * Retrieves the text content of the entry as a `string`
1511
+ *
1512
+ * @param encoding The encoding of the text.
1513
+ * @param options The options.
1514
+ * @returns A promise resolving to a `string`.
1515
+ */
1516
+ getText(encoding?: string, options?: EntryGetDataOptions): Promise<string>;
1517
+ /**
1518
+ * Retrieves the content of the entry as a `Blob` instance
1519
+ *
1520
+ * @param mimeType The MIME type of the content.
1521
+ * @param options The options.
1522
+ * @returns A promise resolving to a `Blob` instance.
1523
+ */
1524
+ getBlob(mimeType?: string, options?: EntryGetDataOptions): Promise<Blob>;
1525
+ /**
1526
+ * Retrieves the content of the entry as as a Data URI `string` encoded in Base64
1527
+ *
1528
+ * @param mimeType The MIME type of the content.
1529
+ * @param options The options.
1530
+ * @returns A promise resolving to a Data URI `string` encoded in Base64.
1531
+ */
1532
+ getData64URI(
1533
+ mimeType?: string,
1534
+ options?: EntryGetDataOptions,
1535
+ ): Promise<string>;
1536
+ /**
1537
+ * Retrieves the content of the entry as a `Uint8Array` instance
1538
+ *
1539
+ * @param options The options.
1540
+ * @returns A promise resolving to a `Uint8Array` instance.
1541
+ */
1542
+ getUint8Array(options?: EntryGetDataOptions): Promise<Uint8Array>;
1543
+ /**
1544
+ * Retrieves the content of the entry via a `WritableStream` instance
1545
+ *
1546
+ * @param writable The `WritableStream` instance.
1547
+ * @param options The options.
1548
+ * @returns A promise resolving to the `WritableStream` instance.
1549
+ */
1550
+ getWritable(
1551
+ writable?: WritableStream,
1552
+ options?: EntryGetDataOptions,
1553
+ ): Promise<WritableStream>;
1554
+ /**
1555
+ * Retrieves the content of the entry via a {@link Writer} instance
1556
+ *
1557
+ * @param writer The {@link Writer} instance.
1558
+ * @param options The options.
1559
+ * @returns A promise resolving to data associated to the {@link Writer} instance.
1560
+ */
1561
+ getData(
1562
+ writer:
1563
+ | Writer<unknown>
1564
+ | WritableWriter
1565
+ | WritableStream
1566
+ | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>,
1567
+ options?: EntryGetDataOptions,
1568
+ ): Promise<unknown>;
1569
+ /**
1570
+ * Replaces the content of the entry with a `Blob` instance
1571
+ *
1572
+ * @param blob The `Blob` instance.
1573
+ */
1574
+ replaceBlob(blob: Blob): void;
1575
+ /**
1576
+ * Replaces the content of the entry with a `string`
1577
+ *
1578
+ * @param text The `string`.
1579
+ */
1580
+ replaceText(text: string): void;
1581
+ /**
1582
+ * Replaces the content of the entry with a Data URI `string` encoded in Base64
1583
+ *
1584
+ * @param dataURI The Data URI `string` encoded in Base64.
1585
+ */
1586
+ replaceData64URI(dataURI: string): void;
1587
+ /**
1588
+ * Replaces the content of the entry with a `Uint8Array` instance
1589
+ *
1590
+ * @param array The `Uint8Array` instance.
1591
+ */
1592
+ replaceUint8Array(array: Uint8Array): void;
1593
+ /**
1594
+ * Replaces the content of the entry with a `ReadableStream` instance
1595
+ *
1596
+ * @param readable The `ReadableStream` instance.
1597
+ */
1598
+ replaceReadable(readable: ReadableStream): void;
1599
+ }
1600
+
1601
+ /**
1602
+ * Represents a directory entry in the zip (Filesystem API).
1603
+ */
1604
+ export class ZipDirectoryEntry extends ZipEntry {
1605
+ /**
1606
+ * `true` for {@link ZipDirectoryEntry} instances.
1607
+ */
1608
+ directory: true;
1609
+ /**
1610
+ * Gets a {@link ZipEntry} child instance from its relative filename
1611
+ *
1612
+ * @param name The relative filename.
1613
+ * @returns A {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance (use the {@link ZipFileEntry#directory} and {@link ZipDirectoryEntry#directory} properties to differentiate entries).
1614
+ */
1615
+ getChildByName(name: string): ZipEntry | undefined;
1616
+ /**
1617
+ * Adds a directory
1618
+ *
1619
+ * @param name The relative filename of the directory.
1620
+ * @param options The options.
1621
+ * @returns A {@link ZipDirectoryEntry} instance.
1622
+ */
1623
+ addDirectory(
1624
+ name: string,
1625
+ options?: ZipWriterAddDataOptions,
1626
+ ): ZipDirectoryEntry;
1627
+ /**
1628
+ * Adds an entry with content provided as text
1629
+ *
1630
+ * @param name The relative filename of the entry.
1631
+ * @param text The text.
1632
+ * @param options The options.
1633
+ * @returns A {@link ZipFileEntry} instance.
1634
+ */
1635
+ addText(
1636
+ name: string,
1637
+ text: string,
1638
+ options?: ZipWriterAddDataOptions,
1639
+ ): ZipFileEntry<string, string>;
1640
+ /**
1641
+ * Adds a entry entry with content provided as a `Blob` instance
1642
+ *
1643
+ * @param name The relative filename of the entry.
1644
+ * @param blob The `Blob` instance.
1645
+ * @param options The options.
1646
+ * @returns A {@link ZipFileEntry} instance.
1647
+ */
1648
+ addBlob(
1649
+ name: string,
1650
+ blob: Blob,
1651
+ options?: ZipWriterAddDataOptions,
1652
+ ): ZipFileEntry<Blob, Blob>;
1653
+ /**
1654
+ * Adds a entry entry with content provided as a Data URI `string` encoded in Base64
1655
+ *
1656
+ * @param name The relative filename of the entry.
1657
+ * @param dataURI The Data URI `string` encoded in Base64.
1658
+ * @param options The options.
1659
+ * @returns A {@link ZipFileEntry} instance.
1660
+ */
1661
+ addData64URI(
1662
+ name: string,
1663
+ dataURI: string,
1664
+ options?: ZipWriterAddDataOptions,
1665
+ ): ZipFileEntry<string, string>;
1666
+ /**
1667
+ * Adds an entry with content provided as a `Uint8Array` instance
1668
+ *
1669
+ * @param name The relative filename of the entry.
1670
+ * @param array The `Uint8Array` instance.
1671
+ * @param options The options.
1672
+ * @returns A {@link ZipFileEntry} instance.
1673
+ */
1674
+ addUint8Array(
1675
+ name: string,
1676
+ array: Uint8Array,
1677
+ options?: ZipWriterAddDataOptions,
1678
+ ): ZipFileEntry<Uint8Array, Uint8Array>;
1679
+ /**
1680
+ * Adds an entry with content fetched from a URL
1681
+ *
1682
+ * @param name The relative filename of the entry.
1683
+ * @param url The URL.
1684
+ * @param options The options.
1685
+ * @returns A {@link ZipFileEntry} instance.
1686
+ */
1687
+ addHttpContent(
1688
+ name: string,
1689
+ url: string,
1690
+ options?: HttpOptions & ZipWriterAddDataOptions,
1691
+ ): ZipFileEntry<string, void>;
1692
+ /**
1693
+ * Adds a entry entry with content provided via a `ReadableStream` instance
1694
+ *
1695
+ * @param name The relative filename of the entry.
1696
+ * @param readable The `ReadableStream` instance.
1697
+ * @param options The options.
1698
+ * @returns A {@link ZipFileEntry} instance.
1699
+ */
1700
+ addReadable(
1701
+ name: string,
1702
+ readable: ReadableStream,
1703
+ options?: ZipWriterAddDataOptions,
1704
+ ): ZipFileEntry<ReadableStream, void>;
1705
+ /**
1706
+ * Adds an entry with content provided via a `File` instance
1707
+ *
1708
+ * @param file The `File` instance.
1709
+ * @param options The options.
1710
+ * @returns A promise resolving to a {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance.
1711
+ */
1712
+ addFile(
1713
+ file: File,
1714
+ options?: ZipWriterAddDataOptions,
1715
+ ): Promise<ZipEntry>;
1716
+ /**
1717
+ * Adds an entry with content provided via a `FileSystemEntry` instance
1718
+ *
1719
+ * @param fileSystemEntry The `FileSystemEntry` instance.
1720
+ * @param options The options.
1721
+ * @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
1722
+ */
1723
+ addFileSystemEntry(
1724
+ fileSystemEntry: FileSystemEntryLike,
1725
+ options?: ZipWriterAddDataOptions,
1726
+ ): Promise<ZipEntry[]>;
1727
+ /**
1728
+ * Adds an entry with content provided via a `FileSystemHandle` instance
1729
+ *
1730
+ * @param fileSystemHandle The `fileSystemHandle` instance.
1731
+ * @param options The options.
1732
+ * @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
1733
+ */
1734
+ addFileSystemHandle(
1735
+ fileSystemHandle: FileSystemHandleLike,
1736
+ options?: ZipWriterAddDataOptions,
1737
+ ): Promise<ZipEntry[]>;
1738
+ /**
1739
+ * Extracts a zip file provided as a `Blob` instance into the entry
1740
+ *
1741
+ * @param blob The `Blob` instance.
1742
+ * @param options The options.
1743
+ */
1744
+ importBlob(
1745
+ blob: Blob,
1746
+ options?: ZipReaderConstructorOptions,
1747
+ ): Promise<[ZipEntry]>;
1748
+ /**
1749
+ * Extracts a zip file provided as a Data URI `string` encoded in Base64 into the entry
1750
+ *
1751
+ * @param dataURI The Data URI `string` encoded in Base64.
1752
+ * @param options The options.
1753
+ */
1754
+ importData64URI(
1755
+ dataURI: string,
1756
+ options?: ZipReaderConstructorOptions,
1757
+ ): Promise<[ZipEntry]>;
1758
+ /**
1759
+ * Extracts a zip file provided as a `Uint8Array` instance into the entry
1760
+ *
1761
+ * @param array The `Uint8Array` instance.
1762
+ * @param options The options.
1763
+ */
1764
+ importUint8Array(
1765
+ array: Uint8Array,
1766
+ options?: ZipReaderConstructorOptions,
1767
+ ): Promise<[ZipEntry]>;
1768
+ /**
1769
+ * Extracts a zip file fetched from a URL into the entry
1770
+ *
1771
+ * @param url The URL.
1772
+ * @param options The options.
1773
+ */
1774
+ importHttpContent(
1775
+ url: string,
1776
+ options?: ZipDirectoryEntryImportHttpOptions,
1777
+ ): Promise<[ZipEntry]>;
1778
+ /**
1779
+ * Extracts a zip file provided via a `ReadableStream` instance into the entry
1780
+ *
1781
+ * @param readable The `ReadableStream` instance.
1782
+ * @param options The options.
1783
+ */
1784
+ importReadable(
1785
+ readable: ReadableStream,
1786
+ options?: ZipReaderConstructorOptions,
1787
+ ): Promise<[ZipEntry]>;
1788
+ /**
1789
+ * Extracts a zip file provided via a custom {@link Reader} instance into the entry
1790
+ *
1791
+ * @param reader The {@link Reader} instance.
1792
+ * @param options The options.
1793
+ */
1794
+ importZip(
1795
+ reader:
1796
+ | Reader<unknown>
1797
+ | ReadableReader
1798
+ | ReadableStream
1799
+ | Reader<unknown>[]
1800
+ | ReadableReader[]
1801
+ | ReadableStream[],
1802
+ options?: ZipReaderConstructorOptions,
1803
+ ): Promise<[ZipEntry]>;
1804
+ /**
1805
+ * Returns a `Blob` instance containing a zip file of the entry and its descendants
1806
+ *
1807
+ * @param options The options.
1808
+ * @returns A promise resolving to the `Blob` instance.
1809
+ */
1810
+ exportBlob(options?: ZipDirectoryEntryExportOptions): Promise<Blob>;
1811
+ /**
1812
+ * Returns a Data URI `string` encoded in Base64 containing a zip file of the entry and its descendants
1813
+ *
1814
+ * @param options The options.
1815
+ * @returns A promise resolving to the Data URI `string` encoded in Base64.
1816
+ */
1817
+ exportData64URI(options?: ZipDirectoryEntryExportOptions): Promise<string>;
1818
+ /**
1819
+ * Returns a `Uint8Array` instance containing a zip file of the entry and its descendants
1820
+ *
1821
+ * @param options The options.
1822
+ * @returns A promise resolving to the `Uint8Array` instance.
1823
+ */
1824
+ exportUint8Array(
1825
+ options?: ZipDirectoryEntryExportOptions,
1826
+ ): Promise<Uint8Array>;
1827
+ /**
1828
+ * Creates a zip file via a `WritableStream` instance containing the entry and its descendants
1829
+ *
1830
+ * @param writable The `WritableStream` instance.
1831
+ * @param options The options.
1832
+ * @returns A promise resolving to the `Uint8Array` instance.
1833
+ */
1834
+ exportWritable(
1835
+ writable?: WritableStream,
1836
+ options?: ZipDirectoryEntryExportOptions,
1837
+ ): Promise<WritableStream>;
1838
+ /**
1839
+ * Creates a zip file via a custom {@link Writer} instance containing the entry and its descendants
1840
+ *
1841
+ * @param writer The {@link Writer} instance.
1842
+ * @param options The options.
1843
+ * @returns A promise resolving to the data.
1844
+ */
1845
+ exportZip(
1846
+ writer:
1847
+ | Writer<unknown>
1848
+ | WritableWriter
1849
+ | WritableStream
1850
+ | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>,
1851
+ options?: ZipDirectoryEntryExportOptions,
1852
+ ): Promise<unknown>;
1853
+ }
1854
+
1855
+ /**
1856
+ * Represents the options passed to {@link ZipDirectoryEntry#importHttpContent}.
1857
+ */
1858
+ export interface ZipDirectoryEntryImportHttpOptions
1859
+ extends ZipReaderConstructorOptions, HttpOptions { }
1860
+
1861
+ /**
1862
+ * Represents the options passed to `{@link ZipDirectoryEntry}#export*()`.
1863
+ */
1864
+ export interface ZipDirectoryEntryExportOptions
1865
+ extends ZipWriterConstructorOptions, EntryDataOnprogressOptions {
1866
+ /**
1867
+ * `true` to use filenames relative to the entry instead of full filenames.
1868
+ */
1869
+ relativePath?: boolean;
1870
+ /**
1871
+ * The MIME type of the exported data when relevant.
1872
+ */
1873
+ mimeType?: string;
1874
+ /**
1875
+ * The options passed to the Reader instances
1876
+ */
1877
+ readerOptions?: ZipReaderConstructorOptions;
1878
+ }
1879
+
1880
+ /**
1881
+ * Represents a Filesystem instance.
1882
+ *
1883
+ * @example
1884
+ * Here is an example showing how to create and read a zip file containing a compressed text file:
1885
+ * ```
1886
+ * const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.";
1887
+ * const FILENAME = "lorem.txt";
1888
+ * const BLOB = new Blob([TEXT_CONTENT], { type: zip.getMimeType(FILENAME) });
1889
+ * let zipFs = new zip.fs.FS();
1890
+ * zipFs.addBlob("lorem.txt", BLOB);
1891
+ * const zippedBlob = await zipFs.exportBlob();
1892
+ * zipFs = new zip.fs.FS();
1893
+ * await zipFs.importBlob(zippedBlob);
1894
+ * const firstEntry = zipFs.children[0];
1895
+ * const unzippedBlob = await firstEntry.getBlob(zip.getMimeType(firstEntry.name));
1896
+ * ```
1897
+ */
1898
+ export class FS extends ZipDirectoryEntry {
1899
+ /**
1900
+ * The root directory.
1901
+ */
1902
+ root: ZipDirectoryEntry;
1903
+ /**
1904
+ * Removes a {@link ZipEntry} instance and its children
1905
+ *
1906
+ * @param entry The {@link ZipEntry} instance to remove.
1907
+ */
1908
+ remove(entry: ZipEntry): void;
1909
+ /**
1910
+ * Moves a {@link ZipEntry} instance and its children into a {@link ZipDirectoryEntry} instance
1911
+ *
1912
+ * @param entry The {@link ZipEntry} instance to move.
1913
+ * @param destination The {@link ZipDirectoryEntry} instance.
1914
+ */
1915
+ move(entry: ZipEntry, destination: ZipDirectoryEntry): void;
1916
+ /**
1917
+ * Returns a {@link ZipEntry} instance from its full filename
1918
+ *
1919
+ * @param fullname The full filename.
1920
+ * @returns The {@link ZipEntry} instance.
1921
+ */
1922
+ find(fullname: string): ZipEntry | undefined;
1923
+ /**
1924
+ * Returns a {@link ZipEntry} instance from the value of {@link ZipEntry#id}
1925
+ *
1926
+ * @param id The id of the {@link ZipEntry} instance.
1927
+ * @returns The {@link ZipEntry} instance.
1928
+ */
1929
+ getById(id: number): ZipEntry | undefined;
1930
+ }
1931
+
1932
+ /**
1933
+ * The Filesystem API.
1934
+ */
1935
+ export const fs: {
1936
+ /**
1937
+ * The Filesystem constructor.
1938
+ *
1939
+ * @defaultValue {@link FS}
1940
+ */
1941
+ FS: typeof FS;
1942
+ /**
1943
+ * The {@link ZipDirectoryEntry} constructor.
1944
+ *
1945
+ * @defaultValue {@link ZipDirectoryEntry}
1946
+ */
1947
+ ZipDirectoryEntry: typeof ZipDirectoryEntry;
1948
+ /**
1949
+ * The {@link ZipFileEntry} constructor.
1950
+ *
1951
+ * @defaultValue {@link ZipFileEntry}
1952
+ */
1953
+ ZipFileEntry: typeof ZipFileEntry;
1954
+ };
1955
+
1956
+ // The error messages.
1957
+ /**
1958
+ * HTTP range error
1959
+ */
1960
+ export const ERR_HTTP_RANGE: string;
1961
+ /**
1962
+ * Zip format error
1963
+ */
1964
+ export const ERR_BAD_FORMAT: string;
1965
+ /**
1966
+ * End of Central Directory Record not found error
1967
+ */
1968
+ export const ERR_EOCDR_NOT_FOUND: string;
1969
+ /**
1970
+ * Zip64 End of Central Directory Locator not found error
1971
+ */
1972
+ export const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: string;
1973
+ /**
1974
+ * Central Directory not found error
1975
+ */
1976
+ export const ERR_CENTRAL_DIRECTORY_NOT_FOUND: string;
1977
+ /**
1978
+ * Local file header not found error
1979
+ */
1980
+ export const ERR_LOCAL_FILE_HEADER_NOT_FOUND: string;
1981
+ /**
1982
+ * Extra field Zip64 not found error
1983
+ */
1984
+ export const ERR_EXTRAFIELD_ZIP64_NOT_FOUND: string;
1985
+ /**
1986
+ * Encrypted entry error
1987
+ */
1988
+ export const ERR_ENCRYPTED: string;
1989
+ /**
1990
+ * Unsupported encryption error
1991
+ */
1992
+ export const ERR_UNSUPPORTED_ENCRYPTION: string;
1993
+ /**
1994
+ * Unsupported compression error
1995
+ */
1996
+ export const ERR_UNSUPPORTED_COMPRESSION: string;
1997
+ /**
1998
+ * Invalid signature error
1999
+ */
2000
+ export const ERR_INVALID_SIGNATURE: string;
2001
+ /**
2002
+ * Invalid password error
2003
+ */
2004
+ export const ERR_INVALID_PASSWORD: string;
2005
+ /**
2006
+ * Duplicate entry error
2007
+ */
2008
+ export const ERR_DUPLICATED_NAME: string;
2009
+ /**
2010
+ * Invalid comment error
2011
+ */
2012
+ export const ERR_INVALID_COMMENT: string;
2013
+ /**
2014
+ * Invalid entry name error
2015
+ */
2016
+ export const ERR_INVALID_ENTRY_NAME: string;
2017
+ /**
2018
+ * Invalid entry comment error
2019
+ */
2020
+ export const ERR_INVALID_ENTRY_COMMENT: string;
2021
+ /**
2022
+ * Invalid version error
2023
+ */
2024
+ export const ERR_INVALID_VERSION: string;
2025
+ /**
2026
+ * Invalid extra field type error
2027
+ */
2028
+ export const ERR_INVALID_EXTRAFIELD_TYPE: string;
2029
+ /**
2030
+ * Invalid extra field data error
2031
+ */
2032
+ export const ERR_INVALID_EXTRAFIELD_DATA: string;
2033
+ /**
2034
+ * Invalid encryption strength error
2035
+ */
2036
+ export const ERR_INVALID_ENCRYPTION_STRENGTH: string;
2037
+ /**
2038
+ * Invalid format error
2039
+ */
2040
+ export const ERR_UNSUPPORTED_FORMAT: string;
2041
+ /**
2042
+ * Split zip file error
2043
+ */
2044
+ export const ERR_SPLIT_ZIP_FILE: string;
2045
+ /**
2046
+ * Iteration completed too soon error
2047
+ */
2048
+ export const ERR_ITERATOR_COMPLETED_TOO_SOON: string;