From a5c9a2ed61612ab262dc20a3250270ca631a3bf8 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Tue, 6 Feb 2024 05:33:29 +0100 Subject: [PATCH] fix: fix the linux patch --- lib/fetch/index.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index 5d3bf459b5b..4b89b4a48e3 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -1099,16 +1099,12 @@ function fetchFinale (fetchParams, response) { const byteStream = new ReadableStream({ readableStream: transformStream.readable, + async start () { + this._bodyReader = this.readableStream.getReader() + }, async pull (controller) { - // TODO(mcollina): removen this block, not sure why pull() is called twice - if (this.readableStream.locked) { - return - } - - const reader = this.readableStream.getReader() - while (controller.desiredSize >= 0) { - const { done, value } = await reader.read() + const { done, value } = await this._bodyReader.read() if (done) { queueMicrotask(() => readableStreamClose(controller)) @@ -1910,8 +1906,8 @@ async function httpNetworkFetch ( // 11. Let pullAlgorithm be an action that resumes the ongoing fetch // if it is suspended. - const pullAlgorithm = () => { - fetchParams.controller.resume() + const pullAlgorithm = async () => { + await fetchParams.controller.resume() } // 12. Let cancelAlgorithm be an algorithm that aborts fetchParams’s @@ -2026,9 +2022,7 @@ async function httpNetworkFetch ( // into stream. const buffer = new Uint8Array(bytes) if (buffer.byteLength) { - try { - fetchParams.controller.controller.enqueue(buffer) - } catch {} + fetchParams.controller.controller.enqueue(buffer) } // 8. If stream is errored, then terminate the ongoing fetch. @@ -2039,7 +2033,7 @@ async function httpNetworkFetch ( // 9. If stream doesn’t need more data ask the user agent to suspend // the ongoing fetch. - if (!fetchParams.controller.controller.desiredSize) { + if (fetchParams.controller.controller.desiredSize <= 0) { return } }