from(input)


从给定输入创建一个异步字节流。字符串使用 UTF-8 编码。ArrayBufferArrayBufferView 值被封装为 Uint8Array。数组和可迭代对象会被递归展开并规范化。

🌐 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 are recursively flattened and normalized.

实现 Symbol.for('Stream.toAsyncStreamable')Symbol.for('Stream.toStreamable') 的对象通过这些协议进行转换。toAsyncStreamable 协议优先于 toStreamable,而 toStreamable 又优先于迭代协议(Symbol.asyncIteratorSymbol.iterator)。

🌐 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);