Bun では、Response オブジェクトは Node.js の Readable を受け入れることができます。
これは、Bun の Response オブジェクトが任意の非同期イテラブルをボディとして許可しているためです。Node.js ストリームは非同期イテラブルなので、Response に直接渡すことができます。
ts
import { Readable } from "stream";
import { serve } from "bun";
serve({
port: 3000,
fetch(req) {
return new Response(Readable.from(["Hello, ", "world!"]), {
headers: { "Content-Type": "text/plain" },
});
},
});