From 08441b855d8cfbe7edd41811c8c719e5fae01f83 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 19 Oct 2020 17:01:36 +0200 Subject: [PATCH] fix(op_crates/fetch): Body.body should be stream of Uint8Array (#8030) --- cli/tests/unit/fetch_test.ts | 4 +++- op_crates/fetch/26_fetch.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 64309c2694..ab92997116 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -133,6 +133,7 @@ unitTest({ perms: { net: true } }, async function fetchAsyncIterator(): Promise< assert(response.body !== null); let total = 0; for await (const chunk of response.body) { + assert(chunk instanceof Uint8Array); total += chunk.length; } @@ -145,12 +146,13 @@ unitTest({ perms: { net: true } }, async function fetchBodyReader(): Promise< const response = await fetch("http://localhost:4545/cli/tests/fixture.json"); const headers = response.headers; assert(response.body !== null); - const reader = await response.body.getReader(); + const reader = response.body.getReader(); let total = 0; while (true) { const { done, value } = await reader.read(); if (done) break; assert(value); + assert(value instanceof Uint8Array); total += value.length; } diff --git a/op_crates/fetch/26_fetch.js b/op_crates/fetch/26_fetch.js index 88744981b5..887e329f9d 100644 --- a/op_crates/fetch/26_fetch.js +++ b/op_crates/fetch/26_fetch.js @@ -786,7 +786,7 @@ this._stream = new ReadableStream({ start(controller) { - controller.enqueue(buf); + controller.enqueue(new Uint8Array(buf)); controller.close(); }, });