( readable: ReadableStream<Uint8Array>, res: ServerResponse, waitUntilForEnd?: Promise<unknown> )
| 121 | } |
| 122 | |
| 123 | export 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 | } |
no test coverage detected