import type { XlsxSink } from '../io/sink'; export interface ZipWriter { /** * Stage an entry. Bytes are pushed through fflate's `ZipDeflate` / * `ZipPassThrough` stream synchronously, so the deflated chunks land on the * sink as the call runs (no per-entry buffering — see the streaming-behaviour * test in `tests/phase-1/zip/writer.test.ts`). Streams (`ReadableStream`) * are not accepted today; pass an already-materialised entry, or use * {@link addStreamingEntry} for chunked writes. * * `compress` defaults to `true`. Pass `false` for already-compressed payloads * (PNG/JPEG/zip-as-binary content like vbaProject.bin) so we don't pay * deflate costs for no gain. */ addEntry(path: string, bytes: Uint8Array | ReadableStream, opts?: { compress?: boolean; }): Promise; /** * Open a streaming entry. Returns a writer the caller can `write()` chunks to * and `end()` to seal the entry. Each chunk pushes through the same fflate * `ZipDeflate` / `ZipPassThrough` machinery as `addEntry`, so peak memory * stays at one chunk + deflate scratch even for multi-GB worksheets. * * Sequencing: only one streaming entry may be open at a time — `addEntry` and * a second `addStreamingEntry` both throw until the current entry's `end()` * resolves. */ addStreamingEntry(path: string, opts?: { compress?: boolean; }): StreamingEntryWriter; /** * Build the central directory and flush all bytes through the sink. * Idempotent; subsequent calls resolve to the same payload. */ finalize(): Promise; /** * Release the sink and underlying writer without producing a valid archive. * Use this from a surrounding catch block when serialization fails part-way * through — without it, streaming sinks (`toFile` / `toWritable`) keep their * file descriptors / writables open and the half-written xlsx looks valid on * disk. Idempotent; safe to call after `finalize()`. */ abort(cause?: unknown): void; } /** Writer handle for a single streaming entry. */ export interface StreamingEntryWriter { /** Push a chunk of bytes (already-encoded). Throws after `end()`. */ write(chunk: Uint8Array): void; /** Seal the entry. Subsequent `write()` throws. Idempotent. */ end(): Promise; } /** * ZIP writer backed by fflate's streaming `Zip` class. Entries are pushed * through `ZipDeflate` / `ZipPassThrough` streams as they arrive, so peak * memory stays at the size of the in-flight entry plus the output buffer rather * than the full archive. * * The sink contract is `toBytes()`, but that name is historical: the sink is * driven by a chunked `write(chunk)` API that fans bytes out as they arrive. * The buffered Node/browser sinks (`toBuffer`, `toBlob`, `toArrayBuffer`) * concatenate the chunks for a single-shot result; streaming sinks * (`toFile`, `toWritable`) forward each chunk to disk / the wrapped writable * without ever holding the full archive resident. Either kind plugs in here. */ export declare function createZipWriter(sink: XlsxSink): ZipWriter;