import type { Readable as NodeReadable, ReadableOptions as NodeReadableOptions, ReadableIteratorOptions, ReadableOperatorOptions, ReadableToWebOptions } from 'node:stream'; import type { Destroyable, DestroyCallback } from './destroy.js'; import type { Duplex } from './duplex.js'; import type { EventKey, Listener } from './events.js'; import type { PipeDestination } from './legacy.js'; import type { WritableState } from './writable.js'; import { Buffer } from 'buffer'; import { captureRejectionSymbol, type EventEmitterOptions } from './events.js'; import { toAsyncStreamable } from './iter.js'; import { Stream } from './legacy.js'; import { StringDecoder } from './string_decoder.js'; import { kOnConstructed, kState } from './utils.js'; export interface ReadableOptions extends NodeReadableOptions, EventEmitterOptions { defaultEncoding?: BufferEncoding; } declare const kErroredValue: unique symbol; declare const kDefaultEncodingValue: unique symbol; declare const kDecoderValue: unique symbol; declare const kEncodingValue: unique symbol; /** * The readable half of a stream's bookkeeping, reachable as `stream._readableState`. * * As with `WritableState`, the flags share one bitfield and the named properties are * accessors over it. */ export declare class ReadableState { [kState]: number; [kErroredValue]: Error | null; [kDefaultEncodingValue]: BufferEncoding; [kDecoderValue]: StringDecoder | null; [kEncodingValue]: BufferEncoding | null; /** The point at which `_read()` stops being called ahead of demand. */ highWaterMark: number; buffer: any[]; bufferIndex: number; length: number; pipes: PipeDestination[]; /** The destination(s) whose `drain` we are waiting on before resuming flow. */ awaitDrainWriters: PipeDestination | Set | null; /** `false` on a Duplex whose readable side was disabled at construction. */ readable?: boolean; constructor(options: ReadableOptions | undefined, stream: Readable, isDuplex: boolean); get objectMode(): boolean; /** Set once `push(null)` has been seen. */ get ended(): boolean; set ended(value: boolean); get endEmitted(): boolean; set endEmitted(value: boolean); /** Whether a `_read()` call is outstanding. */ get reading(): boolean; set reading(value: boolean); get constructed(): boolean; set constructed(value: boolean); get sync(): boolean; set sync(value: boolean); get needReadable(): boolean; set needReadable(value: boolean); get emittedReadable(): boolean; set emittedReadable(value: boolean); get readableListening(): boolean; get resumeScheduled(): boolean; get errorEmitted(): boolean; set errorEmitted(value: boolean); get emitClose(): boolean; get autoDestroy(): boolean; get destroyed(): boolean; set destroyed(value: boolean); get closed(): boolean; set closed(value: boolean); get closeEmitted(): boolean; set closeEmitted(value: boolean); get multiAwaitDrain(): boolean; get readingMore(): boolean; /** Whether any `data` event has been emitted. */ get dataEmitted(): boolean; get errored(): Error | null; set errored(value: Error | null); get defaultEncoding(): BufferEncoding; set defaultEncoding(value: BufferEncoding); get decoder(): StringDecoder | null; set decoder(value: StringDecoder | null); get encoding(): BufferEncoding | null; set encoding(value: BufferEncoding | null); /** `null` until the stream has been resumed or paused. */ get flowing(): boolean | null; set flowing(value: boolean | null); get paused(): boolean; set paused(value: boolean); get pipesCount(): number; [kOnConstructed](stream: Readable): void; } /** * A source of data. * * Subclasses implement `_read()` (and optionally `_destroy()` and `_construct()`) and call * `push()`; the base class handles buffering, flow control and the `data`/`readable` events. */ export declare class Readable extends Stream implements Destroyable, NodeReadable { _readableState: ReadableState; /** Present on a Duplex; `undefined` on a plain Readable. */ _writableState?: WritableState; constructor(options?: ReadableOptions); destroy(error?: Error | null, callback?: DestroyCallback): this; _undestroy(): void; _destroy(error: Error | null, callback: DestroyCallback): void; _construct?(callback: DestroyCallback): void; [captureRejectionSymbol](err: Error): void; [Symbol.asyncDispose](): Promise; /** * Adds a chunk to the read buffer, or ends the stream when passed `null`. * Returns `false` once the high water mark is reached. */ push(chunk: any, encoding?: BufferEncoding): boolean; /** Returns a chunk to the front of the read buffer. Should only ever be a chunk that came out of `read()`. */ unshift(chunk: any, encoding?: BufferEncoding): boolean; isPaused(): boolean; /** Makes the stream emit strings in `encoding` rather than Buffers, without splitting characters. */ setEncoding(encoding: BufferEncoding): this; read(n?: number | null): any; _read(size: number): void; pipe(dest: T, pipeOpts?: { end?: boolean; }): T; unpipe(dest?: PipeDestination): this; on(ev: EventKey, fn: Listener): this; addListener(ev: EventKey, fn: Listener): this; removeListener(ev: EventKey, fn: Listener): this; off(ev: EventKey, fn: Listener): this; removeAllListeners(ev?: EventKey): this; /** Switches the stream into flowing mode. */ resume(): this; pause(): this; /** Uses an old-style (pre-streams2) stream as this stream's data source. */ wrap(stream: any): this; [Symbol.asyncIterator](): NodeJS.AsyncIterator; iterator(options?: ReadableIteratorOptions): NodeJS.AsyncIterator; get readable(): boolean; set readable(value: boolean); get readableDidRead(): boolean; get readableAborted(): boolean; get readableHighWaterMark(): number; get readableBuffer(): any[] | undefined; get readableFlowing(): boolean | null; set readableFlowing(value: boolean | null); get readableLength(): number; get readableObjectMode(): boolean; get readableEncoding(): BufferEncoding | null; get errored(): Error | null; get closed(): boolean; get destroyed(): boolean; set destroyed(value: boolean); get readableEnded(): boolean; /** Builds a Readable from an iterable, async iterable, string or Buffer. */ static from(iterable: string | Buffer | Iterable | AsyncIterable, options?: ReadableOptions): Readable; /** Wraps an old-style stream, or any object with a compatible `data`/`end` event surface. */ static wrap(src: any, options?: ReadableOptions): Readable; /** Wraps a WHATWG `ReadableStream`. */ static fromWeb(readableStream: ReadableStream, options?: ReadableOptions): Readable; /** Exposes this stream as a WHATWG `ReadableStream`. */ static toWeb(streamReadable: Readable, options?: ReadableToWebOptions): ReadableStream; static readonly ReadableState: typeof ReadableState; /** Exposed for tests. */ static _fromList: typeof fromList; [toAsyncStreamable](): AsyncGenerator[], any, any>; } /** * Installed onto the prototype rather than declared in the class body: the operators live in * `operators.js` and `compose` in `compose.js`, which the package entry point loads. */ export interface Readable { map(fn: (value: any, options: { signal: AbortSignal; }) => any, options?: ReadableOperatorOptions): Readable; filter(fn: (value: any, options: { signal: AbortSignal; }) => any, options?: ReadableOperatorOptions): Readable; flatMap(fn: (value: any, options: { signal: AbortSignal; }) => any, options?: ReadableOperatorOptions): Readable; drop(limit: number, options?: ReadableOperatorOptions): Readable; take(limit: number, options?: ReadableOperatorOptions): Readable; every(fn: (value: any, options: { signal: AbortSignal; }) => any, options?: ReadableOperatorOptions): Promise; some(fn: (value: any, options: { signal: AbortSignal; }) => any, options?: ReadableOperatorOptions): Promise; find(fn: (value: any, options: { signal: AbortSignal; }) => any, options?: ReadableOperatorOptions): Promise; forEach(fn: (value: any, options: { signal: AbortSignal; }) => any, options?: ReadableOperatorOptions): Promise; toArray(options?: ReadableOperatorOptions): Promise; reduce(reducer: (previous: any, value: any, options: { signal: AbortSignal; }) => any, initialValue?: any, options?: ReadableOperatorOptions): Promise; /** Available once `@zenfs/streams` (or `@zenfs/streams/compose`) has been imported. */ compose(stream: any, options?: { signal?: AbortSignal; }): Duplex; } /** Takes `n` bytes (or one object) off the front of the buffer. */ declare function fromList(n: number, state: ReadableState): any; export {};