diff options
author | Benjamin Gruenbaum <benjamingr@gmail.com> | 2022-01-21 19:42:21 +0300 |
---|---|---|
committer | Benjamin Gruenbaum <benjamingr@gmail.com> | 2022-01-23 19:43:16 +0300 |
commit | a8afe26fca2d3a7c374f86834525084e10ddc1a1 (patch) | |
tree | 7309be337554092b4978ed0130c1d7695b6c8f53 /doc/api/stream.md | |
parent | 3d27a04b5647d3a357f940dff24603b19da08767 (diff) |
stream: add drop and take
This adds the `drop` and `take` methods to readable streams allowing
users easily drop and take items from the stream.
This continues the iterator-helper proposal alignment task.
Co-Authored-By: Robert Nagy <ronagy@icloud.com>
PR-URL: https://github.com/nodejs/node/pull/41630
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'doc/api/stream.md')
-rw-r--r-- | doc/api/stream.md | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/doc/api/stream.md b/doc/api/stream.md index 1a1b5081be4..c8b9e4400e4 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -2074,6 +2074,50 @@ for await (const result of concatResult) { } ``` +### `readable.drop(limit[, options])` + +<!-- YAML +added: REPLACEME +--> + +> Stability: 1 - Experimental + +* `limit` {number} the number of chunks to drop from the readable. +* `options` {Object} + * `signal` {AbortSignal} allows destroying the stream if the signal is + aborted. +* Returns: {Readable} a stream with `limit` chunks dropped. + +This method returns a new stream with the first `limit` chunks dropped. + +```mjs +import { Readable } from 'stream'; + +await Readable.from([1, 2, 3, 4]).drop(2).toArray(); // [3, 4] +``` + +### `readable.take(limit[, options])` + +<!-- YAML +added: REPLACEME +--> + +> Stability: 1 - Experimental + +* `limit` {number} the number of chunks to take from the readable. +* `options` {Object} + * `signal` {AbortSignal} allows destroying the stream if the signal is + aborted. +* Returns: {Readable} a stream with `limit` chunks taken. + +This method returns a new stream with the first `limit` chunks. + +```mjs +import { Readable } from 'stream'; + +await Readable.from([1, 2, 3, 4]).take(2).toArray(); // [1, 2] +``` + ### Duplex and transform streams #### Class: `stream.Duplex` |