Function: makeBunBodyStream()
makeBunBodyStream(
rawRequest):Readable|undefined
Defined in: service-core/src/http/bun/BunAdapters.ts:413
Exposes a Bun request body as a Node Readable stream instead of buffering it, for a route
registered with { streamingBody: true } (see HttpRouteOptions). Much simpler than the uWS
equivalent (makeBodyStream()) because rawRequest.body is already a real, backpressure-aware
Web ReadableStream — Readable.fromWeb() adapts it without copying, so pulling from the
returned Readable (e.g. via for await or .pipe()) drives the same pull-based backpressure
all the way back to the underlying Bun socket.
Returns undefined for a request with no body (e.g. GET), matching req.rawBody/req.body being
left undefined in that case on the ordinary buffering path.
Destroys the returned stream if the client disconnects mid-upload, via the request's own
AbortSignal — mirroring makeBodyStream()'s uWS onAborted-driven cleanup — so a handler
consuming it via for await sees a thrown error instead of hanging forever.
A route that never reads the returned stream at all can still trigger that destroy() (the request
simply gets aborted independently, e.g. the client navigating away), so a permanent no-op error
listener is attached — a Readable with no active consumer still emits error on destroy(err),
and Node treats a zero-listener error event as fatal (crashes the process). This doesn't swallow
anything from a real consumer: EventEmitter calls every registered listener, not just the first, so
for await/.pipe()/an explicit .on("error") still see the same event independently.
Parameters
rawRequest
Request
Returns
Readable | undefined