@@ -111,14 +111,22 @@ async function run() {
111111
112112Transforms come in two forms:
113113
114- * ** Stateless** -- a function ` (chunks) => result ` called once per batch.
115- Receives ` Uint8Array[] ` (or ` null ` as the flush signal). Returns
116- ` Uint8Array[] ` , ` null ` , or an iterable of chunks.
114+ * ** Stateless** -- a function ` (chunks, options ) => result ` called once per
115+ batch. Receives ` Uint8Array[] ` (or ` null ` as the flush signal) and an
116+ ` options ` object. Returns ` Uint8Array[] ` , ` null ` , or an iterable of chunks.
117117
118- * ** Stateful** -- an object ` { transform(source) } ` where ` transform ` is a
119- generator (sync or async) that receives the entire upstream iterable and
120- yields output. This form is used for compression, encryption, and any
121- transform that needs to buffer across batches.
118+ * ** Stateful** -- an object ` { transform(source, options) } ` where ` transform `
119+ is a generator (sync or async) that receives the entire upstream iterable
120+ and an ` options ` object, and yields output. This form is used for
121+ compression, encryption, and any transform that needs to buffer across
122+ batches.
123+
124+ Both forms receive an ` options ` parameter with the following property:
125+
126+ * ` options.signal ` {AbortSignal} An AbortSignal that fires when the pipeline
127+ is cancelled, encounters an error, or the consumer stops reading. Transforms
128+ can check ` signal.aborted ` or listen for the ` 'abort' ` event to perform
129+ early cleanup.
122130
123131The flush signal (` null ` ) is sent after the source ends, giving transforms
124132a chance to emit trailing data (e.g., compression footers).
@@ -169,7 +177,7 @@ The API supports two models:
169177
170178A writer is any object with a ` write(chunk) ` method. Writers optionally
171179support ` writev(chunks) ` for batch writes (mapped to scatter/gather I/O where
172- available), ` end() ` to signal completion, and ` abort (reason)` to signal
180+ available), ` end() ` to signal completion, and ` fail (reason)` to signal
173181failure.
174182
175183## ` require('node:stream/new') `
@@ -269,7 +277,7 @@ added: REPLACEME
269277 * ` signal ` {AbortSignal} Abort the pipeline.
270278 * ` preventClose ` {boolean} If ` true ` , do not call ` writer.end() ` when
271279 the source ends. ** Default:** ` false ` .
272- * ` preventAbort ` {boolean} If ` true ` , do not call ` writer.abort () ` on
280+ * ` preventFail ` {boolean} If ` true ` , do not call ` writer.fail () ` on
273281 error. ** Default:** ` false ` .
274282* Returns: {Promise\< number>} Total bytes written.
275283
@@ -316,7 +324,7 @@ added: REPLACEME
316324* ` writer ` {Object} Destination with ` write(chunk) ` method.
317325* ` options ` {Object}
318326 * ` preventClose ` {boolean} ** Default:** ` false ` .
319- * ` preventAbort ` {boolean} ** Default:** ` false ` .
327+ * ` preventFail ` {boolean} ** Default:** ` false ` .
320328* Returns: {number} Total bytes written.
321329
322330Synchronous version of [ ` pipeTo() ` ] [ ] .
@@ -451,12 +459,18 @@ run().catch(console.error);
451459
452460The writer returned by ` push() ` has the following methods:
453461
454- ##### ` writer.abort (reason) `
462+ ##### ` writer.fail (reason) `
455463
456464* ` reason ` {Error}
457465* Returns: {Promise\< void>}
458466
459- Abort the stream with an error.
467+ Fail the stream with an error.
468+
469+ ##### ` writer.failSync(reason) `
470+
471+ * ` reason ` {Error}
472+
473+ Synchronously fail the stream with an error. Does not return a promise.
460474
461475##### ` writer.desiredSize `
462476
@@ -465,15 +479,21 @@ Abort the stream with an error.
465479The number of buffer slots available before the high water mark is reached.
466480Returns ` null ` if the writer is closed or the consumer has disconnected.
467481
468- ##### ` writer.end() `
482+ ##### ` writer.end([options] ) `
469483
484+ * ` options ` {Object}
485+ * ` signal ` {AbortSignal} Cancel just this operation. The signal cancels only
486+ the pending ` end() ` call; it does not fail the writer itself.
470487* Returns: {Promise\< number>} Total bytes written.
471488
472489Signal that no more data will be written.
473490
474- ##### ` writer.write(chunk) `
491+ ##### ` writer.write(chunk[, options] ) `
475492
476493* ` chunk ` {Uint8Array|string}
494+ * ` options ` {Object}
495+ * ` signal ` {AbortSignal} Cancel just this write operation. The signal cancels
496+ only the pending ` write() ` call; it does not fail the writer itself.
477497* Returns: {Promise\< void>}
478498
479499Write a chunk. The promise resolves when buffer space is available.
@@ -486,9 +506,12 @@ Write a chunk. The promise resolves when buffer space is available.
486506
487507Synchronous write. Does not block; returns ` false ` if backpressure is active.
488508
489- ##### ` writer.writev(chunks) `
509+ ##### ` writer.writev(chunks[, options] ) `
490510
491511* ` chunks ` {Uint8Array\[ ] |string\[ ] }
512+ * ` options ` {Object}
513+ * ` signal ` {AbortSignal} Cancel just this write operation. The signal cancels
514+ only the pending ` writev() ` call; it does not fail the writer itself.
492515* Returns: {Promise\< void>}
493516
494517Write multiple chunks as a single batch.
0 commit comments