bytes(source[, options])
新增于: v25.9.0
sourceAsyncIterable|Iterable options<Object>signal<AbortSignal>limit<number> 要消耗的最大字节数。如果收集的总字节数超过限制,将抛出ERR_OUT_OF_RANGE错误
- 返回:<Promise> 使用
Uint8Array对象完成。
将流中的所有字节收集到一个 Uint8Array 中。
🌐 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);