Skip to content

Commit 3cdd064

Browse files
jasnellMesteery
authored andcommitted
stream: utility consumers for web and node.js streams
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: nodejs#39594 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 03c2432 commit 3cdd064

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

doc/api/webstreams.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,79 @@ added: v16.7.0
12881288
added: v16.7.0
12891289
-->
12901290
1291+
* `stream` {ReadableStream|stream.Readable|AsyncIterator}
1292+
* Returns: {Promise} Fulfills with the contents of the stream parsed as a
1293+
UTF-8 encoded string.
1294+
1295+
### Utility Consumers
1296+
<!-- YAML
1297+
added: REPLACEME
1298+
-->
1299+
1300+
The utility consumer functions provide common options for consuming
1301+
streams.
1302+
1303+
They are accessed using:
1304+
1305+
```mjs
1306+
import {
1307+
arrayBuffer,
1308+
blob,
1309+
json,
1310+
text,
1311+
} from 'node:stream/consumers';
1312+
```
1313+
1314+
```cjs
1315+
const {
1316+
arrayBuffer,
1317+
blob,
1318+
json,
1319+
text,
1320+
} = require('stream/consumers');
1321+
```
1322+
1323+
#### `streamConsumers.arrayBuffer(stream)`
1324+
<!-- YAML
1325+
added: REPLACEME
1326+
-->
1327+
1328+
* `stream` {ReadableStream|stream.Readable|AsyncIterator}
1329+
* Returns: {Promise} Fulfills with an `ArrayBuffer` containing the full
1330+
contents of the stream.
1331+
1332+
#### `streamConsumers.blob(stream)`
1333+
<!-- YAML
1334+
added: REPLACEME
1335+
-->
1336+
1337+
* `stream` {ReadableStream|stream.Readable|AsyncIterator}
1338+
* Returns: {Promise} Fulfills with a {Blob} containing the full contents
1339+
of the stream.
1340+
1341+
#### `streamConsumers.buffer(stream)`
1342+
<!-- YAML
1343+
added: REPLACEME
1344+
-->
1345+
1346+
* `stream` {ReadableStream|stream.Readable|AsyncIterator}
1347+
* Returns: {Promise} Fulfills with a {Buffer} containing the full
1348+
contents of the stream.
1349+
1350+
#### `streamConsumers.json(stream)`
1351+
<!-- YAML
1352+
added: REPLACEME
1353+
-->
1354+
1355+
* `stream` {ReadableStream|stream.Readable|AsyncIterator}
1356+
* Returns: {Promise} Fulfills with the contents of the stream parsed as a
1357+
UTF-8 encoded string that is then passed through `JSON.parse()`.
1358+
1359+
#### `streamConsumers.text(stream)`
1360+
<!-- YAML
1361+
added: REPLACEME
1362+
-->
1363+
12911364
* `stream` {ReadableStream|stream.Readable|AsyncIterator}
12921365
* Returns: {Promise} Fulfills with the contents of the stream parsed as a
12931366
UTF-8 encoded string.

0 commit comments

Comments
 (0)