@zip.js/zip.js 2.7.59 → 2.7.61

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.
@@ -1,2108 +0,0 @@
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
- interface URLString extends String { }
398
-
399
- /**
400
- * Represents a {@link Reader} instance used to fetch data from a URL.
401
- */
402
- export class HttpReader extends Reader<URLString> {
403
- /**
404
- * Creates the {@link HttpReader} instance
405
- *
406
- * @param url The URL of the data.
407
- * @param options The options.
408
- */
409
- constructor(url: URLString | URL, options?: HttpOptions);
410
- }
411
-
412
- /**
413
- * Represents a {@link Reader} instance used to fetch data from servers returning `Accept-Ranges` headers.
414
- */
415
- export class HttpRangeReader extends HttpReader {
416
- /**
417
- * Creates the {@link HttpRangeReader} instance
418
- *
419
- * @param url The URL of the data.
420
- * @param options The options.
421
- */
422
- constructor(url: URLString | URL, options?: HttpRangeOptions);
423
- }
424
-
425
- /**
426
- * Represents the options passed to the constructor of {@link HttpReader}.
427
- */
428
- export interface HttpOptions extends HttpRangeOptions {
429
- /**
430
- * `true` to use `Range` headers when fetching data from servers returning `Accept-Ranges` headers.
431
- *
432
- * @defaultValue false
433
- */
434
- useRangeHeader?: boolean;
435
- /**
436
- * `true` to always use `Range` headers when fetching data.
437
- *
438
- * @defaultValue false
439
- */
440
- forceRangeRequests?: boolean;
441
- /**
442
- * `true` to prevent using `HEAD` HTTP request in order the get the size of the content.
443
- * `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.
444
- *
445
- * @defaultValue false
446
- */
447
- preventHeadRequest?: boolean;
448
- /**
449
- * `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.
450
- *
451
- * @defaultValue false
452
- */
453
- combineSizeEocd?: boolean;
454
- }
455
-
456
- /**
457
- * Represents options passed to the constructor of {@link HttpRangeReader} and {@link HttpReader}.
458
- */
459
- export interface HttpRangeOptions {
460
- /**
461
- * `true` to rely `XMLHttpRequest` instead of `fetch` to fetch data.
462
- *
463
- * @defaultValue false
464
- */
465
- useXHR?: boolean;
466
- /**
467
- * The HTTP headers.
468
- */
469
- headers?: Iterable<[string, string]> | Map<string, string>;
470
- }
471
-
472
- /**
473
- * Represents an instance used to write data into a `WritableStream` instance.
474
- */
475
- export interface WritableWriter {
476
- /**
477
- * The `WritableStream` instance.
478
- */
479
- writable: WritableStream;
480
- /**
481
- * 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.
482
- */
483
- maxSize?: number;
484
- }
485
-
486
- /**
487
- * Represents an instance used to write unknown type of data.
488
- *
489
- * @example
490
- * Here is an example of custom {@link Writer} class used to write binary strings:
491
- * ```
492
- * class BinaryStringWriter extends Writer {
493
- *
494
- * constructor() {
495
- * super();
496
- * this.binaryString = "";
497
- * }
498
- *
499
- * writeUint8Array(array) {
500
- * for (let indexCharacter = 0; indexCharacter < array.length; indexCharacter++) {
501
- * this.binaryString += String.fromCharCode(array[indexCharacter]);
502
- * }
503
- * }
504
- *
505
- * getData() {
506
- * return this.binaryString;
507
- * }
508
- * }
509
- * ```
510
- */
511
- export class Writer<Type> implements Initializable, WritableWriter {
512
- /**
513
- * The `WritableStream` instance.
514
- */
515
- writable: WritableStream;
516
- /**
517
- * Initializes the instance asynchronously
518
- *
519
- * @param size the total size of the written data in bytes.
520
- */
521
- init?(size?: number): Promise<void>;
522
- /**
523
- * Appends a chunk of data
524
- *
525
- * @param array The chunk data to append.
526
- *
527
- * @virtual
528
- */
529
- writeUint8Array(array: Uint8Array): Promise<void>;
530
- /**
531
- * Retrieves all the written data
532
- *
533
- * @returns A promise resolving to the written data.
534
- */
535
- getData(): Promise<Type>;
536
- }
537
-
538
- /**
539
- * Represents a {@link Writer} instance used to retrieve the written data as a `string`.
540
- */
541
- export class TextWriter extends Writer<string> {
542
- /**
543
- * Creates the {@link TextWriter} instance
544
- *
545
- * @param encoding The encoding of the text.
546
- */
547
- constructor(encoding?: string);
548
- }
549
-
550
- /**
551
- * Represents a {@link WritableWriter} instance used to retrieve the written data as a `Blob` instance.
552
- */
553
- export class BlobWriter implements Initializable, WritableWriter {
554
- /**
555
- * The `WritableStream` instance.
556
- */
557
- writable: WritableStream;
558
- /**
559
- * Initializes the instance asynchronously
560
- */
561
- init(): Promise<void>;
562
- /**
563
- * Creates the {@link BlobWriter} instance
564
- *
565
- * @param mimeString The MIME type of the content.
566
- */
567
- constructor(mimeString?: string);
568
- /**
569
- * Retrieves all the written data
570
- *
571
- * @returns A promise resolving to the written data.
572
- */
573
- getData(): Promise<Blob>;
574
- }
575
-
576
- /**
577
- * Represents a {@link Writer} instance used to retrieve the written data as a Data URI `string` encoded in Base64.
578
- */
579
- export class Data64URIWriter extends Writer<string> {
580
- /**
581
- * Creates the {@link Data64URIWriter} instance
582
- *
583
- * @param mimeString The MIME type of the content.
584
- */
585
- constructor(mimeString?: string);
586
- }
587
-
588
- /**
589
- * Represents a {@link Writer} instance used to retrieve the written data from a generator of {@link WritableWriter} instances (i.e. split zip files).
590
- *
591
- * @deprecated Use {@link SplitDataWriter} instead.
592
- */
593
- export class SplitZipWriter extends SplitDataWriter { }
594
-
595
- /**
596
- * Represents a {@link Writer} instance used to retrieve the written data from a generator of {@link WritableWriter} instances (i.e. split zip files).
597
- */
598
- export class SplitDataWriter implements Initializable, WritableWriter {
599
- /**
600
- * The `WritableStream` instance.
601
- */
602
- writable: WritableStream;
603
- /**
604
- * Initializes the instance asynchronously
605
- */
606
- init(): Promise<void>;
607
- /**
608
- * Creates the {@link SplitDataWriter} instance
609
- *
610
- * @param writerGenerator A generator of Writer instances.
611
- * @param maxSize The maximum size of the data written into {@link Writer} instances (default: 4GB).
612
- */
613
- constructor(
614
- writerGenerator: AsyncGenerator<
615
- Writer<unknown> | WritableWriter | WritableStream,
616
- boolean
617
- >,
618
- maxSize?: number,
619
- );
620
- }
621
-
622
- /**
623
- * Represents a {@link Writer} instance used to retrieve the written data as a `Uint8Array` instance.
624
- */
625
- export class Uint8ArrayWriter extends Writer<Uint8Array> { }
626
-
627
- /**
628
- * Represents an instance used to create an unzipped stream.
629
- *
630
- * @example
631
- * This example will take a zip file, decompress it and then save its files and directories to disk.
632
- * ```
633
- * import {resolve} from "https://deno.land/std/path/mod.ts";
634
- * import {ensureDir, ensureFile} from "https://deno.land/std/fs/mod.ts";
635
- *
636
- * for await (const entry of (await fetch(urlToZippedFile)).body.pipeThrough(new ZipReaderStream())) {
637
- * const fullPath = resolve(destination, entry.filename);
638
- * if (entry.directory) {
639
- * await ensureDir(fullPath);
640
- * continue;
641
- * }
642
- *
643
- * await ensureFile(fullPath);
644
- * await entry.readable?.pipeTo((await Deno.create(fullPath)).writable);
645
- * }
646
- * ```
647
- */
648
- export class ZipReaderStream<T> {
649
- /**
650
- * Creates the stream.
651
- *
652
- * @param options The options.
653
- */
654
- constructor(options?: ZipReaderConstructorOptions);
655
-
656
- /**
657
- * The readable stream.
658
- */
659
- readable: ReadableStream<
660
- Omit<Entry, "getData"> & { readable?: ReadableStream<Uint8Array> }
661
- >;
662
-
663
- /**
664
- * The writable stream.
665
- */
666
- writable: WritableStream<T>;
667
- }
668
-
669
- /**
670
- * Represents an instance used to read a zip file.
671
- *
672
- * @example
673
- * Here is an example showing how to read the text data of the first entry from a zip file:
674
- * ```
675
- * // create a BlobReader to read with a ZipReader the zip from a Blob object
676
- * const reader = new zip.ZipReader(new zip.BlobReader(blob));
677
- *
678
- * // get all entries from the zip
679
- * const entries = await reader.getEntries();
680
- * if (entries.length) {
681
- *
682
- * // get first entry content as text by using a TextWriter
683
- * const text = await entries[0].getData(
684
- * // writer
685
- * new zip.TextWriter(),
686
- * // options
687
- * {
688
- * onprogress: (index, max) => {
689
- * // onprogress callback
690
- * }
691
- * }
692
- * );
693
- * // text contains the entry data as a String
694
- * console.log(text);
695
- * }
696
- *
697
- * // close the ZipReader
698
- * await reader.close();
699
- * ```
700
- */
701
- export class ZipReader<Type> {
702
- /**
703
- * Creates the instance
704
- *
705
- * @param reader The {@link Reader} instance used to read data.
706
- * @param options The options.
707
- */
708
- constructor(
709
- reader:
710
- | Reader<Type>
711
- | ReadableReader
712
- | ReadableStream
713
- | Reader<unknown>[]
714
- | ReadableReader[]
715
- | ReadableStream[],
716
- options?: ZipReaderConstructorOptions,
717
- );
718
- /**
719
- * The global comment of the zip file.
720
- */
721
- comment: Uint8Array;
722
- /**
723
- * The data prepended before the zip file.
724
- */
725
- prependedData?: Uint8Array;
726
- /**
727
- * The data appended after the zip file.
728
- */
729
- appendedData?: Uint8Array;
730
- /**
731
- * Returns all the entries in the zip file
732
- *
733
- * @param options The options.
734
- * @returns A promise resolving to an `array` of {@link Entry} instances.
735
- */
736
- getEntries(options?: ZipReaderGetEntriesOptions): Promise<Entry[]>;
737
- /**
738
- * Returns a generator used to iterate on all the entries in the zip file
739
- *
740
- * @param options The options.
741
- * @returns An asynchronous generator of {@link Entry} instances.
742
- */
743
- getEntriesGenerator(
744
- options?: ZipReaderGetEntriesOptions,
745
- ): AsyncGenerator<Entry, boolean>;
746
- /**
747
- * Closes the zip file
748
- */
749
- close(): Promise<void>;
750
- }
751
-
752
- /**
753
- * Represents the options passed to the constructor of {@link ZipReader}, and `{@link ZipDirectory}#import*`.
754
- */
755
- export interface ZipReaderConstructorOptions
756
- extends ZipReaderOptions, GetEntriesOptions, WorkerConfiguration {
757
- /**
758
- * `true` to extract the prepended data into {@link ZipReader#prependedData}.
759
- *
760
- * @defaultValue false
761
- */
762
- extractPrependedData?: boolean;
763
- /**
764
- * `true` to extract the appended data into {@link ZipReader#appendedData}.
765
- *
766
- * @defaultValue false
767
- */
768
- extractAppendedData?: boolean;
769
- }
770
-
771
- /**
772
- * Represents the options passed to {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
773
- */
774
- export interface ZipReaderGetEntriesOptions
775
- extends GetEntriesOptions, EntryOnprogressOptions { }
776
-
777
- /**
778
- * Represents options passed to the constructor of {@link ZipReader}, {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
779
- */
780
- export interface GetEntriesOptions {
781
- /**
782
- * The encoding of the filename of the entry.
783
- */
784
- filenameEncoding?: string;
785
- /**
786
- * The encoding of the comment of the entry.
787
- */
788
- commentEncoding?: string;
789
- /**
790
- * The function called for decoding the filename and the comment of the entry.
791
- *
792
- * @param value The raw text value.
793
- * @param encoding The encoding of the text.
794
- * @returns The decoded text value or `undefined` if the raw text value should be decoded by zip.js.
795
- */
796
- decodeText?(value: Uint8Array, encoding: string): string | undefined;
797
- }
798
-
799
- /**
800
- * Represents options passed to the constructor of {@link ZipReader} and {@link Entry#getData}.
801
- */
802
- export interface ZipReaderOptions {
803
- /**
804
- * `true` to check only if the password is valid.
805
- *
806
- * @defaultValue false
807
- */
808
- checkPasswordOnly?: boolean;
809
- /**
810
- * `true` to check the signature of the entry.
811
- *
812
- * @defaultValue false
813
- */
814
- checkSignature?: boolean;
815
- /**
816
- * The password used to decrypt the content of the entry.
817
- */
818
- password?: string;
819
- /**
820
- * `true` to read the data as-is without decompressing it and without decrypting it.
821
- */
822
- passThrough?: boolean;
823
- /**
824
- * The password used to encrypt the content of the entry (raw).
825
- */
826
- rawPassword?: Uint8Array;
827
- /**
828
- * The `AbortSignal` instance used to cancel the decompression.
829
- */
830
- signal?: AbortSignal;
831
- /**
832
- * `true` to prevent closing of {@link Writer#writable} when calling {@link Entry#getData}.
833
- *
834
- * @defaultValue false
835
- */
836
- preventClose?: boolean;
837
- /**
838
- * `true` to transfer streams to web workers when decompressing data.
839
- *
840
- * @defaultValue true
841
- */
842
- transferStreams?: boolean;
843
- }
844
-
845
- /**
846
- * Represents the metadata of an entry in a zip file (Core API).
847
- */
848
- export interface EntryMetaData {
849
- /**
850
- * The byte offset of the entry.
851
- */
852
- offset: number;
853
- /**
854
- * The filename of the entry.
855
- */
856
- filename: string;
857
- /**
858
- * The filename of the entry (raw).
859
- */
860
- rawFilename: Uint8Array;
861
- /**
862
- * `true` if the filename is encoded in UTF-8.
863
- */
864
- filenameUTF8: boolean;
865
- /**
866
- * `true` if the entry is a directory.
867
- */
868
- directory: boolean;
869
- /**
870
- * `true` if the entry is an executable file
871
- */
872
- executable: boolean;
873
- /**
874
- * `true` if the content of the entry is encrypted.
875
- */
876
- encrypted: boolean;
877
- /**
878
- * `true` if the content of the entry is encrypted with the ZipCrypto algorithm.
879
- */
880
- zipCrypto: boolean;
881
- /**
882
- * The size of the compressed data in bytes.
883
- */
884
- compressedSize: number;
885
- /**
886
- * The size of the decompressed data in bytes.
887
- */
888
- uncompressedSize: number;
889
- /**
890
- * The last modification date.
891
- */
892
- lastModDate: Date;
893
- /**
894
- * The last access date.
895
- */
896
- lastAccessDate?: Date;
897
- /**
898
- * The creation date.
899
- */
900
- creationDate?: Date;
901
- /**
902
- * The last modification date (raw).
903
- */
904
- rawLastModDate: number | bigint;
905
- /**
906
- * The last access date (raw).
907
- */
908
- rawLastAccessDate?: number | bigint;
909
- /**
910
- * The creation date (raw).
911
- */
912
- rawCreationDate?: number | bigint;
913
- /**
914
- * The comment of the entry.
915
- */
916
- comment: string;
917
- /**
918
- * The comment of the entry (raw).
919
- */
920
- rawComment: Uint8Array;
921
- /**
922
- * `true` if the comment is encoded in UTF-8.
923
- */
924
- commentUTF8: boolean;
925
- /**
926
- * The signature (CRC32 checksum) of the content.
927
- */
928
- signature: number;
929
- /**
930
- * The extra field.
931
- */
932
- extraField?: Map<number, { type: number, data: Uint8Array }>;
933
- /**
934
- * The extra field (raw).
935
- */
936
- rawExtraField: Uint8Array;
937
- /**
938
- * `true` if the entry is using Zip64.
939
- */
940
- zip64: boolean;
941
- /**
942
- * The "Version" field.
943
- */
944
- version: number;
945
- /**
946
- * The "Version made by" field.
947
- */
948
- versionMadeBy: number;
949
- /**
950
- * `true` if `internalFileAttributes` and `externalFileAttributes` are compatible with MS-DOS format.
951
- */
952
- msDosCompatible: boolean;
953
- /**
954
- * The internal file attributes (raw).
955
- */
956
- internalFileAttributes: number;
957
- /**
958
- * The external file attributes (raw).
959
- */
960
- externalFileAttributes: number;
961
- /**
962
- * The number of the disk where the entry data starts.
963
- */
964
- /**
965
- * The internal file attribute (raw).
966
- * @deprecated Use {@link EntryMetaData#internalFileAttributes} instead.
967
- */
968
- internalFileAttribute: number;
969
- /**
970
- * The external file attribute (raw).
971
- * @deprecated Use {@link EntryMetaData#externalFileAttributes} instead.
972
- */
973
- externalFileAttribute: number;
974
- /**
975
- * The number of the disk where the entry data starts.
976
- */
977
- diskNumberStart: number;
978
- /**
979
- * The compression method.
980
- */
981
- compressionMethod: number;
982
- }
983
-
984
- /**
985
- * Represents an entry with its data and metadata in a zip file (Core API).
986
- */
987
- export interface Entry extends EntryMetaData {
988
- /**
989
- * Returns the content of the entry
990
- *
991
- * @param writer The {@link Writer} instance used to write the content of the entry.
992
- * @param options The options.
993
- * @returns A promise resolving to the type to data associated to `writer`.
994
- */
995
- getData?<Type>(
996
- writer:
997
- | Writer<Type>
998
- | WritableWriter
999
- | WritableStream
1000
- | AsyncGenerator<
1001
- Writer<unknown> | WritableWriter | WritableStream,
1002
- boolean
1003
- >,
1004
- options?: EntryGetDataCheckPasswordOptions
1005
- ): Promise<Type>;
1006
- }
1007
-
1008
- /**
1009
- * Represents the options passed to {@link Entry#getData} and `{@link ZipFileEntry}.get*`.
1010
- */
1011
- export interface EntryGetDataOptions
1012
- extends EntryDataOnprogressOptions, ZipReaderOptions, WorkerConfiguration { }
1013
-
1014
- /**
1015
- * Represents the options passed to {@link Entry#getData} and `{@link ZipFileEntry}.get*`.
1016
- */
1017
- export interface EntryGetDataCheckPasswordOptions
1018
- extends EntryGetDataOptions { }
1019
-
1020
- /**
1021
- * Represents an instance used to create a zipped stream.
1022
- *
1023
- * @example
1024
- * This example creates a zipped file called numbers.txt.zip containing the numbers 0 - 1000 each on their own line.
1025
- * ```
1026
- * const readable = ReadableStream.from((function* () {
1027
- * for (let i = 0; i < 1000; ++i)
1028
- * yield i + '\n'
1029
- * })())
1030
- *
1031
- * readable
1032
- * .pipeThrough(new ZipWriterStream().transform('numbers.txt'))
1033
- * .pipeTo((await Deno.create('numbers.txt.zip')).writable)
1034
- * ```
1035
- *
1036
- * @example
1037
- * This example creates a zipped file called Archive.zip containing two files called numbers.txt and letters.txt
1038
- * ```
1039
- * const readable1 = ReadableStream.from((function* () {
1040
- * for (let i = 0; i < 1000; ++i)
1041
- * yield i + '\n'
1042
- * })())
1043
- * const readable2 = ReadableStream.from((function* () {
1044
- * const letters = 'abcdefghijklmnopqrstuvwxyz'.split('')
1045
- * while (letters.length)
1046
- * yield letters.shift() + '\n'
1047
- * })())
1048
- *
1049
- * const zipper = new ZipWriterStream()
1050
- * zipper.readable.pipeTo((await Deno.create('Archive.zip')).writable)
1051
- * readable1.pipeTo(zipper.writable('numbers.txt'))
1052
- * readable2.pipeTo(zipper.writable('letters.txt'))
1053
- * zipper.close()
1054
- * ```
1055
- */
1056
- export class ZipWriterStream {
1057
- /**
1058
- * Creates the stream.
1059
- *
1060
- * @param options The options.
1061
- */
1062
- constructor(options?: ZipWriterConstructorOptions);
1063
-
1064
- /**
1065
- * The readable stream.
1066
- */
1067
- readable: ReadableStream<Uint8Array>;
1068
-
1069
- /**
1070
- * The ZipWriter property.
1071
- */
1072
- zipWriter: ZipWriter<unknown>;
1073
-
1074
- /**
1075
- * Returns an object containing a readable and writable property for the .pipeThrough method
1076
- *
1077
- * @param path The name of the stream when unzipped.
1078
- * @returns An object containing readable and writable properties
1079
- */
1080
- transform<T>(
1081
- path: string,
1082
- ): { readable: ReadableStream<T>; writable: WritableStream<T> };
1083
-
1084
- /**
1085
- * Returns a WritableStream for the .pipeTo method
1086
- *
1087
- * @param path The directory path of where the stream should exist in the zipped stream.
1088
- * @returns A WritableStream.
1089
- */
1090
- writable<T>(path: string): WritableStream<T>;
1091
-
1092
- /**
1093
- * Writes the entries directory, writes the global comment, and returns the content of the zipped file.
1094
- *
1095
- * @param comment The global comment of the zip file.
1096
- * @param options The options.
1097
- * @returns The content of the zip file.
1098
- */
1099
- close(
1100
- comment?: Uint8Array,
1101
- options?: ZipWriterCloseOptions,
1102
- ): Promise<unknown>;
1103
- }
1104
-
1105
- /**
1106
- * Represents an instance used to create a zip file.
1107
- *
1108
- * @example
1109
- * Here is an example showing how to create a zip file containing a compressed text file:
1110
- * ```
1111
- * // use a BlobWriter to store with a ZipWriter the zip into a Blob object
1112
- * const blobWriter = new zip.BlobWriter("application/zip");
1113
- * const writer = new zip.ZipWriter(blobWriter);
1114
- *
1115
- * // use a TextReader to read the String to add
1116
- * await writer.add("filename.txt", new zip.TextReader("test!"));
1117
- *
1118
- * // close the ZipReader
1119
- * await writer.close();
1120
- *
1121
- * // get the zip file as a Blob
1122
- * const blob = await blobWriter.getData();
1123
- * ```
1124
- */
1125
- export class ZipWriter<Type> {
1126
- /**
1127
- * Creates the {@link ZipWriter} instance
1128
- *
1129
- * @param writer The {@link Writer} instance where the zip content will be written.
1130
- * @param options The options.
1131
- */
1132
- constructor(
1133
- writer:
1134
- | Writer<Type>
1135
- | WritableWriter
1136
- | WritableStream
1137
- | AsyncGenerator<
1138
- Writer<unknown> | WritableWriter | WritableStream,
1139
- boolean
1140
- >,
1141
- options?: ZipWriterConstructorOptions,
1142
- );
1143
- /**
1144
- * `true` if the zip contains at least one entry that has been partially written.
1145
- */
1146
- readonly hasCorruptedEntries?: boolean;
1147
- /**
1148
- * Adds an entry into the zip file
1149
- *
1150
- * @param filename The filename of the entry.
1151
- * @param reader The {@link Reader} instance used to read the content of the entry.
1152
- * @param options The options.
1153
- * @returns A promise resolving to an {@link EntryMetaData} instance.
1154
- */
1155
- add<ReaderType>(
1156
- filename: string,
1157
- reader?:
1158
- | Reader<ReaderType>
1159
- | ReadableReader
1160
- | ReadableStream
1161
- | Reader<unknown>[]
1162
- | ReadableReader[]
1163
- | ReadableStream[],
1164
- options?: ZipWriterAddDataOptions,
1165
- ): Promise<EntryMetaData>;
1166
- /**
1167
- * Writes the entries directory, writes the global comment, and returns the content of the zip file
1168
- *
1169
- * @param comment The global comment of the zip file.
1170
- * @param options The options.
1171
- * @returns The content of the zip file.
1172
- */
1173
- close(comment?: Uint8Array, options?: ZipWriterCloseOptions): Promise<Type>;
1174
- }
1175
-
1176
- /**
1177
- * Represents the options passed to {@link ZipWriter#add}.
1178
- */
1179
- export interface ZipWriterAddDataOptions
1180
- extends
1181
- ZipWriterConstructorOptions,
1182
- EntryDataOnprogressOptions,
1183
- WorkerConfiguration {
1184
- /**
1185
- * `true` if the entry is a directory.
1186
- *
1187
- * @defaultValue false
1188
- */
1189
- directory?: boolean;
1190
- /**
1191
- * `true` if the entry is an executable file.
1192
- *
1193
- * @defaultValue false
1194
- */
1195
- executable?: boolean;
1196
- /**
1197
- * The comment of the entry.
1198
- */
1199
- comment?: string;
1200
- /**
1201
- * The extra field of the entry.
1202
- */
1203
- extraField?: Map<number, Uint8Array>;
1204
- /**
1205
- * The uncompressed size of the entry. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
1206
- */
1207
- uncompressedSize?: number;
1208
- /**
1209
- * The signature (CRC32 checksum) of the content. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
1210
- */
1211
- signature?: number;
1212
- }
1213
-
1214
- /**
1215
- * Represents the options passed to {@link ZipWriter#close}.
1216
- */
1217
- export interface ZipWriterCloseOptions extends EntryOnprogressOptions {
1218
- /**
1219
- * `true` to use Zip64 to write the entries directory.
1220
- *
1221
- * @defaultValue false
1222
- */
1223
- zip64?: boolean;
1224
- /**
1225
- * `true` to prevent closing of {@link WritableWriter#writable}.
1226
- *
1227
- * @defaultValue false
1228
- */
1229
- preventClose?: boolean;
1230
- }
1231
-
1232
- /**
1233
- * Represents options passed to the constructor of {@link ZipWriter}, {@link ZipWriter#add} and `{@link ZipDirectoryEntry}#export*`.
1234
- */
1235
- export interface ZipWriterConstructorOptions {
1236
- /**
1237
- * `true` to use Zip64 to store the entry.
1238
- *
1239
- * `zip64` is automatically set to `true` when necessary (e.g. compressed data larger than 4GB or with unknown size).
1240
- *
1241
- * @defaultValue false
1242
- */
1243
- zip64?: boolean;
1244
- /**
1245
- * `true` to prevent closing of {@link WritableWriter#writable}.
1246
- *
1247
- * @defaultValue false
1248
- */
1249
- preventClose?: boolean;
1250
- /**
1251
- * The level of compression.
1252
- *
1253
- * The minimum value is 0 and means that no compression is applied. The maximum value is 9.
1254
- *
1255
- * @defaultValue 5
1256
- */
1257
- level?: number;
1258
- /**
1259
- * `true` to write entry data in a buffer before appending it to the zip file.
1260
- *
1261
- * `bufferedWrite` is automatically set to `true` when compressing more than one entry in parallel.
1262
- *
1263
- * @defaultValue false
1264
- */
1265
- bufferedWrite?: boolean;
1266
- /**
1267
- * `true` to keep the order of the entry physically in the zip file.
1268
- *
1269
- * 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.
1270
- * Another solution to improve the use of web workers is to add entries from smallest to largest in uncompressed size.
1271
- *
1272
- * @defaultValue true
1273
- */
1274
- keepOrder?: boolean;
1275
- /**
1276
- * The password used to encrypt the content of the entry.
1277
- */
1278
- password?: string;
1279
- /**
1280
- * The password used to encrypt the content of the entry (raw).
1281
- */
1282
- rawPassword?: Uint8Array;
1283
- /**
1284
- * The encryption strength (AES):
1285
- * - 1: 128-bit encryption key
1286
- * - 2: 192-bit encryption key
1287
- * - 3: 256-bit encryption key
1288
- *
1289
- * @defaultValue 3
1290
- */
1291
- encryptionStrength?: 1 | 2 | 3;
1292
- /**
1293
- * The `AbortSignal` instance used to cancel the compression.
1294
- */
1295
- signal?: AbortSignal;
1296
- /**
1297
- * The last modification date.
1298
- *
1299
- * @defaultValue The current date.
1300
- */
1301
- lastModDate?: Date;
1302
- /**
1303
- * The last access date.
1304
- *
1305
- * This option is ignored if the {@link ZipWriterConstructorOptions#extendedTimestamp} option is set to `false`.
1306
- *
1307
- * @defaultValue The current date.
1308
- */
1309
- lastAccessDate?: Date;
1310
- /**
1311
- * The creation date.
1312
- *
1313
- * This option is ignored if the {@link ZipWriterConstructorOptions#extendedTimestamp} option is set to `false`.
1314
- *
1315
- * @defaultValue The current date.
1316
- */
1317
- creationDate?: Date;
1318
- /**
1319
- * `true` to store extended timestamp extra fields.
1320
- *
1321
- * When set to `false`, the maximum last modification date cannot exceed November 31, 2107 and the maximum accuracy is 2 seconds.
1322
- *
1323
- * @defaultValue true
1324
- */
1325
- extendedTimestamp?: boolean;
1326
- /**
1327
- * `true` to use the ZipCrypto algorithm to encrypt the content of the entry.
1328
- *
1329
- * It is not recommended to set `zipCrypto` to `true` because the ZipCrypto encryption can be easily broken.
1330
- *
1331
- * @defaultValue false
1332
- */
1333
- zipCrypto?: boolean;
1334
- /**
1335
- * The "Version" field.
1336
- */
1337
- version?: number;
1338
- /**
1339
- * The "Version made by" field.
1340
- *
1341
- * @defaultValue 20
1342
- */
1343
- versionMadeBy?: number;
1344
- /**
1345
- * `true` to mark the file names as UTF-8 setting the general purpose bit 11 in the header (see Appendix D - Language Encoding (EFS)), `false` to mark the names as compliant with the original IBM Code Page 437.
1346
- *
1347
- * Note that this does not ensure that the file names are in the correct encoding.
1348
- *
1349
- * @defaultValue true
1350
- */
1351
- useUnicodeFileNames?: boolean;
1352
- /**
1353
- * `true` to add a data descriptor.
1354
- *
1355
- * When set to `false`, the {@link ZipWriterConstructorOptions#bufferedWrite} option will automatically be set to `true`.
1356
- *
1357
- * @defaultValue true
1358
- */
1359
- dataDescriptor?: boolean;
1360
- /**
1361
- * `true` to add the signature of the data descriptor.
1362
- *
1363
- * @defaultValue false
1364
- */
1365
- dataDescriptorSignature?: boolean;
1366
- /**
1367
- * `true` to write {@link EntryMetaData#externalFileAttributes} in MS-DOS format for folder entries.
1368
- *
1369
- * @defaultValue false
1370
- */
1371
- msDosCompatible?: boolean;
1372
- /**
1373
- * The external file attribute.
1374
- *
1375
- * @defaultValue 0
1376
- */
1377
- externalFileAttributes?: number;
1378
- /**
1379
- * The internal file attribute.
1380
- *
1381
- * @defaultValue 0
1382
- */
1383
- internalFileAttributes?: number;
1384
- /**
1385
- * `false` to never write disk numbers in zip64 data.
1386
- *
1387
- * @defaultValue true
1388
- */
1389
- supportZip64SplitFile?: boolean;
1390
- /**
1391
- * `true`to produce zip files compatible with the USDZ specification.
1392
- *
1393
- * @defaultValue false
1394
- */
1395
- usdz?: boolean;
1396
- /**
1397
- * `true` to write the data as-is without compressing it and without crypting it.
1398
- */
1399
- passThrough?: boolean;
1400
- /**
1401
- * `true` to write encrypted data when `passThrough` is set to `true`.
1402
- */
1403
- encrypted?: boolean;
1404
- /**
1405
- * The offset of the first entry in the zip file.
1406
- */
1407
- offset?: number;
1408
- /**
1409
- * The compression method (e.g. 8 for DEFLATE, 0 for STORE).
1410
- */
1411
- compressionMethod?: number
1412
- /**
1413
- * The function called for encoding the filename and the comment of the entry.
1414
- *
1415
- * @param text The text to encode.
1416
- * @returns The encoded text or `undefined` if the text should be encoded by zip.js.
1417
- */
1418
- encodeText?(text: string): Uint8Array | undefined;
1419
- }
1420
-
1421
- /**
1422
- * Represents options passed to {@link Entry#getData}, {@link ZipWriter.add} and `{@link ZipDirectory}.export*`.
1423
- */
1424
- export interface EntryDataOnprogressOptions {
1425
- /**
1426
- * The function called when starting compression/decompression.
1427
- *
1428
- * @param total The total number of bytes.
1429
- * @returns An empty promise or `undefined`.
1430
- */
1431
- onstart?(total: number): Promise<void> | undefined;
1432
- /**
1433
- * The function called during compression/decompression.
1434
- *
1435
- * @param progress The current progress in bytes.
1436
- * @param total The total number of bytes.
1437
- * @returns An empty promise or `undefined`.
1438
- */
1439
- onprogress?(progress: number, total: number): Promise<void> | undefined;
1440
- /**
1441
- * The function called when ending compression/decompression.
1442
- *
1443
- * @param computedSize The total number of bytes (computed).
1444
- * @returns An empty promise or `undefined`.
1445
- */
1446
- onend?(computedSize: number): Promise<void> | undefined;
1447
- }
1448
-
1449
- /**
1450
- * Represents options passed to {@link ZipReader#getEntries}, {@link ZipReader#getEntriesGenerator}, and {@link ZipWriter#close}.
1451
- */
1452
- export interface EntryOnprogressOptions {
1453
- /**
1454
- * The function called each time an entry is read/written.
1455
- *
1456
- * @param progress The entry index.
1457
- * @param total The total number of entries.
1458
- * @param entry The entry being read/written.
1459
- * @returns An empty promise or `undefined`.
1460
- */
1461
- onprogress?(
1462
- progress: number,
1463
- total: number,
1464
- entry: EntryMetaData,
1465
- ): Promise<void> | undefined;
1466
- }
1467
-
1468
- /**
1469
- * Represents an entry in a zip file (Filesystem API).
1470
- */
1471
- declare class ZipEntry {
1472
- /**
1473
- * The relative filename of the entry.
1474
- */
1475
- name: string;
1476
- /**
1477
- * The underlying {@link EntryMetaData} instance.
1478
- */
1479
- data?: EntryMetaData;
1480
- /**
1481
- * The ID of the instance.
1482
- */
1483
- id: number;
1484
- /**
1485
- * The parent directory of the entry.
1486
- */
1487
- parent?: ZipEntry;
1488
- /**
1489
- * The uncompressed size of the content.
1490
- */
1491
- uncompressedSize: number;
1492
- /**
1493
- * The children of the entry.
1494
- */
1495
- children: ZipEntry[];
1496
- /**
1497
- * Clones the entry
1498
- *
1499
- * @param deepClone `true` to clone all the descendants.
1500
- */
1501
- clone(deepClone?: boolean): ZipEntry;
1502
- /**
1503
- * Returns the full filename of the entry
1504
- */
1505
- getFullname(): string;
1506
- /**
1507
- * Returns the filename of the entry relative to a parent directory
1508
- */
1509
- getRelativeName(ancestor: ZipDirectoryEntry): string;
1510
- /**
1511
- * Tests if a {@link ZipDirectoryEntry} instance is an ancestor of the entry
1512
- *
1513
- * @param ancestor The {@link ZipDirectoryEntry} instance.
1514
- */
1515
- isDescendantOf(ancestor: ZipDirectoryEntry): boolean;
1516
- /**
1517
- * Tests if the entry or any of its children is password protected
1518
- */
1519
- isPasswordProtected(): boolean;
1520
- /**
1521
- * Tests the password on the entry and all children if any, returns `true` if the entry is not password protected
1522
- */
1523
- checkPassword(
1524
- password: string,
1525
- options?: EntryGetDataOptions,
1526
- ): Promise<boolean>;
1527
- /**
1528
- * Set the name of the entry
1529
- *
1530
- * @param name The new name of the entry.
1531
- */
1532
- rename(name: string): void;
1533
- }
1534
-
1535
- /**
1536
- * Represents a file entry in the zip (Filesystem API).
1537
- */
1538
- export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
1539
- /**
1540
- * `void` for {@link ZipFileEntry} instances.
1541
- */
1542
- directory: void;
1543
- /**
1544
- * The {@link Reader} instance used to read the content of the entry.
1545
- */
1546
- reader:
1547
- | Reader<ReaderType>
1548
- | ReadableReader
1549
- | ReadableStream
1550
- | Reader<unknown>[]
1551
- | ReadableReader[]
1552
- | ReadableStream[];
1553
- /**
1554
- * The {@link Writer} instance used to write the content of the entry.
1555
- */
1556
- writer:
1557
- | Writer<WriterType>
1558
- | WritableWriter
1559
- | WritableStream
1560
- | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>;
1561
- /**
1562
- * Retrieves the text content of the entry as a `string`
1563
- *
1564
- * @param encoding The encoding of the text.
1565
- * @param options The options.
1566
- * @returns A promise resolving to a `string`.
1567
- */
1568
- getText(encoding?: string, options?: EntryGetDataOptions): Promise<string>;
1569
- /**
1570
- * Retrieves the content of the entry as a `Blob` instance
1571
- *
1572
- * @param mimeType The MIME type of the content.
1573
- * @param options The options.
1574
- * @returns A promise resolving to a `Blob` instance.
1575
- */
1576
- getBlob(mimeType?: string, options?: EntryGetDataOptions): Promise<Blob>;
1577
- /**
1578
- * Retrieves the content of the entry as as a Data URI `string` encoded in Base64
1579
- *
1580
- * @param mimeType The MIME type of the content.
1581
- * @param options The options.
1582
- * @returns A promise resolving to a Data URI `string` encoded in Base64.
1583
- */
1584
- getData64URI(
1585
- mimeType?: string,
1586
- options?: EntryGetDataOptions,
1587
- ): Promise<string>;
1588
- /**
1589
- * Retrieves the content of the entry as a `Uint8Array` instance
1590
- *
1591
- * @param options The options.
1592
- * @returns A promise resolving to a `Uint8Array` instance.
1593
- */
1594
- getUint8Array(options?: EntryGetDataOptions): Promise<Uint8Array>;
1595
- /**
1596
- * Retrieves the content of the entry via a `WritableStream` instance
1597
- *
1598
- * @param writable The `WritableStream` instance.
1599
- * @param options The options.
1600
- * @returns A promise resolving to the `WritableStream` instance.
1601
- */
1602
- getWritable(
1603
- writable?: WritableStream,
1604
- options?: EntryGetDataOptions,
1605
- ): Promise<WritableStream>;
1606
- /**
1607
- * Retrieves the content of the entry via a {@link Writer} instance
1608
- *
1609
- * @param writer The {@link Writer} instance.
1610
- * @param options The options.
1611
- * @returns A promise resolving to data associated to the {@link Writer} instance.
1612
- */
1613
- getData(
1614
- writer:
1615
- | Writer<unknown>
1616
- | WritableWriter
1617
- | WritableStream
1618
- | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>,
1619
- options?: EntryGetDataOptions,
1620
- ): Promise<unknown>;
1621
- /**
1622
- * Replaces the content of the entry with a `Blob` instance
1623
- *
1624
- * @param blob The `Blob` instance.
1625
- */
1626
- replaceBlob(blob: Blob): void;
1627
- /**
1628
- * Replaces the content of the entry with a `string`
1629
- *
1630
- * @param text The `string`.
1631
- */
1632
- replaceText(text: string): void;
1633
- /**
1634
- * Replaces the content of the entry with a Data URI `string` encoded in Base64
1635
- *
1636
- * @param dataURI The Data URI `string` encoded in Base64.
1637
- */
1638
- replaceData64URI(dataURI: string): void;
1639
- /**
1640
- * Replaces the content of the entry with a `Uint8Array` instance
1641
- *
1642
- * @param array The `Uint8Array` instance.
1643
- */
1644
- replaceUint8Array(array: Uint8Array): void;
1645
- /**
1646
- * Replaces the content of the entry with a `ReadableStream` instance
1647
- *
1648
- * @param readable The `ReadableStream` instance.
1649
- */
1650
- replaceReadable(readable: ReadableStream): void;
1651
- }
1652
-
1653
- /**
1654
- * Represents a directory entry in the zip (Filesystem API).
1655
- */
1656
- export class ZipDirectoryEntry extends ZipEntry {
1657
- /**
1658
- * `true` for {@link ZipDirectoryEntry} instances.
1659
- */
1660
- directory: true;
1661
- /**
1662
- * Gets a {@link ZipEntry} child instance from its relative filename
1663
- *
1664
- * @param name The relative filename.
1665
- * @returns A {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance (use the {@link ZipFileEntry#directory} and {@link ZipDirectoryEntry#directory} properties to differentiate entries).
1666
- */
1667
- getChildByName(name: string): ZipEntry | undefined;
1668
- /**
1669
- * Adds a directory
1670
- *
1671
- * @param name The relative filename of the directory.
1672
- * @param options The options.
1673
- * @returns A {@link ZipDirectoryEntry} instance.
1674
- */
1675
- addDirectory(
1676
- name: string,
1677
- options?: ZipWriterAddDataOptions,
1678
- ): ZipDirectoryEntry;
1679
- /**
1680
- * Adds an entry with content provided as text
1681
- *
1682
- * @param name The relative filename of the entry.
1683
- * @param text The text.
1684
- * @param options The options.
1685
- * @returns A {@link ZipFileEntry} instance.
1686
- */
1687
- addText(
1688
- name: string,
1689
- text: string,
1690
- options?: ZipWriterAddDataOptions,
1691
- ): ZipFileEntry<string, string>;
1692
- /**
1693
- * Adds a entry entry with content provided as a `Blob` instance
1694
- *
1695
- * @param name The relative filename of the entry.
1696
- * @param blob The `Blob` instance.
1697
- * @param options The options.
1698
- * @returns A {@link ZipFileEntry} instance.
1699
- */
1700
- addBlob(
1701
- name: string,
1702
- blob: Blob,
1703
- options?: ZipWriterAddDataOptions,
1704
- ): ZipFileEntry<Blob, Blob>;
1705
- /**
1706
- * Adds a entry entry with content provided as a Data URI `string` encoded in Base64
1707
- *
1708
- * @param name The relative filename of the entry.
1709
- * @param dataURI The Data URI `string` encoded in Base64.
1710
- * @param options The options.
1711
- * @returns A {@link ZipFileEntry} instance.
1712
- */
1713
- addData64URI(
1714
- name: string,
1715
- dataURI: string,
1716
- options?: ZipWriterAddDataOptions,
1717
- ): ZipFileEntry<string, string>;
1718
- /**
1719
- * Adds an entry with content provided as a `Uint8Array` instance
1720
- *
1721
- * @param name The relative filename of the entry.
1722
- * @param array The `Uint8Array` instance.
1723
- * @param options The options.
1724
- * @returns A {@link ZipFileEntry} instance.
1725
- */
1726
- addUint8Array(
1727
- name: string,
1728
- array: Uint8Array,
1729
- options?: ZipWriterAddDataOptions,
1730
- ): ZipFileEntry<Uint8Array, Uint8Array>;
1731
- /**
1732
- * Adds an entry with content fetched from a URL
1733
- *
1734
- * @param name The relative filename of the entry.
1735
- * @param url The URL.
1736
- * @param options The options.
1737
- * @returns A {@link ZipFileEntry} instance.
1738
- */
1739
- addHttpContent(
1740
- name: string,
1741
- url: string,
1742
- options?: HttpOptions & ZipWriterAddDataOptions,
1743
- ): ZipFileEntry<string, void>;
1744
- /**
1745
- * Adds a entry entry with content provided via a `ReadableStream` instance
1746
- *
1747
- * @param name The relative filename of the entry.
1748
- * @param readable The `ReadableStream` instance.
1749
- * @param options The options.
1750
- * @returns A {@link ZipFileEntry} instance.
1751
- */
1752
- addReadable(
1753
- name: string,
1754
- readable: ReadableStream,
1755
- options?: ZipWriterAddDataOptions,
1756
- ): ZipFileEntry<ReadableStream, void>;
1757
- /**
1758
- * Adds an entry with content provided via a `File` instance
1759
- *
1760
- * @param file The `File` instance.
1761
- * @param options The options.
1762
- * @returns A promise resolving to a {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance.
1763
- */
1764
- addFile(
1765
- file: File,
1766
- options?: ZipWriterAddDataOptions,
1767
- ): Promise<ZipEntry>;
1768
- /**
1769
- * Adds an entry with content provided via a `FileSystemEntry` instance
1770
- *
1771
- * @param fileSystemEntry The `FileSystemEntry` instance.
1772
- * @param options The options.
1773
- * @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
1774
- */
1775
- addFileSystemEntry(
1776
- fileSystemEntry: FileSystemEntryLike,
1777
- options?: ZipWriterAddDataOptions,
1778
- ): Promise<ZipEntry[]>;
1779
- /**
1780
- * Adds an entry with content provided via a `FileSystemHandle` instance
1781
- *
1782
- * @param fileSystemHandle The `fileSystemHandle` instance.
1783
- * @param options The options.
1784
- * @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
1785
- */
1786
- addFileSystemHandle(
1787
- fileSystemHandle: FileSystemHandleLike,
1788
- options?: ZipWriterAddDataOptions,
1789
- ): Promise<ZipEntry[]>;
1790
- /**
1791
- * Extracts a zip file provided as a `Blob` instance into the entry
1792
- *
1793
- * @param blob The `Blob` instance.
1794
- * @param options The options.
1795
- */
1796
- importBlob(
1797
- blob: Blob,
1798
- options?: ZipReaderConstructorOptions,
1799
- ): Promise<[ZipEntry]>;
1800
- /**
1801
- * Extracts a zip file provided as a Data URI `string` encoded in Base64 into the entry
1802
- *
1803
- * @param dataURI The Data URI `string` encoded in Base64.
1804
- * @param options The options.
1805
- */
1806
- importData64URI(
1807
- dataURI: string,
1808
- options?: ZipReaderConstructorOptions,
1809
- ): Promise<[ZipEntry]>;
1810
- /**
1811
- * Extracts a zip file provided as a `Uint8Array` instance into the entry
1812
- *
1813
- * @param array The `Uint8Array` instance.
1814
- * @param options The options.
1815
- */
1816
- importUint8Array(
1817
- array: Uint8Array,
1818
- options?: ZipReaderConstructorOptions,
1819
- ): Promise<[ZipEntry]>;
1820
- /**
1821
- * Extracts a zip file fetched from a URL into the entry
1822
- *
1823
- * @param url The URL.
1824
- * @param options The options.
1825
- */
1826
- importHttpContent(
1827
- url: string,
1828
- options?: ZipDirectoryEntryImportHttpOptions,
1829
- ): Promise<[ZipEntry]>;
1830
- /**
1831
- * Extracts a zip file provided via a `ReadableStream` instance into the entry
1832
- *
1833
- * @param readable The `ReadableStream` instance.
1834
- * @param options The options.
1835
- */
1836
- importReadable(
1837
- readable: ReadableStream,
1838
- options?: ZipReaderConstructorOptions,
1839
- ): Promise<[ZipEntry]>;
1840
- /**
1841
- * Extracts a zip file provided via a custom {@link Reader} instance into the entry
1842
- *
1843
- * @param reader The {@link Reader} instance.
1844
- * @param options The options.
1845
- */
1846
- importZip(
1847
- reader:
1848
- | Reader<unknown>
1849
- | ReadableReader
1850
- | ReadableStream
1851
- | Reader<unknown>[]
1852
- | ReadableReader[]
1853
- | ReadableStream[],
1854
- options?: ZipReaderConstructorOptions,
1855
- ): Promise<[ZipEntry]>;
1856
- /**
1857
- * Returns a `Blob` instance containing a zip file of the entry and its descendants
1858
- *
1859
- * @param options The options.
1860
- * @returns A promise resolving to the `Blob` instance.
1861
- */
1862
- exportBlob(options?: ZipDirectoryEntryExportOptions): Promise<Blob>;
1863
- /**
1864
- * Returns a Data URI `string` encoded in Base64 containing a zip file of the entry and its descendants
1865
- *
1866
- * @param options The options.
1867
- * @returns A promise resolving to the Data URI `string` encoded in Base64.
1868
- */
1869
- exportData64URI(options?: ZipDirectoryEntryExportOptions): Promise<string>;
1870
- /**
1871
- * Returns a `Uint8Array` instance containing a zip file of the entry and its descendants
1872
- *
1873
- * @param options The options.
1874
- * @returns A promise resolving to the `Uint8Array` instance.
1875
- */
1876
- exportUint8Array(
1877
- options?: ZipDirectoryEntryExportOptions,
1878
- ): Promise<Uint8Array>;
1879
- /**
1880
- * Creates a zip file via a `WritableStream` instance containing the entry and its descendants
1881
- *
1882
- * @param writable The `WritableStream` instance.
1883
- * @param options The options.
1884
- * @returns A promise resolving to the `Uint8Array` instance.
1885
- */
1886
- exportWritable(
1887
- writable?: WritableStream,
1888
- options?: ZipDirectoryEntryExportOptions,
1889
- ): Promise<WritableStream>;
1890
- /**
1891
- * Creates a zip file via a custom {@link Writer} instance containing the entry and its descendants
1892
- *
1893
- * @param writer The {@link Writer} instance.
1894
- * @param options The options.
1895
- * @returns A promise resolving to the data.
1896
- */
1897
- exportZip(
1898
- writer:
1899
- | Writer<unknown>
1900
- | WritableWriter
1901
- | WritableStream
1902
- | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>,
1903
- options?: ZipDirectoryEntryExportOptions,
1904
- ): Promise<unknown>;
1905
- }
1906
-
1907
- /**
1908
- * Represents the options passed to {@link ZipDirectoryEntry#importHttpContent}.
1909
- */
1910
- export interface ZipDirectoryEntryImportHttpOptions
1911
- extends ZipReaderConstructorOptions, HttpOptions { }
1912
-
1913
- /**
1914
- * Represents the options passed to `{@link ZipDirectoryEntry}#export*()`.
1915
- */
1916
- export interface ZipDirectoryEntryExportOptions
1917
- extends ZipWriterConstructorOptions, EntryDataOnprogressOptions {
1918
- /**
1919
- * `true` to use filenames relative to the entry instead of full filenames.
1920
- */
1921
- relativePath?: boolean;
1922
- /**
1923
- * The MIME type of the exported data when relevant.
1924
- */
1925
- mimeType?: string;
1926
- /**
1927
- * The options passed to the Reader instances
1928
- */
1929
- readerOptions?: ZipReaderConstructorOptions;
1930
- }
1931
-
1932
- /**
1933
- * Represents a Filesystem instance.
1934
- *
1935
- * @example
1936
- * Here is an example showing how to create and read a zip file containing a compressed text file:
1937
- * ```
1938
- * const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.";
1939
- * const FILENAME = "lorem.txt";
1940
- * const BLOB = new Blob([TEXT_CONTENT], { type: zip.getMimeType(FILENAME) });
1941
- * let zipFs = new zip.fs.FS();
1942
- * zipFs.addBlob("lorem.txt", BLOB);
1943
- * const zippedBlob = await zipFs.exportBlob();
1944
- * zipFs = new zip.fs.FS();
1945
- * await zipFs.importBlob(zippedBlob);
1946
- * const firstEntry = zipFs.children[0];
1947
- * const unzippedBlob = await firstEntry.getBlob(zip.getMimeType(firstEntry.name));
1948
- * ```
1949
- */
1950
- export class FS extends ZipDirectoryEntry {
1951
- /**
1952
- * The root directory.
1953
- */
1954
- root: ZipDirectoryEntry;
1955
- /**
1956
- * Removes a {@link ZipEntry} instance and its children
1957
- *
1958
- * @param entry The {@link ZipEntry} instance to remove.
1959
- */
1960
- remove(entry: ZipEntry): void;
1961
- /**
1962
- * Moves a {@link ZipEntry} instance and its children into a {@link ZipDirectoryEntry} instance
1963
- *
1964
- * @param entry The {@link ZipEntry} instance to move.
1965
- * @param destination The {@link ZipDirectoryEntry} instance.
1966
- */
1967
- move(entry: ZipEntry, destination: ZipDirectoryEntry): void;
1968
- /**
1969
- * Returns a {@link ZipEntry} instance from its full filename
1970
- *
1971
- * @param fullname The full filename.
1972
- * @returns The {@link ZipEntry} instance.
1973
- */
1974
- find(fullname: string): ZipEntry | undefined;
1975
- /**
1976
- * Returns a {@link ZipEntry} instance from the value of {@link ZipEntry#id}
1977
- *
1978
- * @param id The id of the {@link ZipEntry} instance.
1979
- * @returns The {@link ZipEntry} instance.
1980
- */
1981
- getById(id: number): ZipEntry | undefined;
1982
- }
1983
-
1984
- /**
1985
- * The Filesystem API.
1986
- */
1987
- export const fs: {
1988
- /**
1989
- * The Filesystem constructor.
1990
- *
1991
- * @defaultValue {@link FS}
1992
- */
1993
- FS: typeof FS;
1994
- /**
1995
- * The {@link ZipDirectoryEntry} constructor.
1996
- *
1997
- * @defaultValue {@link ZipDirectoryEntry}
1998
- */
1999
- ZipDirectoryEntry: typeof ZipDirectoryEntry;
2000
- /**
2001
- * The {@link ZipFileEntry} constructor.
2002
- *
2003
- * @defaultValue {@link ZipFileEntry}
2004
- */
2005
- ZipFileEntry: typeof ZipFileEntry;
2006
- };
2007
-
2008
- // The error messages.
2009
- /**
2010
- * HTTP range error
2011
- */
2012
- export const ERR_HTTP_RANGE: string;
2013
- /**
2014
- * Zip format error
2015
- */
2016
- export const ERR_BAD_FORMAT: string;
2017
- /**
2018
- * End of Central Directory Record not found error
2019
- */
2020
- export const ERR_EOCDR_NOT_FOUND: string;
2021
- /**
2022
- * Zip64 End of Central Directory Locator not found error
2023
- */
2024
- export const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: string;
2025
- /**
2026
- * Central Directory not found error
2027
- */
2028
- export const ERR_CENTRAL_DIRECTORY_NOT_FOUND: string;
2029
- /**
2030
- * Local file header not found error
2031
- */
2032
- export const ERR_LOCAL_FILE_HEADER_NOT_FOUND: string;
2033
- /**
2034
- * Extra field Zip64 not found error
2035
- */
2036
- export const ERR_EXTRAFIELD_ZIP64_NOT_FOUND: string;
2037
- /**
2038
- * Encrypted entry error
2039
- */
2040
- export const ERR_ENCRYPTED: string;
2041
- /**
2042
- * Unsupported encryption error
2043
- */
2044
- export const ERR_UNSUPPORTED_ENCRYPTION: string;
2045
- /**
2046
- * Unsupported compression error
2047
- */
2048
- export const ERR_UNSUPPORTED_COMPRESSION: string;
2049
- /**
2050
- * Invalid signature error
2051
- */
2052
- export const ERR_INVALID_SIGNATURE: string;
2053
- /**
2054
- * Invalid password error
2055
- */
2056
- export const ERR_INVALID_PASSWORD: string;
2057
- /**
2058
- * Duplicate entry error
2059
- */
2060
- export const ERR_DUPLICATED_NAME: string;
2061
- /**
2062
- * Invalid comment error
2063
- */
2064
- export const ERR_INVALID_COMMENT: string;
2065
- /**
2066
- * Invalid entry name error
2067
- */
2068
- export const ERR_INVALID_ENTRY_NAME: string;
2069
- /**
2070
- * Invalid entry comment error
2071
- */
2072
- export const ERR_INVALID_ENTRY_COMMENT: string;
2073
- /**
2074
- * Invalid version error
2075
- */
2076
- export const ERR_INVALID_VERSION: string;
2077
- /**
2078
- * Invalid extra field type error
2079
- */
2080
- export const ERR_INVALID_EXTRAFIELD_TYPE: string;
2081
- /**
2082
- * Invalid extra field data error
2083
- */
2084
- export const ERR_INVALID_EXTRAFIELD_DATA: string;
2085
- /**
2086
- * Invalid encryption strength error
2087
- */
2088
- export const ERR_INVALID_ENCRYPTION_STRENGTH: string;
2089
- /**
2090
- * Invalid format error
2091
- */
2092
- export const ERR_UNSUPPORTED_FORMAT: string;
2093
- /**
2094
- * Split zip file error
2095
- */
2096
- export const ERR_SPLIT_ZIP_FILE: string;
2097
- /**
2098
- * Iteration completed too soon error
2099
- */
2100
- export const ERR_ITERATOR_COMPLETED_TOO_SOON: string;
2101
- /**
2102
- * Undefined uncompressed size error
2103
- */
2104
- export const ERR_UNDEFINED_UNCOMPRESSED_SIZE: string
2105
- /**
2106
- * Writer not initialized error
2107
- */
2108
- export const ERR_WRITER_NOT_INITIALIZED: string;