text(source[, options])


  • source AsyncIterable|Iterable
  • options <Object>
    • encoding <string> 文本编码。默认: 'utf-8'
    • signal <AbortSignal>
    • limit <number> 要消耗的最大字节数。如果收集的总字节数超过限制,将抛出 ERR_OUT_OF_RANGE 错误
  • 返回:Promise

收集所有字节并将其解码为文本。

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