import type * as net from "node:net"; import { ClickHouseException } from "./types.ts"; /** * A streaming byte reader for raw TCP packet framing. * Data block payloads may be compressed, but those are read explicitly with readCompressedBlock(). * * The socket is consumed eagerly via 'data' events (flowing mode) so the kernel * receive buffer stays drained while the decoder works. Pulling through the * stream async iterator instead (paused mode) stops kernel reads every time the * stream buffers one highWaterMark (~64KB); on high-latency links that churn * keeps the TCP receive window from growing and caps throughput at roughly one * receive buffer per round trip. * * If the consumer falls behind and unread data exceeds PAUSE_THRESHOLD, the * socket is paused until the buffer drains below half the threshold, so * backpressure still reaches the server for genuinely slow consumers. */ export declare class StreamingReader { private static MAX_COMPRESSED_BLOCK_SIZE; private static PAUSE_THRESHOLD; private static MIN_CAPACITY; private socket; private buffer; /** Read cursor into buffer. */ private offset; /** End of valid data in buffer. */ private end; /** Bytes before this index were already handed out via peekAll()/nextChunk(). */ private returnedEnd; private done; private error; private wake; private pausedByUs; constructor(socket: net.Socket); private get available(); private append; /** * Move unread bytes to a fresh buffer with headroom for `incoming` more. * Always a fresh allocation, never compaction in place: views handed out by * peekAll()/nextChunk()/readCompressedBlock() must keep their bytes. * Sizing from current unread data (not previous capacity) lets the buffer * shrink back after an unusually large block. */ private realloc; private wakeWaiter; /** Wait for more data, EOF, or error. Callers re-check state after resolution. */ private waitForMore; private resume; private advance; /** Throws on socket error, returns false on EOF, otherwise waits for new data. */ private waitOrEnd; private ensure; consume(n: number): void; /** * All currently buffered unread bytes. Marks them as handed out: a following * nextChunk() resolves only once bytes beyond these arrive. */ peekAll(): Uint8Array; /** Buffered bytes not yet handed out by peekAll()/nextChunk(), or null on EOF. */ nextChunk(): Promise; readVarint(): Promise; readString(): Promise; readU8(): Promise; readInt32LE(): Promise; readU64LE(): Promise; readException(): Promise; private readCompressedFrameSize; readCompressedBlock(): Promise; discardCompressedBlock(): Promise; } //# sourceMappingURL=reader.d.ts.map