Streams
pipeline()
Connect stages, report completion or failure, and optionally cancel through a signal. Local Node 22.16.0; production target compatibility pending. See https://nodejs.org/download/release/v22.16.0/docs/api/stream.html.
Formal Syntax & Structure
nodejs syntaxnodejs
pipeline(source, ...transforms, destination[, options])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| source | stream or iterable | Initial data source. |
| transforms | stream or function | Optional processing stages. |
| destination | stream or function | Final receiver. |
| options | object | Optional signal and other supported options. |
Return Value
Promise
Result or receiver of the documented operation; see the linked versioned API contract.
Working Example
Example Snippetnodejs
import { Readable, Writable, Transform } from 'node:stream';import { pipeline, finished } from 'node:stream/promises';const bytes = Buffer.from('café');async function* decode(source){ const decoder = new TextDecoder('utf-8',{fatal:true}); for await(const chunk of source) yield decoder.decode(chunk,{stream:true}); yield decoder.decode();}let text='';await pipeline(Readable.from([bytes.subarray(0,4),bytes.subarray(4)]),decode,new Writable({write(c,e,cb){text+=c.toString();cb();}}));console.log(text);