Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate metadata types and expose OnUpdateCallback #852

Merged
merged 1 commit into from Jul 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 9 additions & 14 deletions index.d.ts
Expand Up @@ -23,13 +23,6 @@ interface CompressionOptions {
level: number;
}

interface Metadata {
percent: number;
currentFile: string | null;
}

type OnUpdateCallback = (metadata: Metadata) => void;

interface InputByType {
base64: string;
string: string;
Expand Down Expand Up @@ -71,6 +64,13 @@ declare namespace JSZip {

type OutputType = keyof OutputByType;

interface JSZipMetadata {
percent: number;
currentFile: string | null;
}

type OnUpdateCallback = (metadata: JSZipMetadata) => void;

interface JSZipObject {
name: string;
/**
Expand Down Expand Up @@ -170,11 +170,6 @@ declare namespace JSZip {
decodeFileName?: (bytes: string[] | Uint8Array | Buffer) => string;
}

interface JSZipMetadata {
percent: number;
currentFile: string;
}

type DataEventCallback<T> = (dataChunk: T, metadata: JSZipMetadata) => void
type EndEventCallback = () => void
type ErrorEventCallback = (error: Error) => void
Expand Down Expand Up @@ -287,7 +282,7 @@ interface JSZip {
* @param onUpdate The optional function called on each internal update with the metadata.
* @return The serialized archive
*/
generateAsync<T extends JSZip.OutputType>(options?: JSZip.JSZipGeneratorOptions<T>, onUpdate?: OnUpdateCallback): Promise<OutputByType[T]>;
generateAsync<T extends JSZip.OutputType>(options?: JSZip.JSZipGeneratorOptions<T>, onUpdate?: JSZip.OnUpdateCallback): Promise<OutputByType[T]>;

/**
* Generates a new archive asynchronously
Expand All @@ -296,7 +291,7 @@ interface JSZip {
* @param onUpdate The optional function called on each internal update with the metadata.
* @return A Node.js `ReadableStream`
*/
generateNodeStream(options?: JSZip.JSZipGeneratorOptions<'nodebuffer'>, onUpdate?: OnUpdateCallback): NodeJS.ReadableStream;
generateNodeStream(options?: JSZip.JSZipGeneratorOptions<'nodebuffer'>, onUpdate?: JSZip.OnUpdateCallback): NodeJS.ReadableStream;

/**
* Generates the complete zip file with the internal stream implementation
Expand Down