node:stream/promises
Node-compatible promise-based stream helpers (node:stream/promises).
Available in both vjs and vjs-lite runtimes. Enabled by default unless
--no-node-compat is passed.
import ... from "node:stream/promises"
node-compat (enabled by default; disable with --no-node-compat)Example
Section titled “Example”import { PassThrough } from "node:stream";import { pipeline } from "node:stream/promises";
const src = new PassThrough();const dst = new PassThrough();src.end("hello");await pipeline(src, dst);Functions
Section titled “Functions”pipeline
Section titled “pipeline”export function pipeline(
streams: readonly unknown[],
options?: PipelineOptions,
): Promise<unknown>;
export function pipeline(...streams: unknown[]): Promise<unknown>;
Pipe an array of streams and iterables together, forwarding errors and resolving when the destination stream completes.
pipeline(streams, options?)| Name | Type | Description |
|---|---|---|
streams | readonly unknown[] | Ordered sequence of source, transform, and destination stages. |
options optional | PipelineOptions | Optional pipeline configuration. |
Promise<unknown> — Promise resolving with the final stage result or undefined.pipeline(...streams)Pipe variadic stream/transform/iterable stages together, optionally ending with a PipelineOptions object.
| Name | Type | Description |
|---|---|---|
...streams | unknown[] | Source, transforms, destination, and optional trailing PipelineOptions. |
Promise<unknown> — Promise resolving when the pipeline completes.finished
Section titled “finished”export function finished(stream: unknown, options?: FinishedOptions): Promise<void>;
Return a Promise that settles when stream is no longer readable, writable,
or has experienced an error or premature close.
| Name | Type | Description |
|---|---|---|
stream | unknown | Node or Web stream to observe. |
options optional | FinishedOptions | Optional completion flags and abort signal. |
Promise<void> — Promise resolving when stream finishes, or rejecting on error/abort.Interfaces
Section titled “Interfaces”AbortSignalLike
Section titled “AbortSignalLike”export interface AbortSignalLike {
readonly aborted: boolean;
readonly reason?: unknown;
addEventListener(type: string, listener: (...args: any[]) => void, options?: { once?: boolean }): void;
removeEventListener?(type: string, listener: (...args: any[]) => void): void;
}
Minimal abort-signal contract accepted by pipeline and finished.
| Property | Type | Description | Since |
|---|---|---|---|
aborted readonly | boolean | Whether the signal has already been aborted. | v0.0.0-alpha.2 |
reason readonly optional | unknown | Optional abort reason value. | v0.0.0-alpha.2 |
AbortSignalLike.addEventListener
Section titled “AbortSignalLike.addEventListener”addEventListener(type: string, listener: (...args: any[]) => void, options?: { once?: boolean }): void;
Register an "abort" listener.
| Name | Type | Description |
|---|---|---|
type | string | Event type ("abort"). |
listener | (...args: any[]) => void | Callback invoked on abort. |
options optional | { once?: boolean } | Optional listener options. |
voidAbortSignalLike.removeEventListener
Section titled “AbortSignalLike.removeEventListener”removeEventListener?(type: string, listener: (...args: any[]) => void): void;
Unregister an "abort" listener.
| Name | Type | Description |
|---|---|---|
type | string | Event type ("abort"). |
listener | (...args: any[]) => void | Callback to remove. |
voidPipelineOptions
Section titled “PipelineOptions”export interface PipelineOptions {
signal?: AbortSignalLike;
end?: boolean;
}
Options accepted by pipeline().
| Property | Type | Description | Since |
|---|---|---|---|
signal optional | AbortSignalLike | Optional abort signal cancelling the pipeline. | v0.0.0-alpha.2 |
end optional | boolean | End the destination stream when the source finishes (default true). | v0.0.0-alpha.2 |
FinishedOptions
Section titled “FinishedOptions”export interface FinishedOptions {
error?: boolean;
readable?: boolean;
writable?: boolean;
signal?: AbortSignalLike;
cleanup?: boolean;
}
Options accepted by finished().
| Property | Type | Description | Since |
|---|---|---|---|
error optional | boolean | Reject if the stream emits an error before finishing (default true). | v0.0.0-alpha.2 |
readable optional | boolean | Wait for readable side completion on duplex streams. | v0.0.0-alpha.2 |
writable optional | boolean | Wait for writable side completion on duplex streams. | v0.0.0-alpha.2 |
signal optional | AbortSignalLike | Optional abort signal cancelling the wait. | v0.0.0-alpha.2 |
cleanup optional | boolean | Clean up stream listeners on completion. | v0.0.0-alpha.2 |
Default Export
Section titled “Default Export”default export
Section titled “default export”const _default: {
/** Pipe streams together and await completion. @since 0.0.0-alpha.2 */
pipeline: typeof pipeline;
/** Await stream completion or failure. @since 0.0.0-alpha.2 */
finished: typeof finished;
};
export default _default;
Default export object providing { pipeline, finished }.
