Skip to content

In Bun können Response Objekte einen Node.js Readable Stream akzeptieren.

Dies funktioniert, weil Buns Response-Objekt jedes asynchrone Iterable als Body erlaubt. Node.js Streams sind asynchrone Iterables, sodass Sie sie direkt an Response übergeben können.

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" },
    });
  },
});

Bun von www.bunjs.com.cn bearbeitet