Sources
History
from(input): AsyncIterable
string | ArrayBuffer | ArrayBufferView | Iterable | AsyncIterable | Objectnull or undefined.AsyncIterableUint8Array[].Create an async byte stream from the given input. Strings are UTF-8 encoded.
ArrayBuffer and ArrayBufferView values are wrapped as Uint8Array. Arrays
and iterables in input are recursively flattened and normalized.
Objects implementing Symbol.for('Stream.toAsyncStreamable') or
Symbol.for('Stream.toStreamable') are converted via those protocols. The
toAsyncStreamable protocol takes precedence over toStreamable, which takes
precedence over the iteration protocols (Symbol.asyncIterator,
Symbol.iterator).
import { Buffer } from 'node:buffer'; import { from, text } from 'node:stream/iter'; console.log(await text(from('hello'))); // 'hello' console.log(await text(from(Buffer.from('hello')))); // 'hello'
const { Buffer } = require('node:buffer'); const { from, text } = require('node:stream/iter'); async function run() { console.log(await text(from('hello'))); // 'hello' console.log(await text(from(Buffer.from('hello')))); // 'hello' } run().catch(console.error);
fromSync(input): Iterable
string | ArrayBuffer | ArrayBufferView | Iterable | Objectnull or undefined.IterableUint8Array[]Synchronous version of from(). Returns a sync iterable. Cannot accept
async iterables or promises. Objects implementing
Symbol.for('Stream.toStreamable') are converted via that protocol (takes
precedence over Symbol.iterator). The toAsyncStreamable protocol is
ignored entirely.
import { fromSync, textSync } from 'node:stream/iter'; console.log(textSync(fromSync('hello'))); // 'hello'
const { fromSync, textSync } = require('node:stream/iter'); console.log(textSync(fromSync('hello'))); // 'hello'