import { type HashOptions } from 'node:crypto'; import { type Duplex, Readable, type Stream, Transform, type TransformCallback, Writable } from 'node:stream'; /** * @deprecated use native stream piping instead. */ export declare const forwardStreamErrors: (...streams: Stream[]) => void; /** * @deprecated This function has several flaws: * - It only works if all the stream are setup during the same tick * - It does not apply any backpressure to the source stream, which can lead to * memory issues * Use {@link Tee} instead, which is a more robust implementation of the same * concept. */ export declare const cloneStream: (stream: Readable) => Readable; /** * A {@link Transform} that forwards every chunk downstream while mirroring a * copy into a "branch" {@link Writable} (exposed through {@link Tee.branch}, e.g. * to be cached). The tee is paced by the slower of its two consumers, bounding * how much data gets buffered. The branch is completed when the source ends, * and torn down if the tee errors or is destroyed early (e.g. the client * disconnected). * * Consuming the branch is best-effort: its failures are swallowed here and must * never break the main stream. * * Because the tee is a {@link Transform}, its *main* output is a downstream * pipeline stage — so `pipeline([readable, tee, main])` tears the tee (and the * source) down as soon as `main` fails. If you need the branch to keep going * after the main consumer disappears (or vice-versa), use {@link fanOut}, which * owns both outputs instead of exposing one as a pipeline stage. */ export declare class Tee extends Transform { #private; readonly branch: Writable; constructor(branch: Writable | ((readable: Readable) => void)); get branchWritable(): boolean; _transform(chunk: unknown, _enc: BufferEncoding, cb: TransformCallback): void; _flush(cb: TransformCallback): void; _destroy(err: Error | null, cb: (err?: Error | null) => void): void; } /** * A {@link Writable} that mirrors everything written to it into several * independent "sinks", pacing the input by the slowest sink that is still * alive. Unlike {@link Tee}, the sinks are *owned* by the fan-out rather than * being downstream pipeline stages, which lets the two error domains be kept * apart: * * - An *output* (sink) that errors or ends early is simply dropped; the other * sinks — and the input — keep going. Its error is swallowed (best-effort), * exactly like a {@link Tee} branch. * - The *input* (writable side) is only torn down once *every* sink has died, * or if the input itself fails — in which case the failure is propagated to * every surviving sink. * * Designed to be the destination of a pipeline: * * ``` * pipeline([readable, ...transforms, fanOut(main, branch)]) * ``` * * If `main` disconnects (e.g. an HTTP response whose client went away), `branch` * still receives the full stream (e.g. to finish populating a cache), and * vice-versa. A sink may also be provided as a function receiving a * {@link Readable} to consume, mirroring {@link Tee}'s constructor. */ export declare function fanOut(...outputs: ReadonlyArray void)>): Writable; export declare const streamSize: (stream: Readable) => Promise; export declare const streamToBytes: (stream: AsyncIterable) => Promise>; export declare const streamToNodeBuffer: (stream: Iterable | AsyncIterable) => Promise; export declare const byteIterableToStream: (iter: AsyncIterable) => Readable; /** * Coalesce a stream of Uint8Array chunks into larger chunks of at least the * specified size ({@link minChunkSize}). This is useful for optimizing * downstream processing that benefits from larger chunk sizes, such as * compression or hashing. */ export declare const coalesceByteStream: (stream: Iterable | AsyncIterable, minChunkSize: number) => Readable; export declare const bytesToStream: (bytes: Uint8Array) => Readable; export declare class MaxSizeChecker extends Transform { readonly maxSize: number; readonly createError: () => Error; totalSize: number; constructor(maxSize: number, createError?: () => Error); _transform(chunk: Uint8Array, _enc: BufferEncoding, cb: TransformCallback): void; } export declare class MaxSizeError extends TypeError { readonly maxSize: number; name: string; constructor(maxSize: number, options?: ErrorOptions); } export declare class HashPassThrough extends Transform { #private; private readonly hash; constructor(algorithm: string, options?: HashOptions); _transform(chunk: Uint8Array, _enc: BufferEncoding, cb: TransformCallback): void; _flush(cb: TransformCallback): void; get digest(): Buffer; } export declare function decodeStream(stream: Readable, contentEncoding?: string | string[]): Readable; export declare function decodeStream(stream: AsyncIterable, contentEncoding?: string | string[]): AsyncIterable | Readable; /** * Maximum number of content-codings accepted by {@link createDecoders} unless a * caller passes its own. Generous on purpose: a header may legally list several * codings (RFC 9110 §8.4.1). */ export declare const DEFAULT_MAX_CODINGS = 8; export type CreateDecodersOptions = { maxCodings?: number; maxSize?: number; maxSizeError?: () => Error; }; /** * Create a series of decoding streams based on the content-encoding header. The * resulting streams should be piped together to decode the content. * * @see {@link https://datatracker.ietf.org/doc/html/rfc9110#section-8.4.1} */ export declare function createDecoders(contentEncoding?: string | string[], { maxCodings, maxSize, maxSizeError, }?: CreateDecodersOptions): Duplex[]; //# sourceMappingURL=streams.d.ts.map