/** * Streaming, memory-bounded archive extraction across every container ZipKit * reads — ZIP, tar (+ `.tar.gz`/`.tar.zst`/`.tar.xz`), 7z, and lone compressed * streams (gzip/zstd/xz/bzip2/lz4). * * {@link extractStream} yields one {@link ArchiveEntryChunk} at a time so a * consumer can write each entry straight to disk (or a socket) without ever * holding the whole archive decompressed in memory. Two properties make it safe * to point at untrusted input: * * - **`maxTotalBytes`** caps the running total of *actually decompressed* bytes. * For the streamable path (ZIP `store`/`deflate`, gzip, plain tar) the cap is * enforced *during* decompression via the platform's incremental * `DecompressionStream`, so a zip bomb is rejected before it can allocate past * the cap. The engine's one-shot codecs (zstd, xz, bzip2, lzma, 7z) can't be * interrupted mid-frame, so there the cap is best-effort: a declared-size * pre-check plus a post-decode check, bounding blow-up to roughly * `compressedSize × ratio`. * - **`signal`** aborts between chunks. * * Path safety (rejecting `../` and absolute entry names) is the caller's job — * `extractStream` never touches the filesystem, it only decodes bytes. * * @example * ```ts * import { extractStream } from '@myrialabs/zipkit'; * for await (const { info, chunk, done } of extractStream(bytes, { maxTotalBytes: 512 * 1024 * 1024 })) { * if (info.type === 'directory') { await mkdir(info.name); continue; } * await append(info.name, chunk); * } * ``` */ /** How the outer container of an archive is framed. */ export type ArchiveFormat = 'zip' | 'tar' | '7z' | 'gzip' | 'zstd' | 'xz' | 'bzip2' | 'lz4-frame' | 'zlib' | 'tar.gz' | 'tar.zst' | 'tar.xz' | 'tar.bz2'; /** Metadata for one archive member, known before its bytes are streamed. */ export interface ArchiveEntryInfo { /** Path within the archive, using `/` separators. */ name: string; /** Entry kind. */ type: 'file' | 'directory' | 'symlink'; /** Uncompressed size in bytes, or `-1` when the container doesn't record it. */ size: number; /** Unix permission bits, if the archive recorded any. */ mode?: number; /** Last-modified time, if recorded. */ mtime?: Date; /** Symlink target, when `type` is `'symlink'`. */ linkname?: string; } /** One decompressed slice of an entry, emitted by {@link extractStream}. */ export interface ArchiveEntryChunk { /** The entry this chunk belongs to. */ info: ArchiveEntryInfo; /** Decompressed bytes (empty for directories, symlinks, and zero-length files). */ chunk: Uint8Array; /** `true` on the final chunk of this entry — the next chunk starts a new entry. */ done: boolean; } /** Options for {@link extractStream}. */ export interface ExtractStreamOptions { /** Container framing. Auto-detected from magic bytes when omitted. */ format?: ArchiveFormat; /** Password for encrypted ZIP entries (WinZip AES or legacy ZipCrypto). */ password?: string; /** Extract only entries for which this returns `true`. */ filter?: (info: ArchiveEntryInfo) => boolean; /** Cap on total decompressed bytes; throws {@link ZipKitError} once exceeded. */ maxTotalBytes?: number; /** Abort between chunks; throws {@link AbortError} when signalled. */ signal?: AbortSignal; /** Name for the single entry of a lone compressed stream (default `'data'`). */ entryName?: string; } /** * Extract an archive as a stream of entry chunks. Auto-detects the container * from `data`'s magic bytes unless `opts.format` is given. See the module * overview for the memory-bounding and cap semantics. */ export declare function extractStream(data: Uint8Array, opts?: ExtractStreamOptions): AsyncIterable; //# sourceMappingURL=extract.d.ts.map