text(source[, options])
新增于: v25.9.0
sourceAsyncIterable|Iterable options<Object>encoding<string> 文本编码。默认:'utf-8'。signal<AbortSignal>limit<number> 要消耗的最大字节数。如果收集的总字节数超过限制,将抛出ERR_OUT_OF_RANGE错误
- 返回:<Promise> 用
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);