/** * Buffered Stream * * A Duplex-like stream that manages internal buffering with chunk-based read/write operations. * Works identically in both browser and Node.js environments. */ import type { BufferedStreamOptions, DataChunk } from "./types.js"; import { EventEmitter } from "../../utils/event-emitter.js"; export type { BufferedStreamOptions, DataChunk } from "./types.js"; /** * String chunk implementation */ export declare class StringChunk implements DataChunk { private readonly _data; private _buffer?; constructor(data: string); get length(): number; copy(target: Uint8Array, targetOffset: number, offset: number, length: number): number; toUint8Array(): Uint8Array; } /** * Uint8Array chunk implementation */ export declare class ByteChunk implements DataChunk { private readonly _data; constructor(data: Uint8Array); get length(): number; copy(target: Uint8Array, targetOffset: number, offset: number, length: number): number; toUint8Array(): Uint8Array; } /** * Browser-compatible Buffered Stream with efficient chunk management */ export declare class BufferedStream extends EventEmitter { private _chunks; private _chunkReadIndex; private _buffers; private _bufferReadIndex; private readonly _batchSize; private _finished; private _destroyed; private _totalLength; constructor(options?: BufferedStreamOptions); /** * Write data to the stream */ write(chunk: Uint8Array | string): boolean; /** * Read data from the stream */ read(size?: number): Uint8Array | null; /** * Signal end of writes */ end(chunk?: Uint8Array | string): void; /** * Destroy the stream */ destroy(error?: Error): void; /** * Get total buffered length */ get bufferedLength(): number; /** * Get buffer of specified size from internal buffers */ private _getBuffer; /** * Add chunk to internal buffers */ private _addChunkToBuffers; /** * Get all buffered data as a single Uint8Array. * Consumes the internal buffers — after this call, `bufferedLength` is 0. */ toUint8Array(): Uint8Array; /** * Check if stream is finished */ get isFinished(): boolean; /** * Check if stream is destroyed */ get destroyed(): boolean; }