/** * A persistent, warm worker pool for non-blocking compression on Node and Bun. * * Spinning up a worker per call (and re-instantiating the 1.4 MB Wasm engine * each time) is the cold-start tax fflate's async API pays. ZipKit keeps a * fixed pool of workers, each with the engine already loaded, and round-robins * jobs across them. Where workers aren't available (e.g. the browser without * bundler support), it transparently falls back to running on the calling * thread, so the API never breaks. * * @example * ```ts * import { WorkerPool } from '@myrialabs/zipkit'; * const pool = new WorkerPool(); * const out = await pool.compress(bytes, 'zstd', { level: 19 }); * await pool.destroy(); * ``` */ import type { Codec, CompressOptions, DecompressOptions } from '../types.js'; export interface WorkerPoolOptions { /** Number of workers to spawn. Defaults to one per CPU core (max 8). */ size?: number; } export declare class WorkerPool { private readonly size; private workers; private pending; private next; private seq; private ready; private usable; /** * Workers are `unref`'d at rest so an idle pool never blocks process exit. * While any job is in flight we `ref` them, so a script whose last action is * `await pool.compress(...)` doesn't exit before the result arrives. */ private refWhileBusy; constructor(opts?: WorkerPoolOptions); private ensure; private settle; private failAll; private run; /** Compress `data` with `codec` on a worker (or inline as a fallback). */ compress(data: Uint8Array, codec: Codec, opts?: CompressOptions): Promise; /** Decompress `data` with `codec` on a worker (or inline as a fallback). */ decompress(data: Uint8Array, codec: Codec, opts?: DecompressOptions): Promise; /** * Compress a ZIP entry on a worker using the raw libdeflate / zstd engine — * denser than the native path and byte-identical to the inline container * code, so a parallel archive matches a single-threaded one exactly. */ zipCompress(data: Uint8Array, method: 'deflate' | 'zstd', level?: number): Promise; /** Terminate all workers and reject any in-flight jobs. */ destroy(): Promise; } /** A lazily-created, process-wide {@link WorkerPool}. */ export declare function sharedPool(): WorkerPool; //# sourceMappingURL=index.d.ts.map