@@ -169,44 +169,45 @@ declare namespace JSZip {
169
169
createFolders ?: boolean ;
170
170
decodeFileName ?: ( bytes : string [ ] | Uint8Array | Buffer ) => string ;
171
171
}
172
- }
173
172
174
- declare namespace StreamHelper {
175
- type DataEventCallback = ( dataChunk : any , metadata : any ) => any
176
- type EndEventCallback = ( ) => any
177
- type ErrorEventCallback = ( error : Error ) => any
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
178
181
179
- interface StreamHelper {
182
+ interface JSZipStreamHelper < T > {
180
183
/**
181
184
* Register a listener on an event
182
- *
183
- * @param event The name of the event. Only 3 events are supported : data, end and error
184
- * @param callback The function called when the event occurs
185
- * @return The current StreamHelper object, for chaining
186
185
*/
187
- on ( event : 'data' | 'end' | 'error' , callback : DataEventCallback | EndEventCallback | ErrorEventCallback ) ;
186
+ on ( event : 'data' , callback : DataEventCallback < T > ) : this;
187
+ on ( event : 'end' , callback : EndEventCallback ) : this;
188
+ on ( event : 'error' , callback : ErrorEventCallback ) : this;
188
189
189
190
/**
190
191
* Read the whole stream and call a callback with the complete content
191
192
*
192
193
* @param updateCallback The function called every time the stream updates
193
194
* @return A Promise of the full content
194
195
*/
195
- accumulate ( updateCallback ?: ( metadata : any ) => any ) : Promise < any > ;
196
+ accumulate ( updateCallback ?: ( metadata : JSZipMetadata ) => void ) : Promise < T > ;
196
197
197
198
/**
198
199
* Resume the stream if the stream is paused. Once resumed, the stream starts sending data events again
199
200
*
200
201
* @return The current StreamHelper object, for chaining
201
202
*/
202
- resume ( ) : StreamHelper ;
203
+ resume ( ) : this ;
203
204
204
205
/**
205
206
* Pause the stream if the stream is running. Once paused, the stream stops sending data events
206
207
*
207
208
* @return The current StreamHelper object, for chaining
208
209
*/
209
- pause ( ) : StreamHelper ;
210
+ pause ( ) : this ;
210
211
}
211
212
}
212
213
@@ -303,7 +304,7 @@ interface JSZip {
303
304
* @param options Optional options for the generator
304
305
* @return a StreamHelper
305
306
*/
306
- generateInternalStream ( options ?: JSZip . JSZipGeneratorOptions ) : StreamHelper . StreamHelper
307
+ generateInternalStream < T extends JSZip . OutputType > ( options ?: JSZip . JSZipGeneratorOptions < T > ) : JSZip . JSZipStreamHelper < OutputByType [ T ] > ;
307
308
308
309
/**
309
310
* Deserialize zip file asynchronously
0 commit comments