bytes(source[, options])


新增于: v25.9.0
  • source AsyncIterable|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);

AltStyle によって変換されたページ (->オリジナル) /