Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2021-07-31 01:02:13 +0300
committerJames M Snell <jasnell@gmail.com>2021-08-07 01:42:58 +0300
commitc52410710e35150eb88e33de18ae7056b6c8754c (patch)
tree2a9fbb62055110d0c6fd8488c1a410de883bc181 /doc/api/webstreams.md
parente4b1fb5e6422c1ff151234bb9de792d45dd88d87 (diff)
stream: utility consumers for web and node.js streams
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/39594 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'doc/api/webstreams.md')
-rw-r--r--doc/api/webstreams.md73
1 files changed, 73 insertions, 0 deletions
diff --git a/doc/api/webstreams.md b/doc/api/webstreams.md
index d99a66a7163..67675d62975 100644
--- a/doc/api/webstreams.md
+++ b/doc/api/webstreams.md
@@ -1270,5 +1270,78 @@ added: REPLACEME
* Type: {WritableStream}
+### Utility Consumers
+<!-- YAML
+added: REPLACEME
+-->
+
+The utility consumer functions provide common options for consuming
+streams.
+
+They are accessed using:
+
+```mjs
+import {
+ arrayBuffer,
+ blob,
+ json,
+ text,
+} from 'node:stream/consumers';
+```
+
+```cjs
+const {
+ arrayBuffer,
+ blob,
+ json,
+ text,
+} = require('stream/consumers');
+```
+
+#### `streamConsumers.arrayBuffer(stream)`
+<!-- YAML
+added: REPLACEME
+-->
+
+* `stream` {ReadableStream|stream.Readable|AsyncIterator}
+* Returns: {Promise} Fulfills with an `ArrayBuffer` containing the full
+ contents of the stream.
+
+#### `streamConsumers.blob(stream)`
+<!-- YAML
+added: REPLACEME
+-->
+
+* `stream` {ReadableStream|stream.Readable|AsyncIterator}
+* Returns: {Promise} Fulfills with a {Blob} containing the full contents
+ of the stream.
+
+#### `streamConsumers.buffer(stream)`
+<!-- YAML
+added: REPLACEME
+-->
+
+* `stream` {ReadableStream|stream.Readable|AsyncIterator}
+* Returns: {Promise} Fulfills with a {Buffer} containing the full
+ contents of the stream.
+
+#### `streamConsumers.json(stream)`
+<!-- YAML
+added: REPLACEME
+-->
+
+* `stream` {ReadableStream|stream.Readable|AsyncIterator}
+* Returns: {Promise} Fulfills with the contents of the stream parsed as a
+ UTF-8 encoded string that is then passed through `JSON.parse()`.
+
+#### `streamConsumers.text(stream)`
+<!-- YAML
+added: REPLACEME
+-->
+
+* `stream` {ReadableStream|stream.Readable|AsyncIterator}
+* Returns: {Promise} Fulfills with the contents of the stream parsed as a
+ UTF-8 encoded string.
+
[Streams]: stream.md
[WHATWG Streams Standard]: https://streams.spec.whatwg.org/