Skip to content

ReadableStream ​

ReadableStream<T> is a read-only capability returned by native adapters such as file reads and child-process output.

SignatureReadableStream<T>

Methods ​

MethodSignaturePurpose
read() => Promise<T?>Resolves with the next value or empty at end-of-stream.
pipeTo(destination: WritableStream<T>) => Promise<void>Copies values progressively and closes the destination after normal EOF.
close() => Promise<void>Abandons unread values and wakes blocked writers.

Usage ​

tyrus
async function consume(stream: ReadableStream<u8[]>, destination: WritableStream<u8[]>): Promise<void> {
    const first: u8[]? = await stream.read();
    if (first) {
        await destination.write(first);
    }
    await stream.pipeTo(destination);
}

error

tyrus
async function invalid(readable: ReadableStream<u8[]>, bytes: u8[]): Promise<void> {
await readable.write(bytes); 
}

Errors ​

read(), pipeTo(), and close() reject with StreamError when the stream has failed or an operation violates its lifecycle. pipeTo() preserves a structured error produced by its source or destination. Cancelling a pending pipeTo() operation fails both endpoints with ERR_STREAM_CANCELLED and discards their buffered chunks.