Push streams
History
Introduced in: v25.9.0
v25.9.0
push(...transforms?, options?): Object
Attributes
options:
Objectbudget?:
numberMaximum number of buffered bytes before
backpressure is applied. Must be >= 16384.
Default:
16384.backpressure?:
stringBackpressure policy:
'strict', 'unbounded',
'drop-oldest', or 'drop-newest'. Default: 'strict'.signal:
AbortSignalAbort the stream.
Returns:
Objectwriter:
WritableThe writer side.
readable:
AsyncIterablewhose chunks fulfill with
Uint8Array[]Create a push stream with backpressure. The writer pushes data in; the readable side is consumed as an async iterable.
import { push, text } from 'node:stream/iter'; const { writer, readable } = push(); // Producer and consumer must run concurrently. With strict backpressure // (the default), awaited writes block until the consumer reads. const producing = (async () => { await writer.write('hello'); await writer.write(' world'); await writer.end(); })(); console.log(await text(readable)); // 'hello world' await producing;
const { push, text } = require('node:stream/iter'); async function run() { const { writer, readable } = push(); // Producer and consumer must run concurrently. With strict backpressure // (the default), awaited writes block until the consumer reads. const producing = (async () => { await writer.write('hello'); await writer.write(' world'); await writer.end(); })(); console.log(await text(readable)); // 'hello world' await producing; } run().catch(console.error);
The writer returned by push() conforms to the [Writer interface][].