UNPKG

@voxelio/zip

Version:

A tiny and fast client-side streaming ZIP generator

85 lines (84 loc) 3.62 kB
//#region src/input.d.ts type BufferLike = ArrayBuffer | string | ArrayBufferView | Blob; type StreamLike = ReadableStream<Uint8Array> | AsyncIterable<BufferLike>; //#endregion //#region src/unzip.d.ts /** * Extracts files from a ZIP using a Uint8Array. * @param data The ZIP file content as a Uint8Array * @returns An object containing file paths and their contents */ declare function extractZip(data: Uint8Array): Promise<Record<string, Uint8Array>>; //#endregion //#region src/zip.d.ts type ForAwaitable<T> = AsyncIterable<T> | Iterable<T>; //#endregion //#region src/index.d.ts /** The file name, modification date and size will be read from the input; * extra arguments can be given to override the input's metadata. */ type InputWithMeta = File | Response | { input: File | Response; name?: unknown; lastModified?: unknown; size?: number | bigint; mode?: number; }; /** Intrinsic size, but the file name must be provided and modification date can't be guessed. */ type InputWithSizeMeta = { input: BufferLike; name: unknown; lastModified?: unknown; size?: number | bigint; mode?: number; }; /** The file name must be provided ; modification date and content length can't be guessed. */ type InputWithoutMeta = { input: StreamLike; name: unknown; lastModified?: unknown; size?: number | bigint; mode?: number; }; /** The folder name must be provided ; modification date can't be guessed. */ type InputFolder = { name: unknown; lastModified?: unknown; input?: never; size?: never; mode?: number; }; /** Both filename and size must be provided ; input is not helpful here. */ type JustMeta = { input?: StreamLike | undefined; name: unknown; lastModified?: unknown; size: number | bigint; mode?: number; }; type Options = { /** If provided, the returned Response will have its `Content-Length` header set to this value. * It can be computed accurately with the `predictLength` function. */ length?: number | bigint; /** If provided, the returned Response will have its `Content-Length` header set to the result of * calling `predictLength` on that metadata. Overrides the `length` option. */ metadata?: Iterable<InputWithMeta | InputWithSizeMeta | JustMeta>; /** The ZIP *language encoding flag* will always be set when a filename was given as a string, * but when it is given as an ArrayView or ArrayBuffer, it depends on this option : * - `true`: always on (ArrayBuffers will *always* be flagged as UTF-8) — recommended, * - `false`: always off (ArrayBuffers will *never* be flagged as UTF-8), * - `undefined`: each ArrayBuffer will be tested and flagged if it is valid UTF-8. */ buffersAreUTF8?: boolean; }; /** Given an iterable of file metadata (or equivalent), * @returns the exact byte length of the Zip file that would be generated by `downloadZip`. */ declare const predictLength: (files: Iterable<InputWithMeta | InputWithSizeMeta | JustMeta | InputFolder>) => bigint; declare function downloadZip(files: ForAwaitable<InputWithMeta | InputWithSizeMeta | InputWithoutMeta | InputFolder>, options?: Options): Response; declare function makeZip(files: ForAwaitable<InputWithMeta | InputWithSizeMeta | InputWithoutMeta | InputFolder>, options?: Options): ReadableStream<Uint8Array<ArrayBufferLike>>; /** * Extracts files from a ZIP using a Uint8Array. * @param data The ZIP file content as a Uint8Array * @returns An object containing file paths and their contents */ //#endregion export { InputWithMeta, InputWithoutMeta, Options, downloadZip, extractZip, makeZip, predictLength }; //# sourceMappingURL=index.d.ts.map