@@ -15,6 +15,14 @@ interface JSZipSupport {
1515
1616type Compression = 'STORE' | 'DEFLATE' ;
1717
18+ /**
19+ * Depends on the compression type. With `STORE` (no compression), these options are ignored. With
20+ * `DEFLATE`, you can give the compression level between 1 (best speed) and 9 (best compression).
21+ */
22+ interface CompressionOptions {
23+ level : number ;
24+ }
25+
1826interface Metadata {
1927 percent : number ;
2028 currentFile : string ;
@@ -56,7 +64,7 @@ interface OutputByType {
5664// compressedContent: string|ArrayBuffer|Uint8Array|Buffer;
5765// }
5866
59- type InputFileFormat = InputByType [ keyof InputByType ] ;
67+ type InputFileFormat = InputByType [ keyof InputByType ] | Promise < InputByType [ keyof InputByType ] > ;
6068
6169declare namespace JSZip {
6270 type InputType = keyof InputByType ;
@@ -101,7 +109,14 @@ declare namespace JSZip {
101109 * The last modification date, defaults to the current date.
102110 */
103111 date ?: Date ;
104- compression ?: string ;
112+ /**
113+ * Sets per file compression. The `compressionOptions` parameter depends on the compression type.
114+ */
115+ compression ?: Compression ;
116+ /**
117+ * Sets per file compression level for `DEFLATE` compression.
118+ */
119+ compressionOptions ?: null | CompressionOptions ;
105120 comment ?: string ;
106121 /** Set to `true` if (and only if) the input is a "binary string" and has already been prepared with a `0xFF` mask. */
107122 optimizedBinaryString ?: boolean ;
@@ -124,10 +139,14 @@ declare namespace JSZip {
124139 }
125140
126141 interface JSZipGeneratorOptions < T extends OutputType = OutputType > {
142+ /**
143+ * Sets compression option for all entries that have not specified their own `compression` option
144+ */
127145 compression ?: Compression ;
128- compressionOptions ?: null | {
129- level : number ;
130- } ;
146+ /**
147+ * Sets compression level for `DEFLATE` compression.
148+ */
149+ compressionOptions ?: null | CompressionOptions ;
131150 type ?: T ;
132151 comment ?: string ;
133152 /**
@@ -150,6 +169,46 @@ declare namespace JSZip {
150169 createFolders ?: boolean ;
151170 decodeFileName ?: ( bytes : string [ ] | Uint8Array | Buffer ) => string ;
152171 }
172+
173+ interface JSZipMetadata {
174+ percent : number ;
175+ currentFile : string ;
176+ }
177+
178+ type DataEventCallback < T > = ( dataChunk : T , metadata : JSZipMetadata ) => void
179+ type EndEventCallback = ( ) => void
180+ type ErrorEventCallback = ( error : Error ) => void
181+
182+ interface JSZipStreamHelper < T > {
183+ /**
184+ * Register a listener on an event
185+ */
186+ on ( event : 'data' , callback : DataEventCallback < T > ) : this;
187+ on ( event : 'end' , callback : EndEventCallback ) : this;
188+ on ( event : 'error' , callback : ErrorEventCallback ) : this;
189+
190+ /**
191+ * Read the whole stream and call a callback with the complete content
192+ *
193+ * @param updateCallback The function called every time the stream updates
194+ * @return A Promise of the full content
195+ */
196+ accumulate ( updateCallback ?: ( metadata : JSZipMetadata ) => void ) : Promise < T > ;
197+
198+ /**
199+ * Resume the stream if the stream is paused. Once resumed, the stream starts sending data events again
200+ *
201+ * @return The current StreamHelper object, for chaining
202+ */
203+ resume ( ) : this;
204+
205+ /**
206+ * Pause the stream if the stream is running. Once paused, the stream stops sending data events
207+ *
208+ * @return The current StreamHelper object, for chaining
209+ */
210+ pause ( ) : this;
211+ }
153212}
154213
155214interface JSZip {
@@ -239,6 +298,14 @@ interface JSZip {
239298 */
240299 generateNodeStream ( options ?: JSZip . JSZipGeneratorOptions < 'nodebuffer' > , onUpdate ?: OnUpdateCallback ) : NodeJS . ReadableStream ;
241300
301+ /**
302+ * Generates the complete zip file with the internal stream implementation
303+ *
304+ * @param options Optional options for the generator
305+ * @return a StreamHelper
306+ */
307+ generateInternalStream < T extends JSZip . OutputType > ( options ?: JSZip . JSZipGeneratorOptions < T > ) : JSZip . JSZipStreamHelper < OutputByType [ T ] > ;
308+
242309 /**
243310 * Deserialize zip file asynchronously
244311 *
@@ -251,15 +318,7 @@ interface JSZip {
251318 /**
252319 * Create JSZip instance
253320 */
254-
255- /**
256- * Create JSZip instance
257- * If no parameters given an empty zip archive will be created
258- *
259- * @param data Serialized zip archive
260- * @param options Description of the serialized zip archive
261- */
262- new ( data ?: InputFileFormat , options ?: JSZip . JSZipLoadOptions ) : this;
321+ new ( ) : this;
263322
264323 ( ) : JSZip ;
265324
0 commit comments