import type { DuplexOptions as NodeDuplexOptions, Duplex as NodeDuplex } from 'node:stream'; import type { EventEmitterOptions } from './events.js'; import { Readable, type ReadableOptions } from './readable.js'; import type { ReadableWritablePair } from 'node:stream/web'; import { WritableState, type WriteCallback, type WriteRequest } from './writable.js'; /** `node:stream`'s options, plus the flags it accepts at runtime but does not declare. */ export interface DuplexOptions extends NodeDuplexOptions, EventEmitterOptions { /** Set to `false` to build a Duplex that is only writable. */ readable?: boolean; /** Set to `false` to build a Duplex that is only readable. */ writable?: boolean; /** Encoding assumed for string chunks passed to `push()`. Defaults to `utf8`. */ defaultEncoding?: BufferEncoding; } /** The writable half, taken from `Writable.prototype` at the bottom of this module. */ export interface Duplex { _writableState: WritableState; write(chunk: any, encoding?: BufferEncoding | null, callback?: WriteCallback): boolean; write(chunk: any, callback?: WriteCallback): boolean; end(callback?: WriteCallback): this; end(chunk: any, callback?: WriteCallback): this; end(chunk: any, encoding?: BufferEncoding | null, callback?: WriteCallback): this; cork(): void; uncork(): void; setDefaultEncoding(encoding: BufferEncoding): this; _write(chunk: any, encoding: BufferEncoding, callback: WriteCallback): void; _writev?(chunks: WriteRequest[], callback: WriteCallback): void; _final(callback: WriteCallback): void; writable: boolean; readonly writableAborted: boolean; readonly writableBuffer: ReturnType | undefined; readonly writableCorked: number; readonly writableEnded: boolean; readonly writableFinished: boolean; readonly writableHighWaterMark: number; readonly writableLength: number; readonly writableNeedDrain: boolean; readonly writableObjectMode: boolean; } /** * A stream that is both readable and writable. */ export declare class Duplex extends Readable implements NodeDuplex { /** When `false`, ending the readable side also ends the writable side. Defaults to `true`. */ allowHalfOpen: boolean; constructor(options?: DuplexOptions); /** Both sides have to be destroyed for a Duplex to count as destroyed. */ get destroyed(): boolean; set destroyed(value: boolean); /** Builds a Duplex from an iterable, async generator function, promise, web stream or stream pair. */ static from(body: unknown): Duplex; /** * Wraps a WHATWG `{ readable, writable }` pair. * * The trailing overload only exists so this static stays assignable to the one it shadows * on `Readable`; passing a bare `ReadableStream` throws. */ static fromWeb(pair: ReadableWritablePair, options?: DuplexOptions): Duplex; static fromWeb(readableStream: ReadableStream, options?: ReadableOptions): Readable; /** * Exposes a Duplex as a WHATWG `{ readable, writable }` pair. * * As with {@link Duplex.fromWeb}, the trailing overload is only there for assignability; * a Readable that is not a Duplex throws. */ static toWeb(duplex: Duplex): ReadableWritablePair; static toWeb(streamReadable: Readable, options?: { strategy?: QueuingStrategy; }): ReadableStream; }