Bun

指南

使用 Bun 將 Node.js Readable 轉換為 Uint8Array

在 Bun 中,要將 Node.js 的 Readable 流轉換為 Uint8Array,您可以建立一個新的 Response 物件,並將流作為其 body,然後使用 bytes() 將流讀取到 Uint8Array 中。

import { Readable } from "stream";
const stream = Readable.from(["Hello, ", "world!"]);
const buf = await new Response(stream).bytes();