import type { ZipWorkerBackend } from "./index"; /** * Worker instance or factory used by `createWorkerBackend()`. * * A factory is recommended so the backend can recreate a worker after aborts, * crashes, or termination. This library never creates blob URL workers * internally; pass a CSP-appropriate worker URL from your app or extension. */ export type ZipWorkerFactory = Worker | (() => Worker); /** * How byte-array inputs are sent to the worker. * * - `"copy"` keeps caller-owned buffers intact. * - `"transfer"` transfers full `ArrayBuffer` / full-span `Uint8Array` inputs * and detaches them. * - `"auto"` is conservative: it transfers only a copy that the backend had to * create for a partial `Uint8Array` view, avoiding detaching caller buffers. */ export type ZipWorkerTransferMode = "auto" | "copy" | "transfer"; /** Options for `createWorkerBackend()`. */ export interface ZipWorkerBackendOptions { /** * Worker instance or factory used by this backend. * * Use a static script URL that satisfies your CSP, for example * `() => new Worker(browser.runtime.getURL("jszipp.worker.mjs"), { type: "module" })` * in a modern extension page. A factory is preferred because the backend * creates workers lazily, can recreate them after `terminate()` or crashes, * and can still honor `fallback` if construction fails. With a compat build, use the matching * `cr61ff58/jszipp.worker.js` or `cr86ff68/jszipp.worker.js` classic * worker script and omit `{ type: "module" }`. */ workerSource?: ZipWorkerFactory; /** * Deprecated alias for `workerSource`. * * Kept temporarily for compatibility with older callers. */ worker?: ZipWorkerFactory; /** * Whether to fall back to JSZipp's normal in-thread preparation when the * worker path is unavailable, a request cannot be cloned/sent, or a worker * request fails while the source data is still usable locally. * * Defaults to `true`. Set to `false` when worker usage is required and any * worker failure should reject the write. Requests sent with * `transfer: "transfer"` can still fall back for inputs whose caller-owned * bytes were not transferred (for example strings, Blobs, or partial * `Uint8Array` views). Fallback is unavailable only after the worker takes * ownership of the original caller-owned source buffer. */ fallback?: boolean; /** * Byte transfer policy for `ArrayBuffer` and `Uint8Array` inputs. * * Defaults to `"copy"` so caller-owned buffers are not detached. */ transfer?: ZipWorkerTransferMode; /** * Minimum known input size, in bytes, required before the backend uses a * worker. Smaller entries return `undefined` and use the normal path. * * Defaults to `32768` (32 KiB) so worker offload stays focused on * responsiveness for larger payloads instead of adding `postMessage` * overhead to small entries. */ minSize?: number; } /** * Reusable worker backend returned by `createWorkerBackend()`. * * The same backend can be passed to multiple `ZipWriter` instances. Writers do * not terminate it automatically; call `terminate()` when the backend is no * longer needed. Aborting one write rejects only that write; it does not tear * down sibling work sharing the backend or stop compression already running in * the worker. */ export interface ZipWorkerBackendHandle extends ZipWorkerBackend { /** Terminate the current worker instance and reject any in-flight requests. */ terminate(): void; } /** * Create a reusable backend for `new ZipWriter({ worker })`. * * The returned backend prepares eligible async entries in a Web Worker and * returns `undefined` for entries that should use JSZipp's normal in-thread * preparation path. */ export declare const createWorkerBackend: (options: ZipWorkerBackendOptions) => ZipWorkerBackendHandle;