Skip to content

Commit 8f91a22

Browse files
committed
add null type to metadata
1 parent f43810e commit 8f91a22

File tree

1 file changed

+57
-24
lines changed

1 file changed

+57
-24
lines changed

index.d.ts

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface JSZipSupport {
1313
nodebuffer: boolean;
1414
}
1515

16-
type Compression = 'STORE' | 'DEFLATE';
16+
type Compression = "STORE" | "DEFLATE";
1717

1818
/**
1919
* Depends on the compression type. With `STORE` (no compression), these options are ignored. With
@@ -23,9 +23,9 @@ interface CompressionOptions {
2323
level: number;
2424
}
2525

26-
interface Metadata {
26+
interface Metadata {
2727
percent: number;
28-
currentFile: string;
28+
currentFile: string | null;
2929
}
3030

3131
type OnUpdateCallback = (metadata: Metadata) => void;
@@ -64,7 +64,9 @@ interface OutputByType {
6464
// compressedContent: string|ArrayBuffer|Uint8Array|Buffer;
6565
// }
6666

67-
type InputFileFormat = InputByType[keyof InputByType] | Promise<InputByType[keyof InputByType]>;
67+
type InputFileFormat =
68+
| InputByType[keyof InputByType]
69+
| Promise<InputByType[keyof InputByType]>;
6870

6971
declare namespace JSZip {
7072
type InputType = keyof InputByType;
@@ -93,8 +95,14 @@ declare namespace JSZip {
9395
* @param onUpdate a function to call on each internal update.
9496
* @return Promise the promise of the result.
9597
*/
96-
async<T extends OutputType>(type: T, onUpdate?: OnUpdateCallback): Promise<OutputByType[T]>;
97-
nodeStream(type?: 'nodebuffer', onUpdate?: OnUpdateCallback): NodeJS.ReadableStream;
98+
async<T extends OutputType>(
99+
type: T,
100+
onUpdate?: OnUpdateCallback
101+
): Promise<OutputByType[T]>;
102+
nodeStream(
103+
type?: "nodebuffer",
104+
onUpdate?: OnUpdateCallback
105+
): NodeJS.ReadableStream;
98106
}
99107

100108
interface JSZipFileOptions {
@@ -159,7 +167,7 @@ declare namespace JSZip {
159167
/** Stream the files and create file descriptors */
160168
streamFiles?: boolean;
161169
/** DOS (default) or UNIX */
162-
platform?: 'DOS' | 'UNIX';
170+
platform?: "DOS" | "UNIX";
163171
}
164172

165173
interface JSZipLoadOptions {
@@ -175,25 +183,27 @@ declare namespace JSZip {
175183
currentFile: string;
176184
}
177185

178-
type DataEventCallback<T> = (dataChunk: T, metadata: JSZipMetadata) => void
179-
type EndEventCallback = () => void
180-
type ErrorEventCallback = (error: Error) => void
186+
type DataEventCallback<T> = (dataChunk: T, metadata: JSZipMetadata) => void;
187+
type EndEventCallback = () => void;
188+
type ErrorEventCallback = (error: Error) => void;
181189

182190
interface JSZipStreamHelper<T> {
183191
/**
184192
* Register a listener on an event
185193
*/
186-
on(event: 'data', callback: DataEventCallback<T>): this;
187-
on(event: 'end', callback: EndEventCallback): this;
188-
on(event: 'error', callback: ErrorEventCallback): this;
194+
on(event: "data", callback: DataEventCallback<T>): this;
195+
on(event: "end", callback: EndEventCallback): this;
196+
on(event: "error", callback: ErrorEventCallback): this;
189197

190198
/**
191199
* Read the whole stream and call a callback with the complete content
192200
*
193201
* @param updateCallback The function called every time the stream updates
194202
* @return A Promise of the full content
195203
*/
196-
accumulate(updateCallback?: (metadata: JSZipMetadata) => void): Promise<T>;
204+
accumulate(
205+
updateCallback?: (metadata: JSZipMetadata) => void
206+
): Promise<T>;
197207

198208
/**
199209
* Resume the stream if the stream is paused. Once resumed, the stream starts sending data events again
@@ -212,7 +222,7 @@ declare namespace JSZip {
212222
}
213223

214224
interface JSZip {
215-
files: {[key: string]: JSZip.JSZipObject};
225+
files: { [key: string]: JSZip.JSZipObject };
216226

217227
/**
218228
* Get a file from the archive
@@ -238,8 +248,16 @@ interface JSZip {
238248
* @param options Optional information about the file
239249
* @return JSZip object
240250
*/
241-
file<T extends JSZip.InputType>(path: string, data: InputByType[T] | Promise<InputByType[T]>, options?: JSZip.JSZipFileOptions): this;
242-
file<T extends JSZip.InputType>(path: string, data: null, options?: JSZip.JSZipFileOptions & { dir: true }): this;
251+
file<T extends JSZip.InputType>(
252+
path: string,
253+
data: InputByType[T] | Promise<InputByType[T]>,
254+
options?: JSZip.JSZipFileOptions
255+
): this;
256+
file<T extends JSZip.InputType>(
257+
path: string,
258+
data: null,
259+
options?: JSZip.JSZipFileOptions & { dir: true }
260+
): this;
243261

244262
/**
245263
* Returns an new JSZip instance with the given folder as root
@@ -262,15 +280,19 @@ interface JSZip {
262280
*
263281
* @param callback function
264282
*/
265-
forEach(callback: (relativePath: string, file: JSZip.JSZipObject) => void): void;
283+
forEach(
284+
callback: (relativePath: string, file: JSZip.JSZipObject) => void
285+
): void;
266286

267287
/**
268288
* Get all files which match the given filter function
269289
*
270290
* @param predicate Filter function
271291
* @return Array of matched elements
272292
*/
273-
filter(predicate: (relativePath: string, file: JSZip.JSZipObject) => boolean): JSZip.JSZipObject[];
293+
filter(
294+
predicate: (relativePath: string, file: JSZip.JSZipObject) => boolean
295+
): JSZip.JSZipObject[];
274296

275297
/**
276298
* Removes the file or folder from the archive
@@ -287,7 +309,10 @@ interface JSZip {
287309
* @param onUpdate The optional function called on each internal update with the metadata.
288310
* @return The serialized archive
289311
*/
290-
generateAsync<T extends JSZip.OutputType>(options?: JSZip.JSZipGeneratorOptions<T>, onUpdate?: OnUpdateCallback): Promise<OutputByType[T]>;
312+
generateAsync<T extends JSZip.OutputType>(
313+
options?: JSZip.JSZipGeneratorOptions<T>,
314+
onUpdate?: OnUpdateCallback
315+
): Promise<OutputByType[T]>;
291316

292317
/**
293318
* Generates a new archive asynchronously
@@ -296,15 +321,20 @@ interface JSZip {
296321
* @param onUpdate The optional function called on each internal update with the metadata.
297322
* @return A Node.js `ReadableStream`
298323
*/
299-
generateNodeStream(options?: JSZip.JSZipGeneratorOptions<'nodebuffer'>, onUpdate?: OnUpdateCallback): NodeJS.ReadableStream;
324+
generateNodeStream(
325+
options?: JSZip.JSZipGeneratorOptions<"nodebuffer">,
326+
onUpdate?: OnUpdateCallback
327+
): NodeJS.ReadableStream;
300328

301329
/**
302330
* Generates the complete zip file with the internal stream implementation
303331
*
304332
* @param options Optional options for the generator
305333
* @return a StreamHelper
306334
*/
307-
generateInternalStream<T extends JSZip.OutputType>(options?: JSZip.JSZipGeneratorOptions<T>): JSZip.JSZipStreamHelper<OutputByType[T]>;
335+
generateInternalStream<T extends JSZip.OutputType>(
336+
options?: JSZip.JSZipGeneratorOptions<T>
337+
): JSZip.JSZipStreamHelper<OutputByType[T]>;
308338

309339
/**
310340
* Deserialize zip file asynchronously
@@ -313,12 +343,15 @@ interface JSZip {
313343
* @param options Options for deserializing
314344
* @return Returns promise
315345
*/
316-
loadAsync(data: InputFileFormat, options?: JSZip.JSZipLoadOptions): Promise<JSZip>;
346+
loadAsync(
347+
data: InputFileFormat,
348+
options?: JSZip.JSZipLoadOptions
349+
): Promise<JSZip>;
317350

318351
/**
319352
* Create JSZip instance
320353
*/
321-
new(): this;
354+
new (): this;
322355

323356
(): JSZip;
324357

0 commit comments

Comments
 (0)