/** * Copyright (c) 2026 AzerothJS. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ /** * @internal A Node readable as a response body, owned HERE rather than by `Readable.toWeb`. * * Node's adapter keeps its `'data'` listener attached after a cancel and enqueues whatever the * source emits next onto a controller it has already closed. A cancelled download reaches that * state routinely: the adapter destroys the socket, cancels this reader, and a source whose flow * was resumed a tick earlier still delivers one more chunk. The enqueue throws synchronously * inside the emitter, above every framework catch, so a client that stalls and disconnects * mid-download takes the process down with it. * * So the boundary is written out: one latch closed by cancel, end or error, and nothing touches * the controller after it. Backpressure is the adapter's own rule (enqueue, pause when the queue * is full, resume on pull), and cancel destroys the source WITH its reason, so a source that * distinguishes an abort from a broken pipe still can and its file descriptor is released. * * This lives in one module because it was fixed in one caller first and the other kept the * crash: a compressed download and a static file both cross this boundary, and a rule that * exists twice is a rule that gets fixed once. */ import type { Readable } from 'node:stream'; /** @internal How one caller wants a truncated body reported. */ export interface WebStreamOptions { /** * Builds the error for a source that closed without ending. The default is an unbranded * `ERR_STREAM_PREMATURE_CLOSE`, which the error path reads as the server fault a truncated * read is; a caller whose truncation means the PEER left supplies a client-fault error * instead. It is per-caller because the same event means opposite things: a compressed * response stops short because the client went away, a file read stops short because the * file or the disk did. */ prematureClose?: () => Error; } /** * @internal Wraps `source` as a web stream that cannot enqueue after it settles. * * @param source - The Node readable to serve. It is paused immediately and driven by `pull`. * @param options - Per-caller policy; see {@link WebStreamOptions}. * @returns A web stream suitable as a `Response` body. */ export declare function webStreamOf(source: Readable, options?: WebStreamOptions): ReadableStream;