fix: content conversion bug

pull/2479/head
adrieljss 5 months ago
parent 9b472c2015
commit 57eb09b350
No known key found for this signature in database
GPG Key ID: 849F13CBD0B4AD05

@ -186,23 +186,31 @@ export async function fetch(
throw new Error(ERROR_REQUEST_CANCELLED)
}
const streamChannel = new Channel<Uint8Array>()
const streamChannel = new Channel<ArrayBuffer | number[]>()
const readableStreamBody = new ReadableStream({
start: (controller) => {
streamChannel.onmessage = (res: Uint8Array) => {
streamChannel.onmessage = (res: ArrayBuffer | number[]) => {
// close early if aborted
if (signal?.aborted) {
controller.error(ERROR_REQUEST_CANCELLED)
controller.close()
return
}
if (!res.length) {
// close when the signal to close (an empty chunk)
// is sent from the IPC.
if (res instanceof ArrayBuffer
? res.byteLength == 0
: res.length == 0) {
controller.close()
return
}
controller.enqueue(res)
// the content conversion (like .text(), .json(), etc.) in Response
// must have Uint8Array as its content, else it will
// have untraceable error that's hard to debug.
controller.enqueue(new Uint8Array(res))
}
}
})

Loading…
Cancel
Save