MCPcopy
hub / github.com/vercel/next.js / pipeToNodeResponse

Function pipeToNodeResponse

packages/next/src/server/pipe-readable.ts:123–146  ·  view source on GitHub ↗
(
  readable: ReadableStream<Uint8Array>,
  res: ServerResponse,
  waitUntilForEnd?: Promise<unknown>
)

Source from the content-addressed store, hash-verified

121}
122
123export async function pipeToNodeResponse(
124 readable: ReadableStream<Uint8Array>,
125 res: ServerResponse,
126 waitUntilForEnd?: Promise<unknown>
127) {
128 try {
129 // If the response has already errored, then just return now.
130 const { errored, destroyed } = res
131 if (errored || destroyed) return
132
133 // Create a new AbortController so that we can abort the readable if the
134 // client disconnects.
135 const controller = createAbortController(res)
136
137 const writer = createWriterFromResponse(res, waitUntilForEnd)
138
139 await readable.pipeTo(writer, { signal: controller.signal })
140 } catch (err: any) {
141 // If this isn't related to an abort error, re-throw it.
142 if (isAbortError(err)) return
143
144 throw new Error('failed to pipe response', { cause: err })
145 }
146}

Callers 5

sendResponseFunction · 0.90
pipeToNodeResponseMethod · 0.90
NextNodeServerClass · 0.90
runEdgeFunctionMethod · 0.90
handleRequestFunction · 0.90

Calls 4

createAbortControllerFunction · 0.90
createWriterFromResponseFunction · 0.85
isAbortErrorFunction · 0.85
pipeToMethod · 0.45

Tested by

no test coverage detected