/** * Node.js True Streaming Compression * * Uses zlib.createDeflateRaw() with explicit flush() calls for real chunk-by-chunk streaming. * Each write() immediately produces compressed output without waiting for end(). */ import { type Gunzip, type Inflate } from "zlib"; import { Transform } from "../../stream/index.js"; export type { DeflateStream, InflateStream, StreamCompressOptions, StreamingCodec } from "./streaming-compress.base.js"; import type { DeflateStream, InflateStream, StreamCompressOptions, SyncDeflaterLike } from "./streaming-compress.base.js"; export type { SyncDeflaterLike }; /** * Create a true streaming DEFLATE compressor * Returns a Transform stream that emits compressed data immediately after each write */ export declare function createDeflateStream(options?: StreamCompressOptions): DeflateStream; /** * Create a true streaming INFLATE decompressor * * @param options - Decompression options (useWorker is ignored in Node.js) */ export declare function createInflateStream(options?: StreamCompressOptions): InflateStream; /** * Check if true streaming deflate-raw is available * In Node.js, zlib is always available, so this always returns true */ export declare function hasDeflateRaw(): boolean; export type GzipStream = Transform; export type GunzipStream = Gunzip; /** * Create a streaming GZIP compressor */ export declare function createGzipStream(options?: StreamCompressOptions): GzipStream; /** * Create a streaming GZIP decompressor */ export declare function createGunzipStream(_options?: StreamCompressOptions): GunzipStream; export type ZlibStream = Transform; export type UnzlibStream = Inflate; /** * Create a streaming Zlib compressor */ export declare function createZlibStream(options?: StreamCompressOptions): ZlibStream; /** * Create a streaming Zlib decompressor */ export declare function createUnzlibStream(_options?: StreamCompressOptions): UnzlibStream; /** * Node.js synchronous deflater that batches small writes for better * compression. * * Previous implementation compressed each `write()` call independently * with `deflateRawSync()`, creating a fresh zlib context every time. * For streaming workloads that push many small chunks (e.g. WorkbookWriter * writing one row at a time), this destroyed the LZ77 dictionary between * chunks and caused compression ratios to drop from ~82% to ~58%. * * The new implementation accumulates incoming data into an internal buffer * and only calls `deflateRawSync()` when the buffer reaches 64 KB (or on * `finish()`). Each batch is still compressed independently, but 64 KB * is enough for zlib to build a good dictionary — the compression ratio * is within ~1% of a single-shot compression of the entire input. * * The trade-off is slightly higher latency (compressed output is not * returned byte-for-byte immediately), but this is acceptable because * the ZIP writer buffers output anyway and the streaming contract only * requires data to flow *eventually*, not after every single write. */ export declare class SyncDeflater implements SyncDeflaterLike { private _level; private _pending; private _pendingSize; constructor(level?: number); write(data: Uint8Array): Uint8Array; finish(): Uint8Array; private _flushBatch; } /** * On Node.js, `zlib.deflateRawSync` is native and fast — no need to detour * through the async streaming path. Always returns false. */ export declare function hasNativeAsyncDeflate(): boolean;