a user-land copy of the node:stream/consumers library from Node.js
npm install stream-consumersnode:stream/consumers for Deno, Browsers and older nodejs versions
(targeting NodeJS v16.7.0+ only? use node:stream/consumers instead)
imported instead of required.npm install stream-consumersThe utility consumer functions provide common options for consuming
streams.
They are accessed using:
``js`
import { arrayBuffer, blob, json, text } from 'stream-consumers'
#### streamConsumers.arrayBuffer(stream)
* stream {ReadableStream|stream.Readable|AsyncIterator}ArrayBuffer
* Returns: {Promise} Fulfills with an containing the full
contents of the stream.
#### streamConsumers.blob(stream)
* stream {ReadableStream|stream.Readable|AsyncIterator}
* Returns: {Promise} Fulfills with a {Blob} containing the full contents
of the stream.
#### streamConsumers.json(stream)
* stream {ReadableStream|stream.Readable|AsyncIterator}JSON.parse()
* Returns: {Promise} Fulfills with the contents of the stream parsed as a
UTF-8 encoded string that is then passed through .
#### streamConsumers.text(stream)
* stream {ReadableStream|stream.Readable|AsyncIterator}
* Returns: {Promise} Fulfills with the contents of the stream parsed as a
UTF-8 encoded string.
#### streamConsumers.buffer(stream) ⚠️ Not supported
Use arrayBuffer(stream).then(Buffer.from) instead if you realy want a Buffer.
(you should be using uint8array instead for better Browser/Deno bundles.
Response can be a grate hack to abuse it's feature to convert mostly anything else
without the need for this library.
new Response(new ReadableStream({...})).json()
But this can't work with async iterator or node:streams` that's when you should be using this utility stream consumers that all accepts async iterators.