import type { DestroyCallback, Destroyable } from './destroy.js'; import type { PipeDestination } from './legacy.js'; import type { ReadableState } from './readable.js'; import type { WritableOptions as NodeWritableOptions, Writable as NodeWritable } from 'node:stream'; import { captureRejectionSymbol, type EventEmitterOptions } from './events.js'; import { Stream } from './legacy.js'; import { type Callback } from './util.js'; import { kOnConstructed, kState } from './utils.js'; /** `'buffer'` marks an already-decoded chunk; `''` is used where no encoding applies. */ export type ChunkEncoding = BufferEncoding | 'buffer' | ''; export type WriteCallback = Callback; export interface WritableOptions extends NodeWritableOptions, EventEmitterOptions { } export interface WriteRequest { chunk: any; encoding: ChunkEncoding; } interface BufferedWrite extends WriteRequest { callback: WriteCallback; } interface AfterWriteTickInfo { count: number; cb: WriteCallback; stream: Writable; state: WritableState; } declare const kErroredValue: unique symbol; declare const kDefaultEncodingValue: unique symbol; declare const kWriteCbValue: unique symbol; declare const kAfterWriteTickInfoValue: unique symbol; declare const kBufferedValue: unique symbol; declare const kOnFinishedValue: unique symbol; /** * The writable half of a stream's bookkeeping, reachable as `stream._writableState`. * * Flags live in a single bitfield so the hot paths can test several at once; the named * properties below are accessors over that field, kept for compatibility with code that * inspects stream state. */ export declare class WritableState { [kState]: number; [kErroredValue]: Error | null; [kDefaultEncodingValue]: BufferEncoding; [kWriteCbValue]: WriteCallback | null; [kAfterWriteTickInfoValue]: AfterWriteTickInfo | null; [kBufferedValue]: BufferedWrite[] | null; [kOnFinishedValue]: WriteCallback[] | null; /** The point at which `write()` starts returning false. */ highWaterMark: number; /** Bytes (or, in object mode, chunks) waiting to reach `_write()`. */ length: number; corked: number; writelen: number; /** Number of pending user write callbacks; must reach 0 before `finish`. */ pendingcb: number; bufferedIndex: number; readonly onwrite: (er?: Error | null) => void; constructor(options: WritableOptions | undefined, stream: Writable, isDuplex: boolean); get objectMode(): boolean; get finalCalled(): boolean; set finalCalled(value: boolean); get needDrain(): boolean; set needDrain(value: boolean); /** Set as soon as `end()` is entered. */ get ending(): boolean; set ending(value: boolean); /** Set once `end()` has returned. */ get ended(): boolean; set ended(value: boolean); get finished(): boolean; set finished(value: boolean); get destroyed(): boolean; set destroyed(value: boolean); get decodeStrings(): boolean; get writing(): boolean; /** Whether the `_write()` callback fired synchronously. */ get sync(): boolean; get bufferProcessing(): boolean; get constructed(): boolean; set constructed(value: boolean); get prefinished(): boolean; set prefinished(value: boolean); get errorEmitted(): boolean; set errorEmitted(value: boolean); get emitClose(): boolean; get autoDestroy(): boolean; get closed(): boolean; set closed(value: boolean); get closeEmitted(): boolean; set closeEmitted(value: boolean); get allBuffers(): boolean; get allNoop(): boolean; get errored(): Error | null; set errored(value: Error | null); /** `false` on a Duplex whose writable side was disabled at construction. */ get writable(): boolean | undefined; set writable(value: boolean | undefined | null); get defaultEncoding(): BufferEncoding; set defaultEncoding(value: BufferEncoding); get writecb(): WriteCallback; set writecb(value: WriteCallback | null); get afterWriteTickInfo(): AfterWriteTickInfo | null; get buffered(): BufferedWrite[]; set buffered(value: BufferedWrite[] | null); get bufferedRequestCount(): number; getBuffer(): BufferedWrite[]; [kOnConstructed](stream: Writable): void; } /** * `_final` is declared here rather than in the class body because it has no default * implementation: `node:stream` types it as always present, and `prefinish()` checks for it * at runtime before calling it. */ export interface Writable { _final(callback: WriteCallback): void; } /** * A destination for data. * * Subclasses implement `_write()` (and optionally `_writev()`, `_final()`, `_destroy()` * and `_construct()`); the base class handles buffering, back-pressure and `drain`. */ export declare class Writable extends Stream implements Destroyable, NodeWritable { _writableState: WritableState; /** Present on a Duplex; `undefined` on a plain Writable. */ _readableState?: ReadableState; constructor(options?: WritableOptions); static readonly WritableState: typeof WritableState; /** Recognizes a Duplex, which inherits from Readable and so is not a structural subclass. */ static [Symbol.hasInstance](instance: unknown): boolean; /** Writables are not readable, so piping from one is always an error. */ pipe(dest: T): T; write(chunk: any, encoding?: BufferEncoding | null, callback?: WriteCallback): boolean; write(chunk: any, callback?: WriteCallback): boolean; /** Buffers writes until a matching number of `uncork()` calls. */ cork(): void; uncork(): void; setDefaultEncoding(encoding: BufferEncoding): this; _write(chunk: any, encoding: BufferEncoding, callback: WriteCallback): void; _writev?(chunks: WriteRequest[], callback: WriteCallback): void; _construct?(callback: DestroyCallback): void; end(callback?: WriteCallback): this; end(chunk: any, callback?: WriteCallback): this; end(chunk: any, encoding?: BufferEncoding | null, callback?: WriteCallback): this; get closed(): boolean; get destroyed(): boolean; set destroyed(value: boolean); get writable(): boolean; set writable(value: boolean); get writableFinished(): boolean; get writableObjectMode(): boolean; get writableBuffer(): BufferedWrite[] | undefined; get writableEnded(): boolean; get writableNeedDrain(): boolean; get writableHighWaterMark(): number; get writableCorked(): number; get writableLength(): number; get errored(): Error | null; get writableAborted(): boolean; destroy(error?: Error | null, callback?: DestroyCallback): this; _undestroy(): void; _destroy(error: Error | null, callback: DestroyCallback): void; [captureRejectionSymbol](err: Error): void; /** Wraps a WHATWG `WritableStream`. */ static fromWeb(writableStream: WritableStream, options?: WritableOptions): Writable; /** Exposes this stream as a WHATWG `WritableStream`. */ static toWeb(streamWritable: Writable): WritableStream; [Symbol.asyncDispose](): Promise; } export {};