Streams
Writable.write()
Queue a chunk and observe the boolean flow-control result. 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
writable.write(chunk[, encoding][, callback])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| chunk | string | Buffer | Uint8Array | object | Data accepted by the configured stream. |
| encoding | string | String encoding, when applicable. |
| callback | function | Optional write completion callback. |
Return Value
boolean
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';import { once } from 'node:events';const sink = new Writable({highWaterMark:1,write(c,e,cb){setImmediate(cb);}});const accepted = sink.write('x');console.log(accepted);if(!accepted) await once(sink,'drain');sink.end(); await finished(sink,{cleanup:true});console.log('done');