Skip to content

Commit c837a4b

Browse files
Victor CASTRO-CINTASStuk
authored andcommitted
Types definitions for generateInternalStream method and StreamHelper class
1 parent 798eefd commit c837a4b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

index.d.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,45 @@ declare namespace JSZip {
167167
}
168168
}
169169

170+
declare namespace StreamHelper {
171+
type DataEventCallback = (dataChunk: any, metadata: any) => any
172+
type EndEventCallback = () => any
173+
type ErrorEventCallback = (error: Error) => any
174+
175+
interface StreamHelper {
176+
/**
177+
* Register a listener on an event
178+
*
179+
* @param event The name of the event. Only 3 events are supported : data, end and error
180+
* @param callback The function called when the event occurs
181+
* @return The current StreamHelper object, for chaining
182+
*/
183+
on(event: 'data' | 'end' | 'error', callback: DataEventCallback | EndEventCallback | ErrorEventCallback);
184+
185+
/**
186+
* Read the whole stream and call a callback with the complete content
187+
*
188+
* @param updateCallback The function called every time the stream updates
189+
* @return A Promise of the full content
190+
*/
191+
accumulate(updateCallback?: (metadata: any) => any): Promise<any>;
192+
193+
/**
194+
* Resume the stream if the stream is paused. Once resumed, the stream starts sending data events again
195+
*
196+
* @return The current StreamHelper object, for chaining
197+
*/
198+
resume(): StreamHelper;
199+
200+
/**
201+
* Pause the stream if the stream is running. Once paused, the stream stops sending data events
202+
*
203+
* @return The current StreamHelper object, for chaining
204+
*/
205+
pause(): StreamHelper;
206+
}
207+
}
208+
170209
interface JSZip {
171210
files: {[key: string]: JSZip.JSZipObject};
172211

@@ -254,6 +293,14 @@ interface JSZip {
254293
*/
255294
generateNodeStream(options?: JSZip.JSZipGeneratorOptions<'nodebuffer'>, onUpdate?: OnUpdateCallback): NodeJS.ReadableStream;
256295

296+
/**
297+
* Generates the complete zip file with the internal stream implementation
298+
*
299+
* @param options Optional options for the generator
300+
* @return a StreamHelper
301+
*/
302+
generateInternalStream(options?: JSZip.JSZipGeneratorOptions): StreamHelper.StreamHelper
303+
257304
/**
258305
* Deserialize zip file asynchronously
259306
*

0 commit comments

Comments
 (0)