import { ByteQueue } from "../shared/byte-queue.js"; import { Duplex, PassThrough, Transform, type Readable } from "../../stream/index.js"; import { type CrxHeader, type EntryProps, type EntryVars, type ParseDriverState, type ParseOptions, type ZipExtraFields } from "./parser-core.js"; export declare const DEFAULT_UNZIP_STREAM_HIGH_WATER_MARK: number; export type DrainStream = Transform & { promise: () => Promise; }; export declare function autodrain(stream: { pipe: (dest: Transform) => unknown; }): DrainStream; /** * Collects all data from a readable stream into a single Uint8Array. */ export declare function bufferStream(entry: Readable): Promise; export type PullFn = (length: number) => Promise; export declare class PullStream extends Duplex { protected readonly _queue: ByteQueue; private readonly _inputHighWaterMarkBytes; private readonly _inputLowWaterMarkBytes; get buffer(): Uint8Array; set buffer(value: Uint8Array); cb?: () => void; finished: boolean; match?: number; __emittedError?: Error; private _pendingChunkResolve?; private _pendingChunkPromise?; constructor(opts?: ParseOptions); write: { (chunk: Uint8Array, callback?: (error?: Error | null) => void): boolean; (chunk: Uint8Array, encoding?: string, callback?: (error?: Error | null) => void): boolean; (chunk: string, callback?: (error?: Error | null) => void): boolean; (chunk: string, encoding?: string, callback?: (error?: Error | null) => void): boolean; }; push: (chunk: TRead | null) => boolean; private _notifyPendingChunkWaiter; private _waitForChunkSignal; private _pullFixedLength; _write(chunk: Uint8Array | string, _encoding: string, callback: () => void): void; _read(): void; protected _maybeReleaseWriteCallback(): void; /** * The `eof` parameter is interpreted as `file_length` if the type is number * otherwise (i.e. Uint8Array) it is interpreted as a pattern signaling end of stream */ stream(eof: number | Uint8Array, includeEof?: boolean): PassThrough; pull(eof: number | Uint8Array, includeEof?: boolean): Promise; pullUntil(pattern: Uint8Array, includeEof?: boolean): Promise; } export type PullStreamPublicApi = { buffer: Uint8Array; cb?: () => void; finished: boolean; match?: number; stream(eof: number | Uint8Array, includeEof?: boolean): PassThrough; pull(eof: number | Uint8Array, includeEof?: boolean): Promise; pullUntil(pattern: Uint8Array, includeEof?: boolean): Promise; }; export interface StreamUntilValidatedDataDescriptorSource { getLength(): number; read(length: number): Uint8Array; /** Optional: zero-copy chunk views for streaming writes. */ peekChunks?(length: number): Uint8Array[]; /** Optional: consume bytes previously written from peekChunks(). */ discard?(length: number): void; indexOfPattern(pattern: Uint8Array, startIndex: number): number; peekUint32LE(offset: number): number | null; isFinished(): boolean; onDataAvailable(cb: () => void): () => void; maybeReleaseWriteCallback?: () => void; } export interface StreamUntilValidatedDataDescriptorOptions { source: StreamUntilValidatedDataDescriptorSource; dataDescriptorSignature: Uint8Array; /** Keep enough bytes to validate: descriptor(16) + next record sig(4) = 20. */ keepTailBytes?: number; errorMessage?: string; } /** * Stream compressed file data until we reach a validated DATA_DESCRIPTOR boundary. * * This encapsulates the shared logic used by both Node and browser parsers. */ export declare function streamUntilValidatedDataDescriptor(options: StreamUntilValidatedDataDescriptorOptions): PassThrough; export interface ZipEntry extends PassThrough { path: string; props: EntryProps; /** * Entry type. Note: Streaming parser can only reliably detect "Directory" vs "File". * "Symlink" detection requires Central Directory access (use buffer-based parsing). */ type: "Directory" | "File" | "Symlink"; vars: EntryVars; extraFields: ZipExtraFields; size?: number; __autodraining?: boolean; autodrain: () => DrainStream; buffer: () => Promise; } export interface ParseIO { pull(length: number): Promise; pullUntil(pattern: Uint8Array, includeEof?: boolean): Promise; stream(length: number): PassThrough; streamUntilDataDescriptor(): PassThrough; setDone(): void; } export interface ParseEmitter { emitEntry(entry: ZipEntry): void; pushEntry(entry: ZipEntry): void; pushEntryIfPiped(entry: ZipEntry): void; emitCrxHeader(header: CrxHeader): void; emitError(err: Error): void; emitClose(): void; } export type InflateFactory = () => Transform | Duplex | PassThrough; /** * Synchronous inflate function type for small file optimization. * When provided and file size is below threshold, this will be used * instead of streaming decompression for better performance. */ export type InflateRawSync = (data: Uint8Array) => Uint8Array; export declare function runParseLoop(opts: ParseOptions, io: ParseIO, emitter: ParseEmitter, inflateFactory: InflateFactory, state: ParseDriverState, inflateRawSync?: InflateRawSync): Promise;