import type { Stream } from './legacy.js'; import type { ReadableState } from './readable.js'; import type { WritableState } from './writable.js'; import { type Callback } from './util.js'; export declare const kDestroy: unique symbol; export declare const kConstruct: unique symbol; export type DestroyCallback = Callback; /** The internals `destroy()` reaches for. Both state sides are optional so this covers Readable, Writable and Duplex. */ export interface Destroyable extends Stream { _readableState?: ReadableState; _writableState?: WritableState; _destroy(error: Error | null, callback: DestroyCallback): void; _construct?(callback: DestroyCallback): void; destroy(error?: Error | null, callback?: DestroyCallback): this; } export declare function destroy(this: Destroyable, err?: Error | null, callback?: DestroyCallback): Destroyable; /** Resets a destroyed stream so it can be used again. Exposed as `_undestroy()`. */ export declare function undestroy(this: Destroyable): void; /** * Fails `stream` with `err`, destroying it when `autoDestroy` is on and otherwise emitting `error` directly. * `sync` defers the emission by a tick, for callers already inside a synchronous stream callback. */ export declare function errorOrDestroy(stream: Destroyable, err?: Error | null, sync?: boolean): void; /** Runs the stream's `_construct()` hook, holding off `_destroy()` and reads until it completes. */ export declare function construct(stream: Destroyable, callback: () => void): void; /** Destroys any stream-like value, including legacy streams that only have `close()`. */ export declare function destroyer(stream: unknown, err?: Error | null): void;