On this page

Consumers

History
M

array

History
array(source, options?): Promise
Attributes
whose chunks must be Uint8Array[]
options:Object
limit:number
Maximum number of bytes to consume. If the total bytes collected exceeds limit, an ERR_OUT_OF_RANGE error is thrown
Returns:Promise
Fulfills with an array of Uint8Array objects.

Collect all chunks as an array of Uint8Array values (without concatenating).

M

arrayBuffer

History
arrayBuffer(source, options?): Promise
Attributes
whose chunks must be Uint8Array[]
options:Object
limit:number
Maximum number of bytes to consume. If the total bytes collected exceeds limit, an ERR_OUT_OF_RANGE error is thrown
Returns:Promise
Fulfills with an ArrayBuffer object.

Collect all bytes into an ArrayBuffer.

M

arrayBufferSync

History
arrayBufferSync(source, options?): ArrayBuffer
Attributes
source:Iterable
whose chunks must be Uint8Array[]
options:Object
limit:number
Maximum number of bytes to consume. If the total bytes collected exceeds limit, an ERR_OUT_OF_RANGE error is thrown
Returns:ArrayBuffer

Synchronous version of arrayBuffer().

M

arraySync

History
arraySync(source, options?): Uint8Array[]
Attributes
source:Iterable
whose chunks must be Uint8Array[]
options:Object
limit:number
Maximum number of bytes to consume. If the total bytes collected exceeds limit, an ERR_OUT_OF_RANGE error is thrown
Returns:Uint8Array[]

Synchronous version of array().

M

bytes

History
bytes(source, options?): Promise
Attributes
whose chunks must be Uint8Array[]
options:Object
limit:number
Maximum number of bytes to consume. If the total bytes collected exceeds limit, an ERR_OUT_OF_RANGE error is thrown
Returns:Promise
Fulfills 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);
M

bytesSync

History
bytesSync(source, options?): Uint8Array
Attributes
source:Iterable
whose chunks must be Uint8Array[]
options:Object
limit:number
Maximum number of bytes to consume. If the total bytes collected exceeds limit, an ERR_OUT_OF_RANGE error is thrown
Returns:Uint8Array

Synchronous version of bytes().

M

text

History
text(source, options?): Promise
Attributes
whose chunks must be Uint8Array[]
options:Object
encoding?:string
Text encoding. Default: 'utf-8'.
limit:number
Maximum number of bytes to consume. If the total bytes collected exceeds limit, an ERR_OUT_OF_RANGE error is thrown
Returns:Promise
Fulfills 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);
M

textSync

History
textSync(source, options?): string
Attributes
source:Iterable
whose chunks must be Uint8Array[]
options:Object
encoding?:string
Default: 'utf-8'.
limit:number
Maximum number of bytes to consume. If the total bytes collected exceeds limit, an ERR_OUT_OF_RANGE error is thrown
Returns:string

Synchronous version of text().