summaryrefslogtreecommitdiff
path: root/cli/rt/26_fetch.js
diff options
context:
space:
mode:
Diffstat (limited to 'cli/rt/26_fetch.js')
-rw-r--r--cli/rt/26_fetch.js20
1 files changed, 11 insertions, 9 deletions
diff --git a/cli/rt/26_fetch.js b/cli/rt/26_fetch.js
index 1c1d8c78f..ca36d7ba4 100644
--- a/cli/rt/26_fetch.js
+++ b/cli/rt/26_fetch.js
@@ -5,7 +5,6 @@
const { notImplemented } = window.__bootstrap.util;
const { getHeaderValueParams, isTypedArray } = window.__bootstrap.webUtil;
const { Blob, bytesSymbol: blobBytesSymbol } = window.__bootstrap.blob;
- const { read } = window.__bootstrap.io;
const { close } = window.__bootstrap.resources;
const Body = window.__bootstrap.body;
const { ReadableStream } = window.__bootstrap.streams;
@@ -283,6 +282,7 @@
body,
clientRid,
);
+ const rid = fetchResponse.bodyRid;
if (
NULL_BODY_STATUS.includes(fetchResponse.status) ||
@@ -294,25 +294,27 @@
responseBody = null;
} else {
responseBody = new ReadableStream({
+ type: "bytes",
async pull(controller) {
try {
- const b = new Uint8Array(1024 * 32);
- const result = await read(fetchResponse.bodyRid, b);
- if (result === null) {
+ const result = await core.jsonOpAsync("op_fetch_read", { rid });
+ if (!result || !result.chunk) {
controller.close();
- return close(fetchResponse.bodyRid);
+ close(rid);
+ } else {
+ // TODO(ry) This is terribly inefficient. Make this zero-copy.
+ const chunk = new Uint8Array(result.chunk);
+ controller.enqueue(chunk);
}
-
- controller.enqueue(b.subarray(0, result));
} catch (e) {
controller.error(e);
controller.close();
- close(fetchResponse.bodyRid);
+ close(rid);
}
},
cancel() {
// When reader.cancel() is called
- close(fetchResponse.bodyRid);
+ close(rid);
},
});
}