Consumers
History
Introduced in: v25.9.0
v25.9.0
array(source, options?): Promise
Attributes
source:
AsyncIterable | Iterablewhose chunks must be
Uint8Array[]options:
Objectsignal:
AbortSignallimit:
numberMaximum number of bytes to consume. If the total bytes
collected exceeds limit, an
ERR_OUT_OF_RANGE error is thrownReturns:
PromiseFulfills with an array of
Uint8Array objects.Collect all chunks as an array of Uint8Array values (without concatenating).
arrayBuffer(source, options?): Promise
Attributes
source:
AsyncIterable | Iterablewhose chunks must be
Uint8Array[]options:
Objectsignal:
AbortSignallimit:
numberMaximum number of bytes to consume. If the total bytes
collected exceeds limit, an
ERR_OUT_OF_RANGE error is thrownReturns:
PromiseFulfills with an
ArrayBuffer object.Collect all bytes into an ArrayBuffer.
arrayBufferSync(source, options?): ArrayBuffer
Attributes
source:
Iterablewhose chunks must be
Uint8Array[]options:
Objectlimit:
numberMaximum number of bytes to consume. If the total bytes
collected exceeds limit, an
ERR_OUT_OF_RANGE error is thrownReturns:
ArrayBufferSynchronous version of arrayBuffer().
arraySync(source, options?): Uint8Array[]
Attributes
source:
Iterablewhose chunks must be
Uint8Array[]options:
Objectlimit:
numberMaximum number of bytes to consume. If the total bytes
collected exceeds limit, an
ERR_OUT_OF_RANGE error is thrownReturns:
Uint8Array[]Synchronous version of array().
bytes(source, options?): Promise
Attributes
source:
AsyncIterable | Iterablewhose chunks must be
Uint8Array[]options:
Objectsignal:
AbortSignallimit:
numberMaximum number of bytes to consume. If the total bytes
collected exceeds limit, an
ERR_OUT_OF_RANGE error is thrownReturns:
PromiseFulfills with an
Uint8Array object.Collect all bytes from a stream into a single Uint8Array.
import { from, bytes } from 'node:stream/iter'; const data = await bytes(from('hello')); console.log(data); // Uint8Array(5) [ 104, 101, 108, 108, 111 ]
const { from, bytes } = require('node:stream/iter'); async function run() { const data = await bytes(from('hello')); console.log(data); // Uint8Array(5) [ 104, 101, 108, 108, 111 ] } run().catch(console.error);
bytesSync(source, options?): Uint8Array
Attributes
source:
Iterablewhose chunks must be
Uint8Array[]options:
Objectlimit:
numberMaximum number of bytes to consume. If the total bytes
collected exceeds limit, an
ERR_OUT_OF_RANGE error is thrownReturns:
Uint8ArraySynchronous version of bytes().
text(source, options?): Promise
Attributes
source:
AsyncIterable | Iterablewhose chunks must be
Uint8Array[]options:
Objectencoding?:
stringText encoding. Default:
'utf-8'.signal:
AbortSignallimit:
numberMaximum number of bytes to consume. If the total bytes
collected exceeds limit, an
ERR_OUT_OF_RANGE error is thrownReturns:
PromiseFulfills with a
string.Collect all bytes and decode as text.
import { from, text } from 'node:stream/iter'; console.log(await text(from('hello'))); // 'hello'
const { from, text } = require('node:stream/iter'); async function run() { console.log(await text(from('hello'))); // 'hello' } run().catch(console.error);
textSync(source, options?): string
Attributes
Synchronous version of text().