On this page

Push streams

History
M

push

History
push(...transforms?, options?): Object
Attributes
...transforms:Function | Object
Optional transforms applied to the readable side.
options:Object
budget?:number
Maximum number of buffered bytes before backpressure is applied. Must be >= 16384. Default: 16384.
backpressure?:string
Backpressure policy: 'strict', 'unbounded', 'drop-oldest', or 'drop-newest'. Default: 'strict'.
Abort the stream.
Returns:Object
writer:Writable
The writer side.
readable:AsyncIterable
whose 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][].