Skip to main content
在 Bun 中,Response 对象可以接受 Node.js 的 Readable 这是因为 Bun 的 Response 对象允许任何异步可迭代对象作为其主体。Node.js 流是异步可迭代对象,因此你可以直接将它们传递给 Response
https://mintcdn.com/ikxin/RzFFGbzo0-4huILA/icons/typescript.svg?fit=max&auto=format&n=RzFFGbzo0-4huILA&q=85&s=a3dffd2241f05776d3bd25171d0c5a79server.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" },
    });
  },
});