@zip.js/zip.js 2.7.61 → 2.7.63

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,7 +154,7 @@
154
154
  * }));
155
155
  * }
156
156
  * ```
157
- *
157
+ *
158
158
  * @module
159
159
  */
160
160
 
@@ -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
  /**
@@ -479,7 +479,7 @@ export interface ReadableReader {
479
479
  * this.size = this.binaryString.length;
480
480
  * }
481
481
  *
482
- * readCompatibleUint8Array(offset, length) {
482
+ * readUint8Array(offset, length) {
483
483
  * const result = new Uint8Array(length);
484
484
  * for (let indexCharacter = 0; indexCharacter < length; indexCharacter++) {
485
485
  * result[indexCharacter] = this.binaryString.charCodeAt(indexCharacter + offset) & 0xFF;
@@ -515,7 +515,7 @@ export class Reader<Type> implements Initializable, ReadableReader {
515
515
  * @param length The length of the data to read in bytes.
516
516
  * @returns A promise resolving to a chunk of data.
517
517
  */
518
- readCompatibleUint8Array(index: number, length: number): Promise<Uint8Array>;
518
+ readUint8Array(index: number, length: number): Promise<Uint8Array>;
519
519
  }
520
520
 
521
521
  /**
@@ -536,7 +536,7 @@ export class Data64URIReader extends Reader<string> { }
536
536
  /**
537
537
  * Represents a {@link Reader} instance used to read data provided as a `Uint8Array` instance.
538
538
  */
539
- export class CompatibleUint8ArrayReader 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).
@@ -638,7 +638,7 @@ export interface WritableWriter {
638
638
  */
639
639
  writable: WritableStream;
640
640
  /**
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.
641
+ * 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
642
  */
643
643
  maxSize?: number;
644
644
  }
@@ -656,7 +656,7 @@ export interface WritableWriter {
656
656
  * this.binaryString = "";
657
657
  * }
658
658
  *
659
- * writeCompatibleUint8Array(array) {
659
+ * writeUint8Array(array) {
660
660
  * for (let indexCharacter = 0; indexCharacter < array.length; indexCharacter++) {
661
661
  * this.binaryString += String.fromCharCode(array[indexCharacter]);
662
662
  * }
@@ -686,7 +686,7 @@ export class Writer<Type> implements Initializable, WritableWriter {
686
686
  *
687
687
  * @virtual
688
688
  */
689
- writeCompatibleUint8Array(array: Uint8Array): Promise<void>;
689
+ writeUint8Array(array: Uint8Array): Promise<void>;
690
690
  /**
691
691
  * Retrieves all the written data
692
692
  *
@@ -782,7 +782,7 @@ export class SplitDataWriter implements Initializable, WritableWriter {
782
782
  /**
783
783
  * Represents a {@link Writer} instance used to retrieve the written data as a `Uint8Array` instance.
784
784
  */
785
- export class CompatibleUint8ArrayWriter extends Writer<Uint8Array> { }
785
+ export class Uint8ArrayWriter extends Writer<Uint8Array> { }
786
786
 
787
787
  /**
788
788
  * Represents an instance used to create an unzipped stream.
@@ -948,7 +948,7 @@ export interface GetEntriesOptions {
948
948
  commentEncoding?: string;
949
949
  /**
950
950
  * The function called for decoding the filename and the comment of the entry.
951
- *
951
+ *
952
952
  * @param value The raw text value.
953
953
  * @param encoding The encoding of the text.
954
954
  * @returns The decoded text value or `undefined` if the raw text value should be decoded by zip.js.
@@ -957,7 +957,7 @@ export interface GetEntriesOptions {
957
957
  }
958
958
 
959
959
  /**
960
- * Represents options passed to the constructor of {@link ZipReader} and {@link Entry#getData}.
960
+ * Represents options passed to the constructor of {@link ZipReader} and {@link FileEntry#getData}.
961
961
  */
962
962
  export interface ZipReaderOptions {
963
963
  /**
@@ -989,7 +989,7 @@ export interface ZipReaderOptions {
989
989
  */
990
990
  signal?: AbortSignal;
991
991
  /**
992
- * `true` to prevent closing of {@link Writer#writable} when calling {@link Entry#getData}.
992
+ * `true` to prevent closing of {@link Writer#writable} when calling {@link FileEntry#getData}.
993
993
  *
994
994
  * @defaultValue false
995
995
  */
@@ -1140,11 +1140,13 @@ export interface EntryMetaData {
1140
1140
  */
1141
1141
  compressionMethod: number;
1142
1142
  }
1143
+ export interface DirectoryEntry extends Omit<EntryMetaData, 'directory'> {
1144
+ directory: true;
1145
+ getData?: undefined;
1146
+ }
1143
1147
 
1144
- /**
1145
- * Represents an entry with its data and metadata in a zip file (Core API).
1146
- */
1147
- export interface Entry extends EntryMetaData {
1148
+ export interface FileEntry extends Omit<EntryMetaData, 'directory'> {
1149
+ directory: false;
1148
1150
  /**
1149
1151
  * Returns the content of the entry
1150
1152
  *
@@ -1152,7 +1154,7 @@ export interface Entry extends EntryMetaData {
1152
1154
  * @param options The options.
1153
1155
  * @returns A promise resolving to the type to data associated to `writer`.
1154
1156
  */
1155
- getData?<Type>(
1157
+ getData<Type>(
1156
1158
  writer:
1157
1159
  | Writer<Type>
1158
1160
  | WritableWriter
@@ -1166,13 +1168,34 @@ export interface Entry extends EntryMetaData {
1166
1168
  }
1167
1169
 
1168
1170
  /**
1169
- * Represents the options passed to {@link Entry#getData} and `{@link ZipFileEntry}.get*`.
1171
+ * Represents an entry with its data and metadata in a zip file (Core API).
1172
+ * This is a union type of {@link DirectoryEntry} and {@link FileEntry}.
1173
+ *
1174
+ * Before using getData, you should check if the entry is a file.
1175
+ *
1176
+ * @example
1177
+ *
1178
+ * ```ts
1179
+ * for await (const entry of reader.getEntriesGenerator()) {
1180
+ * if (entry.directory) continue;
1181
+ *
1182
+ * // entry is a FileEntry
1183
+ * const plainTextData = await entry.getData(new TextWriter());
1184
+ *
1185
+ * // Do something with the plainTextData
1186
+ * }
1187
+ * ```
1188
+ */
1189
+ export type Entry = DirectoryEntry | FileEntry;
1190
+
1191
+ /**
1192
+ * Represents the options passed to {@link FileEntry#getData} and `{@link ZipFileEntry}.get*`.
1170
1193
  */
1171
1194
  export interface EntryGetDataOptions
1172
1195
  extends EntryDataOnprogressOptions, ZipReaderOptions, WorkerConfiguration { }
1173
1196
 
1174
1197
  /**
1175
- * Represents the options passed to {@link Entry#getData} and `{@link ZipFileEntry}.get*`.
1198
+ * Represents the options passed to {@link FileEntry#getData} and `{@link ZipFileEntry}.get*`.
1176
1199
  */
1177
1200
  export interface EntryGetDataCheckPasswordOptions
1178
1201
  extends EntryGetDataOptions { }
@@ -1503,7 +1526,7 @@ export interface ZipWriterConstructorOptions {
1503
1526
  versionMadeBy?: number;
1504
1527
  /**
1505
1528
  * `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
- *
1529
+ *
1507
1530
  * Note that this does not ensure that the file names are in the correct encoding.
1508
1531
  *
1509
1532
  * @defaultValue true
@@ -1571,7 +1594,7 @@ export interface ZipWriterConstructorOptions {
1571
1594
  compressionMethod?: number
1572
1595
  /**
1573
1596
  * The function called for encoding the filename and the comment of the entry.
1574
- *
1597
+ *
1575
1598
  * @param text The text to encode.
1576
1599
  * @returns The encoded text or `undefined` if the text should be encoded by zip.js.
1577
1600
  */
@@ -1579,7 +1602,7 @@ export interface ZipWriterConstructorOptions {
1579
1602
  }
1580
1603
 
1581
1604
  /**
1582
- * Represents options passed to {@link Entry#getData}, {@link ZipWriter.add} and `{@link ZipDirectory}.export*`.
1605
+ * Represents options passed to {@link FileEntry#getData}, {@link ZipWriter.add} and `{@link ZipDirectory}.export*`.
1583
1606
  */
1584
1607
  export interface EntryDataOnprogressOptions {
1585
1608
  /**
@@ -1751,7 +1774,7 @@ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
1751
1774
  * @param options The options.
1752
1775
  * @returns A promise resolving to a `Uint8Array` instance.
1753
1776
  */
1754
- getCompatibleUint8Array(options?: EntryGetDataOptions): Promise<Uint8Array>;
1777
+ getUint8Array(options?: EntryGetDataOptions): Promise<Uint8Array>;
1755
1778
  /**
1756
1779
  * Retrieves the content of the entry via a `WritableStream` instance
1757
1780
  *
@@ -1801,7 +1824,7 @@ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
1801
1824
  *
1802
1825
  * @param array The `Uint8Array` instance.
1803
1826
  */
1804
- replaceCompatibleUint8Array(array: Uint8Array): void;
1827
+ replaceUint8Array(array: Uint8Array): void;
1805
1828
  /**
1806
1829
  * Replaces the content of the entry with a `ReadableStream` instance
1807
1830
  *
@@ -1883,7 +1906,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1883
1906
  * @param options The options.
1884
1907
  * @returns A {@link ZipFileEntry} instance.
1885
1908
  */
1886
- addCompatibleUint8Array(
1909
+ addUint8Array(
1887
1910
  name: string,
1888
1911
  array: Uint8Array,
1889
1912
  options?: ZipWriterAddDataOptions,
@@ -1973,7 +1996,7 @@ export class ZipDirectoryEntry extends ZipEntry {
1973
1996
  * @param array The `Uint8Array` instance.
1974
1997
  * @param options The options.
1975
1998
  */
1976
- importCompatibleUint8Array(
1999
+ importUint8Array(
1977
2000
  array: Uint8Array,
1978
2001
  options?: ZipReaderConstructorOptions,
1979
2002
  ): Promise<[ZipEntry]>;
@@ -2033,7 +2056,7 @@ export class ZipDirectoryEntry extends ZipEntry {
2033
2056
  * @param options The options.
2034
2057
  * @returns A promise resolving to the `Uint8Array` instance.
2035
2058
  */
2036
- exportCompatibleUint8Array(
2059
+ exportUint8Array(
2037
2060
  options?: ZipDirectoryEntryExportOptions,
2038
2061
  ): Promise<Uint8Array>;
2039
2062
  /**
@@ -2261,7 +2284,7 @@ export const ERR_ITERATOR_COMPLETED_TOO_SOON: string;
2261
2284
  /**
2262
2285
  * Undefined uncompressed size error
2263
2286
  */
2264
- export const ERR_UNDEFINED_UNCOMPRESSED_SIZE: string
2287
+ export const ERR_UNDEFINED_UNCOMPRESSED_SIZE: string;
2265
2288
  /**
2266
2289
  * Writer not initialized error
2267
2290
  */