@zip.js/zip.js 2.7.62 → 2.7.64

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.
package/index.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * @author Gildas Lormeau
9
9
  * @license BSD-3-Clause
10
- *
10
+ *
11
11
  * @example
12
12
  * Hello world
13
13
  * ```js
@@ -19,39 +19,39 @@
19
19
  * ZipReader,
20
20
  * ZipWriter,
21
21
  * } from from "@zip-js/zip-js";
22
- *
22
+ *
23
23
  * // ----
24
24
  * // Write the zip file
25
25
  * // ----
26
- *
26
+ *
27
27
  * // Creates a BlobWriter object where the zip content will be written.
28
28
  * const zipFileWriter = new BlobWriter();
29
- *
29
+ *
30
30
  * // Creates a TextReader object storing the text of the entry to add in the zip
31
31
  * // (i.e. "Hello world!").
32
32
  * const helloWorldReader = new TextReader("Hello world!");
33
- *
33
+ *
34
34
  * // Creates a ZipWriter object writing data via `zipFileWriter`, adds the entry
35
35
  * // "hello.txt" containing the text "Hello world!" via `helloWorldReader`, and
36
36
  * // closes the writer.
37
37
  * const zipWriter = new ZipWriter(zipFileWriter);
38
38
  * await zipWriter.add("hello.txt", helloWorldReader);
39
39
  * await zipWriter.close();
40
- *
40
+ *
41
41
  * // Retrieves the Blob object containing the zip content into `zipFileBlob`. It
42
42
  * // is also returned by zipWriter.close() for more convenience.
43
43
  * const zipFileBlob = await zipFileWriter.getData();
44
- *
44
+ *
45
45
  * // ----
46
46
  * // Read the zip file
47
47
  * // ----
48
- *
48
+ *
49
49
  * // Creates a BlobReader object used to read `zipFileBlob`.
50
50
  * const zipFileReader = new BlobReader(zipFileBlob);
51
51
  * // Creates a TextWriter object where the content of the first entry in the zip
52
52
  * // will be written.
53
53
  * const helloWorldWriter = new TextWriter();
54
- *
54
+ *
55
55
  * // Creates a ZipReader object reading the zip content via `zipFileReader`,
56
56
  * // retrieves metadata (name, dates, etc.) of the first entry, retrieves its
57
57
  * // content via `helloWorldWriter`, and closes the reader.
@@ -59,11 +59,11 @@
59
59
  * const firstEntry = (await zipReader.getEntries()).shift();
60
60
  * const helloWorldText = await firstEntry.getData(helloWorldWriter);
61
61
  * await zipReader.close();
62
- *
62
+ *
63
63
  * // Displays "Hello world!".
64
64
  * console.log(helloWorldText);
65
65
  * ```
66
- *
66
+ *
67
67
  * @example
68
68
  * Hello world with Streams
69
69
  * ```js
@@ -72,11 +72,11 @@
72
72
  * ZipReader,
73
73
  * ZipWriter,
74
74
  * } from "@zip-js/zip-js";
75
- *
75
+ *
76
76
  * // ----
77
77
  * // Write the zip file
78
78
  * // ----
79
- *
79
+ *
80
80
  * // Creates a TransformStream object, the zip content will be written in the
81
81
  * // `writable` property.
82
82
  * const zipFileStream = new TransformStream();
@@ -86,21 +86,21 @@
86
86
  * // Creates a ReadableStream object storing the text of the entry to add in the
87
87
  * // zip (i.e. "Hello world!").
88
88
  * const helloWorldReadable = new Blob(["Hello world!"]).stream();
89
- *
89
+ *
90
90
  * // Creates a ZipWriter object writing data into `zipFileStream.writable`, adds
91
91
  * // the entry "hello.txt" containing the text "Hello world!" retrieved from
92
92
  * // `helloWorldReadable`, and closes the writer.
93
93
  * const zipWriter = new ZipWriter(zipFileStream.writable);
94
94
  * await zipWriter.add("hello.txt", helloWorldReadable);
95
95
  * await zipWriter.close();
96
- *
96
+ *
97
97
  * // Retrieves the Blob object containing the zip content into `zipFileBlob`.
98
98
  * const zipFileBlob = await zipFileBlobPromise;
99
- *
99
+ *
100
100
  * // ----
101
101
  * // Read the zip file
102
102
  * // ----
103
- *
103
+ *
104
104
  * // Creates a BlobReader object used to read `zipFileBlob`.
105
105
  * const zipFileReader = new BlobReader(zipFileBlob);
106
106
  * // Creates a TransformStream object, the content of the first entry in the zip
@@ -109,7 +109,7 @@
109
109
  * // Creates a Promise object resolved to the content of the first entry returned
110
110
  * // as text from `helloWorldStream.readable`.
111
111
  * const helloWorldTextPromise = new Response(helloWorldStream.readable).text();
112
- *
112
+ *
113
113
  * // Creates a ZipReader object reading the zip content via `zipFileReader`,
114
114
  * // retrieves metadata (name, dates, etc.) of the first entry, retrieves its
115
115
  * // content into `helloWorldStream.writable`, and closes the reader.
@@ -117,12 +117,12 @@
117
117
  * const firstEntry = (await zipReader.getEntries()).shift();
118
118
  * await firstEntry.getData(helloWorldStream.writable);
119
119
  * await zipReader.close();
120
- *
120
+ *
121
121
  * // Displays "Hello world!".
122
122
  * const helloWorldText = await helloWorldTextPromise;
123
123
  * console.log(helloWorldText);
124
124
  * ```
125
- *
125
+ *
126
126
  * @example
127
127
  * Adding concurrently multiple entries in a zip file
128
128
  * ```js
@@ -132,11 +132,11 @@
132
132
  * TextReader,
133
133
  * ZipWriter,
134
134
  * } from "@zip-js/zip-js";
135
- *
135
+ *
136
136
  * const README_URL = "https://unpkg.com/@zip.js/zip.js/README.md";
137
137
  * getZipFileBlob()
138
138
  * .then(downloadFile);
139
- *
139
+ *
140
140
  * async function getZipFileBlob() {
141
141
  * const zipWriter = new ZipWriter(new BlobWriter("application/zip"));
142
142
  * await Promise.all([
@@ -145,7 +145,7 @@
145
145
  * ]);
146
146
  * return zipWriter.close();
147
147
  * }
148
- *
148
+ *
149
149
  * function downloadFile(blob) {
150
150
  * document.body.appendChild(Object.assign(document.createElement("a"), {
151
151
  * download: "hello.zip",
@@ -154,9 +154,9 @@
154
154
  * }));
155
155
  * }
156
156
  * ```
157
- *
157
+ *
158
158
  * @module
159
- */
159
+ */
160
160
 
161
161
  /**
162
162
  * Represents the `FileSystemEntry` class.
@@ -164,7 +164,7 @@
164
164
  * @see {@link https://wicg.github.io/entries-api/#api-entry|specification}
165
165
  */
166
166
  // deno-lint-ignore no-empty-interface
167
- interface FileSystemEntryLike { }
167
+ interface FileSystemEntryLike {}
168
168
 
169
169
  /**
170
170
  * Represents the `FileSystemHandle` class.
@@ -172,7 +172,7 @@ interface FileSystemEntryLike { }
172
172
  * @see {@link https://fs.spec.whatwg.org/#api-filesystemhandle}
173
173
  */
174
174
  // deno-lint-ignore no-empty-interface
175
- interface FileSystemHandleLike { }
175
+ interface FileSystemHandleLike {}
176
176
 
177
177
  /**
178
178
  * Represents a generic `TransformStream` class.
@@ -286,7 +286,7 @@ export interface Configuration extends WorkerConfiguration {
286
286
  }
287
287
 
288
288
  /**
289
- * Represents configuration passed to {@link configure}, the constructor of {@link ZipReader}, {@link Entry#getData}, the constructor of {@link ZipWriter}, and {@link ZipWriter#add}.
289
+ * Represents configuration passed to {@link configure}, the constructor of {@link ZipReader}, {@link FileEntry#getData}, the constructor of {@link ZipWriter}, and {@link ZipWriter#add}.
290
290
  */
291
291
  export interface WorkerConfiguration {
292
292
  /**
@@ -314,7 +314,7 @@ export interface WorkerConfiguration {
314
314
  export function initShimAsyncCodec(
315
315
  library: EventBasedZipLibrary,
316
316
  constructorOptions: unknown | null,
317
- registerDataHandler: registerDataHandler,
317
+ registerDataHandler: registerDataHandler
318
318
  ): ZipLibrary;
319
319
 
320
320
  /**
@@ -428,7 +428,7 @@ declare class ZipInflate extends SyncCodec {
428
428
  /**
429
429
  * Represents a class implementing `CompressionStream` or `DecompressionStream` interfaces.
430
430
  */
431
- declare class CodecStream extends TransformStream { }
431
+ declare class CodecStream extends TransformStream {}
432
432
 
433
433
  /**
434
434
  * Returns the MIME type corresponding to a filename extension.
@@ -521,40 +521,41 @@ export class Reader<Type> implements Initializable, ReadableReader {
521
521
  /**
522
522
  * Represents a {@link Reader} instance used to read data provided as a `string`.
523
523
  */
524
- export class TextReader extends Reader<string> { }
524
+ export class TextReader extends Reader<string> {}
525
525
 
526
526
  /**
527
527
  * Represents a {@link Reader} instance used to read data provided as a `Blob` instance.
528
528
  */
529
- export class BlobReader extends Reader<Blob> { }
529
+ export class BlobReader extends Reader<Blob> {}
530
530
 
531
531
  /**
532
532
  * Represents a {@link Reader} instance used to read data provided as a Data URI `string` encoded in Base64.
533
533
  */
534
- export class Data64URIReader extends Reader<string> { }
534
+ export class Data64URIReader extends Reader<string> {}
535
535
 
536
536
  /**
537
537
  * Represents a {@link Reader} instance used to read data provided as a `Uint8Array` instance.
538
538
  */
539
- export class Uint8ArrayReader extends Reader<Uint8Array> { }
539
+ export class Uint8ArrayReader extends Reader<Uint8Array> {}
540
540
 
541
541
  /**
542
542
  * Represents a {@link Reader} instance used to read data provided as an array of {@link ReadableReader} instances (e.g. split zip files).
543
543
  *
544
544
  * @deprecated Use {@link SplitDataReader} instead.
545
545
  */
546
- export class SplitZipReader extends SplitDataReader { }
546
+ export class SplitZipReader extends SplitDataReader {}
547
547
 
548
548
  /**
549
549
  * Represents a {@link Reader} instance used to read data provided as an array of {@link ReadableReader} instances (e.g. split zip files).
550
550
  */
551
- export class SplitDataReader
552
- extends Reader<Reader<unknown>[] | ReadableReader[] | ReadableStream[]> { }
551
+ export class SplitDataReader extends Reader<
552
+ Reader<unknown>[] | ReadableReader[] | ReadableStream[]
553
+ > {}
553
554
 
554
555
  /**
555
556
  * Represents a URL stored into a `string`.
556
557
  */
557
- interface URLString extends String { }
558
+ interface URLString extends String {}
558
559
 
559
560
  /**
560
561
  * Represents a {@link Reader} instance used to fetch data from a URL.
@@ -638,7 +639,7 @@ export interface WritableWriter {
638
639
  */
639
640
  writable: WritableStream;
640
641
  /**
641
- * 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.
642
+ * The maximum size of split data when creating a {@link ZipWriter} instance or when calling {@link FileEntry#getData} with a generator of {@link WritableWriter} instances.
642
643
  */
643
644
  maxSize?: number;
644
645
  }
@@ -750,7 +751,7 @@ export class Data64URIWriter extends Writer<string> {
750
751
  *
751
752
  * @deprecated Use {@link SplitDataWriter} instead.
752
753
  */
753
- export class SplitZipWriter extends SplitDataWriter { }
754
+ export class SplitZipWriter extends SplitDataWriter {}
754
755
 
755
756
  /**
756
757
  * Represents a {@link Writer} instance used to retrieve the written data from a generator of {@link WritableWriter} instances (i.e. split zip files).
@@ -775,14 +776,14 @@ export class SplitDataWriter implements Initializable, WritableWriter {
775
776
  Writer<unknown> | WritableWriter | WritableStream,
776
777
  boolean
777
778
  >,
778
- maxSize?: number,
779
+ maxSize?: number
779
780
  );
780
781
  }
781
782
 
782
783
  /**
783
784
  * Represents a {@link Writer} instance used to retrieve the written data as a `Uint8Array` instance.
784
785
  */
785
- export class Uint8ArrayWriter extends Writer<Uint8Array> { }
786
+ export class Uint8ArrayWriter extends Writer<Uint8Array> {}
786
787
 
787
788
  /**
788
789
  * Represents an instance used to create an unzipped stream.
@@ -873,7 +874,7 @@ export class ZipReader<Type> {
873
874
  | Reader<unknown>[]
874
875
  | ReadableReader[]
875
876
  | ReadableStream[],
876
- options?: ZipReaderConstructorOptions,
877
+ options?: ZipReaderConstructorOptions
877
878
  );
878
879
  /**
879
880
  * The global comment of the zip file.
@@ -901,7 +902,7 @@ export class ZipReader<Type> {
901
902
  * @returns An asynchronous generator of {@link Entry} instances.
902
903
  */
903
904
  getEntriesGenerator(
904
- options?: ZipReaderGetEntriesOptions,
905
+ options?: ZipReaderGetEntriesOptions
905
906
  ): AsyncGenerator<Entry, boolean>;
906
907
  /**
907
908
  * Closes the zip file
@@ -913,7 +914,9 @@ export class ZipReader<Type> {
913
914
  * Represents the options passed to the constructor of {@link ZipReader}, and `{@link ZipDirectory}#import*`.
914
915
  */
915
916
  export interface ZipReaderConstructorOptions
916
- extends ZipReaderOptions, GetEntriesOptions, WorkerConfiguration {
917
+ extends ZipReaderOptions,
918
+ GetEntriesOptions,
919
+ WorkerConfiguration {
917
920
  /**
918
921
  * `true` to extract the prepended data into {@link ZipReader#prependedData}.
919
922
  *
@@ -932,7 +935,8 @@ export interface ZipReaderConstructorOptions
932
935
  * Represents the options passed to {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
933
936
  */
934
937
  export interface ZipReaderGetEntriesOptions
935
- extends GetEntriesOptions, EntryOnprogressOptions { }
938
+ extends GetEntriesOptions,
939
+ EntryOnprogressOptions {}
936
940
 
937
941
  /**
938
942
  * Represents options passed to the constructor of {@link ZipReader}, {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
@@ -948,7 +952,7 @@ export interface GetEntriesOptions {
948
952
  commentEncoding?: string;
949
953
  /**
950
954
  * The function called for decoding the filename and the comment of the entry.
951
- *
955
+ *
952
956
  * @param value The raw text value.
953
957
  * @param encoding The encoding of the text.
954
958
  * @returns The decoded text value or `undefined` if the raw text value should be decoded by zip.js.
@@ -957,7 +961,7 @@ export interface GetEntriesOptions {
957
961
  }
958
962
 
959
963
  /**
960
- * Represents options passed to the constructor of {@link ZipReader} and {@link Entry#getData}.
964
+ * Represents options passed to the constructor of {@link ZipReader} and {@link FileEntry#getData}.
961
965
  */
962
966
  export interface ZipReaderOptions {
963
967
  /**
@@ -989,7 +993,7 @@ export interface ZipReaderOptions {
989
993
  */
990
994
  signal?: AbortSignal;
991
995
  /**
992
- * `true` to prevent closing of {@link Writer#writable} when calling {@link Entry#getData}.
996
+ * `true` to prevent closing of {@link Writer#writable} when calling {@link FileEntry#getData}.
993
997
  *
994
998
  * @defaultValue false
995
999
  */
@@ -1089,7 +1093,7 @@ export interface EntryMetaData {
1089
1093
  /**
1090
1094
  * The extra field.
1091
1095
  */
1092
- extraField?: Map<number, { type: number, data: Uint8Array }>;
1096
+ extraField?: Map<number, { type: number; data: Uint8Array }>;
1093
1097
  /**
1094
1098
  * The extra field (raw).
1095
1099
  */
@@ -1140,11 +1144,13 @@ export interface EntryMetaData {
1140
1144
  */
1141
1145
  compressionMethod: number;
1142
1146
  }
1147
+ export interface DirectoryEntry extends Omit<EntryMetaData, "directory"> {
1148
+ directory: true;
1149
+ getData?: undefined;
1150
+ }
1143
1151
 
1144
- /**
1145
- * Represents an entry with its data and metadata in a zip file (Core API).
1146
- */
1147
- export interface Entry extends EntryMetaData {
1152
+ export interface FileEntry extends Omit<EntryMetaData, "directory"> {
1153
+ directory: false;
1148
1154
  /**
1149
1155
  * Returns the content of the entry
1150
1156
  *
@@ -1152,30 +1158,52 @@ export interface Entry extends EntryMetaData {
1152
1158
  * @param options The options.
1153
1159
  * @returns A promise resolving to the type to data associated to `writer`.
1154
1160
  */
1155
- getData?<Type>(
1161
+ getData<Type>(
1156
1162
  writer:
1157
1163
  | Writer<Type>
1158
1164
  | WritableWriter
1159
1165
  | WritableStream
1160
1166
  | AsyncGenerator<
1161
- Writer<unknown> | WritableWriter | WritableStream,
1162
- boolean
1163
- >,
1167
+ Writer<unknown> | WritableWriter | WritableStream,
1168
+ boolean
1169
+ >,
1164
1170
  options?: EntryGetDataCheckPasswordOptions
1165
1171
  ): Promise<Type>;
1166
1172
  }
1167
1173
 
1168
1174
  /**
1169
- * Represents the options passed to {@link Entry#getData} and `{@link ZipFileEntry}.get*`.
1175
+ * Represents an entry with its data and metadata in a zip file (Core API).
1176
+ * This is a union type of {@link DirectoryEntry} and {@link FileEntry}.
1177
+ *
1178
+ * Before using getData, you should check if the entry is a file.
1179
+ *
1180
+ * @example
1181
+ *
1182
+ * ```ts
1183
+ * for await (const entry of reader.getEntriesGenerator()) {
1184
+ * if (entry.directory) continue;
1185
+ *
1186
+ * // entry is a FileEntry
1187
+ * const plainTextData = await entry.getData(new TextWriter());
1188
+ *
1189
+ * // Do something with the plainTextData
1190
+ * }
1191
+ * ```
1192
+ */
1193
+ export type Entry = DirectoryEntry | FileEntry;
1194
+
1195
+ /**
1196
+ * Represents the options passed to {@link FileEntry#getData} and `{@link ZipFileEntry}.get*`.
1170
1197
  */
1171
1198
  export interface EntryGetDataOptions
1172
- extends EntryDataOnprogressOptions, ZipReaderOptions, WorkerConfiguration { }
1199
+ extends EntryDataOnprogressOptions,
1200
+ ZipReaderOptions,
1201
+ WorkerConfiguration {}
1173
1202
 
1174
1203
  /**
1175
- * Represents the options passed to {@link Entry#getData} and `{@link ZipFileEntry}.get*`.
1204
+ * Represents the options passed to {@link FileEntry#getData} and `{@link ZipFileEntry}.get*`.
1176
1205
  */
1177
- export interface EntryGetDataCheckPasswordOptions
1178
- extends EntryGetDataOptions { }
1206
+ export interface EntryGetDataCheckPasswordOptions extends EntryGetDataOptions {}
1179
1207
 
1180
1208
  /**
1181
1209
  * Represents an instance used to create a zipped stream.
@@ -1237,9 +1265,10 @@ export class ZipWriterStream {
1237
1265
  * @param path The name of the stream when unzipped.
1238
1266
  * @returns An object containing readable and writable properties
1239
1267
  */
1240
- transform<T>(
1241
- path: string,
1242
- ): { readable: ReadableStream<T>; writable: WritableStream<T> };
1268
+ transform<T>(path: string): {
1269
+ readable: ReadableStream<T>;
1270
+ writable: WritableStream<T>;
1271
+ };
1243
1272
 
1244
1273
  /**
1245
1274
  * Returns a WritableStream for the .pipeTo method
@@ -1258,7 +1287,7 @@ export class ZipWriterStream {
1258
1287
  */
1259
1288
  close(
1260
1289
  comment?: Uint8Array,
1261
- options?: ZipWriterCloseOptions,
1290
+ options?: ZipWriterCloseOptions
1262
1291
  ): Promise<unknown>;
1263
1292
  }
1264
1293
 
@@ -1295,15 +1324,33 @@ export class ZipWriter<Type> {
1295
1324
  | WritableWriter
1296
1325
  | WritableStream
1297
1326
  | AsyncGenerator<
1298
- Writer<unknown> | WritableWriter | WritableStream,
1299
- boolean
1300
- >,
1301
- options?: ZipWriterConstructorOptions,
1327
+ Writer<unknown> | WritableWriter | WritableStream,
1328
+ boolean
1329
+ >,
1330
+ options?: ZipWriterConstructorOptions
1302
1331
  );
1303
1332
  /**
1304
1333
  * `true` if the zip contains at least one entry that has been partially written.
1305
1334
  */
1306
1335
  readonly hasCorruptedEntries?: boolean;
1336
+
1337
+ /**
1338
+ * Adds an existing zip file at the beginning of the current zip. This method
1339
+ * cannot be called after the first call to {@link ZipWriter#add}.
1340
+ *
1341
+ * @param reader The {@link Reader} instance used to read the content of the zip file.
1342
+ * @returns A promise resolving when the zip file has been added.
1343
+ */
1344
+ prependZip<ReaderType>(
1345
+ reader:
1346
+ | Reader<ReaderType>
1347
+ | ReadableReader
1348
+ | ReadableStream
1349
+ | Reader<unknown>[]
1350
+ | ReadableReader[]
1351
+ | ReadableStream[]
1352
+ ): Promise<void>;
1353
+
1307
1354
  /**
1308
1355
  * Adds an entry into the zip file
1309
1356
  *
@@ -1321,8 +1368,18 @@ export class ZipWriter<Type> {
1321
1368
  | Reader<unknown>[]
1322
1369
  | ReadableReader[]
1323
1370
  | ReadableStream[],
1324
- options?: ZipWriterAddDataOptions,
1371
+ options?: ZipWriterAddDataOptions
1325
1372
  ): Promise<EntryMetaData>;
1373
+
1374
+ /**
1375
+ * Removes an entry from the zip file. Note that the entry is not removed from the zip file, but it
1376
+ * is not written to the entries directory.
1377
+ *
1378
+ * @param entry The entry to remove. This can be an {@link Entry} instance or the filename of the entry.
1379
+ * @returns `true` if the entry has been removed, `false` otherwise.
1380
+ */
1381
+ remove(entry: Entry | string): boolean;
1382
+
1326
1383
  /**
1327
1384
  * Writes the entries directory, writes the global comment, and returns the content of the zip file
1328
1385
  *
@@ -1337,10 +1394,9 @@ export class ZipWriter<Type> {
1337
1394
  * Represents the options passed to {@link ZipWriter#add}.
1338
1395
  */
1339
1396
  export interface ZipWriterAddDataOptions
1340
- extends
1341
- ZipWriterConstructorOptions,
1342
- EntryDataOnprogressOptions,
1343
- WorkerConfiguration {
1397
+ extends ZipWriterConstructorOptions,
1398
+ EntryDataOnprogressOptions,
1399
+ WorkerConfiguration {
1344
1400
  /**
1345
1401
  * `true` if the entry is a directory.
1346
1402
  *
@@ -1484,7 +1540,8 @@ export interface ZipWriterConstructorOptions {
1484
1540
  */
1485
1541
  extendedTimestamp?: boolean;
1486
1542
  /**
1487
- * `true` to use the ZipCrypto algorithm to encrypt the content of the entry.
1543
+ * `true` to use the ZipCrypto algorithm to encrypt the content of the entry. Setting it to `true` will also
1544
+ * set the {@link ZipWriterConstructorOptions#dataDescriptor} to `true`.
1488
1545
  *
1489
1546
  * It is not recommended to set `zipCrypto` to `true` because the ZipCrypto encryption can be easily broken.
1490
1547
  *
@@ -1502,8 +1559,9 @@ export interface ZipWriterConstructorOptions {
1502
1559
  */
1503
1560
  versionMadeBy?: number;
1504
1561
  /**
1505
- * `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.
1506
- *
1562
+ * `true` to mark the file names as UTF-8 setting the general purpose bit 11 in the header (see Appendix D -
1563
+ * Language Encoding (EFS)), `false` to mark the names as compliant with the original IBM Code Page 437.
1564
+ *
1507
1565
  * Note that this does not ensure that the file names are in the correct encoding.
1508
1566
  *
1509
1567
  * @defaultValue true
@@ -1512,9 +1570,10 @@ export interface ZipWriterConstructorOptions {
1512
1570
  /**
1513
1571
  * `true` to add a data descriptor.
1514
1572
  *
1515
- * When set to `false`, the {@link ZipWriterConstructorOptions#bufferedWrite} option will automatically be set to `true`.
1516
- *
1517
- * @defaultValue true
1573
+ * When set to `false`, the {@link ZipWriterConstructorOptions#bufferedWrite} option will automatically be
1574
+ * set to `true`. It will be automatically set to `false` when it is `undefined` and the
1575
+ * {@link ZipWriterConstructorOptions#bufferedWrite} option is set to `true`, or ` when the
1576
+ * {@link ZipWriterConstructorOptions#zipCrypto} option is set to `true`. Otherwise, the default value is `true`.
1518
1577
  */
1519
1578
  dataDescriptor?: boolean;
1520
1579
  /**
@@ -1568,10 +1627,10 @@ export interface ZipWriterConstructorOptions {
1568
1627
  /**
1569
1628
  * The compression method (e.g. 8 for DEFLATE, 0 for STORE).
1570
1629
  */
1571
- compressionMethod?: number
1630
+ compressionMethod?: number;
1572
1631
  /**
1573
1632
  * The function called for encoding the filename and the comment of the entry.
1574
- *
1633
+ *
1575
1634
  * @param text The text to encode.
1576
1635
  * @returns The encoded text or `undefined` if the text should be encoded by zip.js.
1577
1636
  */
@@ -1579,7 +1638,7 @@ export interface ZipWriterConstructorOptions {
1579
1638
  }
1580
1639
 
1581
1640
  /**
1582
- * Represents options passed to {@link Entry#getData}, {@link ZipWriter.add} and `{@link ZipDirectory}.export*`.
1641
+ * Represents options passed to {@link FileEntry#getData}, {@link ZipWriter.add} and `{@link ZipDirectory}.export*`.
1583
1642
  */
1584
1643
  export interface EntryDataOnprogressOptions {
1585
1644
  /**
@@ -1621,7 +1680,7 @@ export interface EntryOnprogressOptions {
1621
1680
  onprogress?(
1622
1681
  progress: number,
1623
1682
  total: number,
1624
- entry: EntryMetaData,
1683
+ entry: EntryMetaData
1625
1684
  ): Promise<void> | undefined;
1626
1685
  }
1627
1686
 
@@ -1682,7 +1741,7 @@ declare class ZipEntry {
1682
1741
  */
1683
1742
  checkPassword(
1684
1743
  password: string,
1685
- options?: EntryGetDataOptions,
1744
+ options?: EntryGetDataOptions
1686
1745
  ): Promise<boolean>;
1687
1746
  /**
1688
1747
  * Set the name of the entry
@@ -1743,7 +1802,7 @@ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
1743
1802
  */
1744
1803
  getData64URI(
1745
1804
  mimeType?: string,
1746
- options?: EntryGetDataOptions,
1805
+ options?: EntryGetDataOptions
1747
1806
  ): Promise<string>;
1748
1807
  /**
1749
1808
  * Retrieves the content of the entry as a `Uint8Array` instance
@@ -1761,7 +1820,7 @@ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
1761
1820
  */
1762
1821
  getWritable(
1763
1822
  writable?: WritableStream,
1764
- options?: EntryGetDataOptions,
1823
+ options?: EntryGetDataOptions
1765
1824
  ): Promise<WritableStream>;
1766
1825
  /**
1767
1826
  * Retrieves the content of the entry via a {@link Writer} instance
@@ -1776,7 +1835,7 @@ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
1776
1835
  | WritableWriter
1777
1836
  | WritableStream
1778
1837
  | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>,
1779
- options?: EntryGetDataOptions,
1838
+ options?: EntryGetDataOptions
1780
1839
  ): Promise<unknown>;
1781
1840
  /**
1782
1841
  * Replaces the content of the entry with a `Blob` instance
@@ -1834,7 +1893,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1834
1893
  */
1835
1894
  addDirectory(
1836
1895
  name: string,
1837
- options?: ZipWriterAddDataOptions,
1896
+ options?: ZipWriterAddDataOptions
1838
1897
  ): ZipDirectoryEntry;
1839
1898
  /**
1840
1899
  * Adds an entry with content provided as text
@@ -1847,7 +1906,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1847
1906
  addText(
1848
1907
  name: string,
1849
1908
  text: string,
1850
- options?: ZipWriterAddDataOptions,
1909
+ options?: ZipWriterAddDataOptions
1851
1910
  ): ZipFileEntry<string, string>;
1852
1911
  /**
1853
1912
  * Adds a entry entry with content provided as a `Blob` instance
@@ -1860,7 +1919,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1860
1919
  addBlob(
1861
1920
  name: string,
1862
1921
  blob: Blob,
1863
- options?: ZipWriterAddDataOptions,
1922
+ options?: ZipWriterAddDataOptions
1864
1923
  ): ZipFileEntry<Blob, Blob>;
1865
1924
  /**
1866
1925
  * Adds a entry entry with content provided as a Data URI `string` encoded in Base64
@@ -1873,7 +1932,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1873
1932
  addData64URI(
1874
1933
  name: string,
1875
1934
  dataURI: string,
1876
- options?: ZipWriterAddDataOptions,
1935
+ options?: ZipWriterAddDataOptions
1877
1936
  ): ZipFileEntry<string, string>;
1878
1937
  /**
1879
1938
  * Adds an entry with content provided as a `Uint8Array` instance
@@ -1886,7 +1945,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1886
1945
  addUint8Array(
1887
1946
  name: string,
1888
1947
  array: Uint8Array,
1889
- options?: ZipWriterAddDataOptions,
1948
+ options?: ZipWriterAddDataOptions
1890
1949
  ): ZipFileEntry<Uint8Array, Uint8Array>;
1891
1950
  /**
1892
1951
  * Adds an entry with content fetched from a URL
@@ -1899,7 +1958,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1899
1958
  addHttpContent(
1900
1959
  name: string,
1901
1960
  url: string,
1902
- options?: HttpOptions & ZipWriterAddDataOptions,
1961
+ options?: HttpOptions & ZipWriterAddDataOptions
1903
1962
  ): ZipFileEntry<string, void>;
1904
1963
  /**
1905
1964
  * Adds a entry entry with content provided via a `ReadableStream` instance
@@ -1912,7 +1971,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1912
1971
  addReadable(
1913
1972
  name: string,
1914
1973
  readable: ReadableStream,
1915
- options?: ZipWriterAddDataOptions,
1974
+ options?: ZipWriterAddDataOptions
1916
1975
  ): ZipFileEntry<ReadableStream, void>;
1917
1976
  /**
1918
1977
  * Adds an entry with content provided via a `File` instance
@@ -1921,10 +1980,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1921
1980
  * @param options The options.
1922
1981
  * @returns A promise resolving to a {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance.
1923
1982
  */
1924
- addFile(
1925
- file: File,
1926
- options?: ZipWriterAddDataOptions,
1927
- ): Promise<ZipEntry>;
1983
+ addFile(file: File, options?: ZipWriterAddDataOptions): Promise<ZipEntry>;
1928
1984
  /**
1929
1985
  * Adds an entry with content provided via a `FileSystemEntry` instance
1930
1986
  *
@@ -1934,7 +1990,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1934
1990
  */
1935
1991
  addFileSystemEntry(
1936
1992
  fileSystemEntry: FileSystemEntryLike,
1937
- options?: ZipWriterAddDataOptions,
1993
+ options?: ZipWriterAddDataOptions
1938
1994
  ): Promise<ZipEntry[]>;
1939
1995
  /**
1940
1996
  * Adds an entry with content provided via a `FileSystemHandle` instance
@@ -1945,7 +2001,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1945
2001
  */
1946
2002
  addFileSystemHandle(
1947
2003
  fileSystemHandle: FileSystemHandleLike,
1948
- options?: ZipWriterAddDataOptions,
2004
+ options?: ZipWriterAddDataOptions
1949
2005
  ): Promise<ZipEntry[]>;
1950
2006
  /**
1951
2007
  * Extracts a zip file provided as a `Blob` instance into the entry
@@ -1955,7 +2011,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1955
2011
  */
1956
2012
  importBlob(
1957
2013
  blob: Blob,
1958
- options?: ZipReaderConstructorOptions,
2014
+ options?: ZipReaderConstructorOptions
1959
2015
  ): Promise<[ZipEntry]>;
1960
2016
  /**
1961
2017
  * Extracts a zip file provided as a Data URI `string` encoded in Base64 into the entry
@@ -1965,7 +2021,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1965
2021
  */
1966
2022
  importData64URI(
1967
2023
  dataURI: string,
1968
- options?: ZipReaderConstructorOptions,
2024
+ options?: ZipReaderConstructorOptions
1969
2025
  ): Promise<[ZipEntry]>;
1970
2026
  /**
1971
2027
  * Extracts a zip file provided as a `Uint8Array` instance into the entry
@@ -1975,7 +2031,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1975
2031
  */
1976
2032
  importUint8Array(
1977
2033
  array: Uint8Array,
1978
- options?: ZipReaderConstructorOptions,
2034
+ options?: ZipReaderConstructorOptions
1979
2035
  ): Promise<[ZipEntry]>;
1980
2036
  /**
1981
2037
  * Extracts a zip file fetched from a URL into the entry
@@ -1985,7 +2041,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1985
2041
  */
1986
2042
  importHttpContent(
1987
2043
  url: string,
1988
- options?: ZipDirectoryEntryImportHttpOptions,
2044
+ options?: ZipDirectoryEntryImportHttpOptions
1989
2045
  ): Promise<[ZipEntry]>;
1990
2046
  /**
1991
2047
  * Extracts a zip file provided via a `ReadableStream` instance into the entry
@@ -1995,7 +2051,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1995
2051
  */
1996
2052
  importReadable(
1997
2053
  readable: ReadableStream,
1998
- options?: ZipReaderConstructorOptions,
2054
+ options?: ZipReaderConstructorOptions
1999
2055
  ): Promise<[ZipEntry]>;
2000
2056
  /**
2001
2057
  * Extracts a zip file provided via a custom {@link Reader} instance into the entry
@@ -2011,7 +2067,7 @@ export class ZipDirectoryEntry extends ZipEntry {
2011
2067
  | Reader<unknown>[]
2012
2068
  | ReadableReader[]
2013
2069
  | ReadableStream[],
2014
- options?: ZipReaderConstructorOptions,
2070
+ options?: ZipReaderConstructorOptions
2015
2071
  ): Promise<[ZipEntry]>;
2016
2072
  /**
2017
2073
  * Returns a `Blob` instance containing a zip file of the entry and its descendants
@@ -2034,7 +2090,7 @@ export class ZipDirectoryEntry extends ZipEntry {
2034
2090
  * @returns A promise resolving to the `Uint8Array` instance.
2035
2091
  */
2036
2092
  exportUint8Array(
2037
- options?: ZipDirectoryEntryExportOptions,
2093
+ options?: ZipDirectoryEntryExportOptions
2038
2094
  ): Promise<Uint8Array>;
2039
2095
  /**
2040
2096
  * Creates a zip file via a `WritableStream` instance containing the entry and its descendants
@@ -2045,7 +2101,7 @@ export class ZipDirectoryEntry extends ZipEntry {
2045
2101
  */
2046
2102
  exportWritable(
2047
2103
  writable?: WritableStream,
2048
- options?: ZipDirectoryEntryExportOptions,
2104
+ options?: ZipDirectoryEntryExportOptions
2049
2105
  ): Promise<WritableStream>;
2050
2106
  /**
2051
2107
  * Creates a zip file via a custom {@link Writer} instance containing the entry and its descendants
@@ -2060,7 +2116,7 @@ export class ZipDirectoryEntry extends ZipEntry {
2060
2116
  | WritableWriter
2061
2117
  | WritableStream
2062
2118
  | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>,
2063
- options?: ZipDirectoryEntryExportOptions,
2119
+ options?: ZipDirectoryEntryExportOptions
2064
2120
  ): Promise<unknown>;
2065
2121
  }
2066
2122
 
@@ -2068,13 +2124,15 @@ export class ZipDirectoryEntry extends ZipEntry {
2068
2124
  * Represents the options passed to {@link ZipDirectoryEntry#importHttpContent}.
2069
2125
  */
2070
2126
  export interface ZipDirectoryEntryImportHttpOptions
2071
- extends ZipReaderConstructorOptions, HttpOptions { }
2127
+ extends ZipReaderConstructorOptions,
2128
+ HttpOptions {}
2072
2129
 
2073
2130
  /**
2074
2131
  * Represents the options passed to `{@link ZipDirectoryEntry}#export*()`.
2075
2132
  */
2076
2133
  export interface ZipDirectoryEntryExportOptions
2077
- extends ZipWriterConstructorOptions, EntryDataOnprogressOptions {
2134
+ extends ZipWriterConstructorOptions,
2135
+ EntryDataOnprogressOptions {
2078
2136
  /**
2079
2137
  * `true` to use filenames relative to the entry instead of full filenames.
2080
2138
  */
@@ -2266,3 +2324,7 @@ export const ERR_UNDEFINED_UNCOMPRESSED_SIZE: string;
2266
2324
  * Writer not initialized error
2267
2325
  */
2268
2326
  export const ERR_WRITER_NOT_INITIALIZED: string;
2327
+ /**
2328
+ * Zip file not empty error
2329
+ */
2330
+ export const ERR_ZIP_NOT_EMPTY: string;