export declare const DEFAULT_BYTE_STREAM_CHUNK_SIZE: number; declare const symbolDispose: symbol; /** * Creates a transferable ReadableStream from an async iterator. * * Use this when a StreamReader's contents need to be sent to a worker thread, * since async iterators are not transferable. * * @param {AsyncIterator} iterator - The async iterator to wrap. * @param {string} [name="iterator"] - Optional name for error messages. * @returns {ReadableStream} A transferable ReadableStream that pulls from the iterator. */ export declare function readableStreamFromIterator(iterator: any, name?: string): ReadableStream; /** * Creates a transferable ReadableStream from a byte-stream reader. * * Generated p3 stream readers expose `read({ count })`, which performs one * bounded Canonical ABI stream read for up to `count` bytes. Prefer that path so * host byte sinks consume practical chunks instead of one byte at a time. * * @param {object} reader - Reader that provides `read()`, or `[Symbol.asyncIterator]()`. * @param {object} [opts={}] - Optional adapter settings. * @param {number} [opts.chunkSize=DEFAULT_BYTE_STREAM_CHUNK_SIZE] - Maximum bytes to request per generated `read()` call. * @param {string} [opts.name="stream reader"] - Reader name used in error messages. * @returns {ReadableStream} A transferable stream of byte chunks. */ export declare function readableByteStreamFromReader(reader: any, opts?: {}): ReadableStream; export declare function _byteChunk(value: any): any; /** * Creates a bidirectional stream with separate reader and writer interfaces. * * Uses a TransformStream internally. * * @param {Object} [opts={}] - Configuration options for the stream. * @param {number} [opts.readableHWM=65536] - High water mark for the readable side (bytes). * @param {number} [opts.writableHWM=65536] - High water mark for the writable side (bytes). * * @returns {Object} An object containing: * - `tx` {StreamWriter}: The writer for sending data to the stream. * - `rx` {StreamReader}: The reader for receiving data from the stream. * * @example * * const { tx, rx } = stream(); * const payload = Buffer.from('roundtrip'); * * await tx.write(payload); * await tx.close(); * * const chunk1 = await rx.read(); * expect(chunk1).toEqual(payload); * * const done = await rx.read(); * expect(done).toBeNull(); * */ export declare function stream(opts?: { readableHWM?: number; writableHWM?: number; }): { tx: StreamWriter; rx: StreamReader; }; export declare class StreamReader { #private; [symbolDispose]: () => void; /** * Constructs a StreamReader. * * @param {AsyncIterable|Iterable} source - An async or sync iterable to consume e.g. ReadableStream, async generator, array. * @throws {Error} If the provided source does not implement `[Symbol.asyncIterator]` or `[Symbol.iterator]`. */ constructor(source: any, opts?: { preventCancel?: boolean; }); /** * Reads the next chunk from the stream. * * @returns {Promise} Resolves with the next chunk or null if the stream is done. */ read(): Promise; /** * Reads all chunks from the stream and concatenates them into a buffer. * * @returns {Promise} Resolves with the concatenated buffer. */ readAll(): Promise>; /** * Cancels the stream, signalling a premature exit to the iterator. * * @returns {Promise} */ cancel(_reason: any): Promise; /** * Closes the reader and releases the iterator. * Only calls return() if the iterator hasn't completed naturally, * since return() is meant for premature exits only. */ close(): void; /** * Consumes the reader and returns the underlying async iterator. * * After calling this method the StreamReader is closed and must not be used. * * @returns {AsyncIterator} The remaining async iterator. */ intoAsyncIterator(): any; /** * Implements the async-iterable protocol so a StreamReader can be used * directly with `for await…of` and any helper that consumes an * async iterator (e.g. `readableStreamFromIterator`). Like * `intoAsyncIterator()` above, this consumes the reader. * * @returns {AsyncIterator} */ [Symbol.asyncIterator](): any; } export declare class StreamWriter { #private; /** * Constructs a StreamWriter. * * @param {WritableStream} writable - The writable stream to write to. * @throws {Error} If the provided stream does not implement `getWriter`. */ constructor(writable: any); /** * Writes a chunk to the stream. * * @param {*} chunk - The chunk to write. * @returns {Promise} */ write(chunk: any): Promise; /** * Aborts the stream with the given reason. * * @param {*} reason - The reason for aborting the stream. * @returns {Promise} */ abort(reason: any): Promise; /** * Closes the writer and the stream. * * @returns {Promise} */ close(): Promise; /** * Closes the writer with an error. * * @param {Error} error - The error to close the writer with. * @returns {Promise} */ closeWithError(error: any): Promise; /** * Converts the writer back into a writable stream. * * @returns {WritableStream} The original writable stream that implements `getWriter()`. */ intoWritableStream(): Promise; } export {};