From 862dfd7cbead4e4b0a8b7647600bf241497a89cc Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Tue, 9 Jan 2024 23:53:28 +1100 Subject: [PATCH] chore: cleanup `readAll()` logic (#21862) --- ext/io/12_io.js | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/ext/io/12_io.js b/ext/io/12_io.js index 36cde6020d..3bf05207d4 100644 --- a/ext/io/12_io.js +++ b/ext/io/12_io.js @@ -15,7 +15,6 @@ const { ArrayPrototypePush, TypedArrayPrototypeSubarray, TypedArrayPrototypeSet, - TypedArrayPrototypeGetBuffer, TypedArrayPrototypeGetByteLength, } = primordials; @@ -112,26 +111,18 @@ function write(rid, data) { const READ_PER_ITER = 64 * 1024; // 64kb -function readAll(r) { - return readAllInner(r); -} -async function readAllInner(r, options) { +async function readAll(r) { const buffers = []; - const signal = options?.signal ?? null; + while (true) { - signal?.throwIfAborted(); const buf = new Uint8Array(READ_PER_ITER); const read = await r.read(buf); if (typeof read == "number") { - ArrayPrototypePush( - buffers, - new Uint8Array(TypedArrayPrototypeGetBuffer(buf), 0, read), - ); + ArrayPrototypePush(buffers, TypedArrayPrototypeSubarray(buf, 0, read)); } else { break; } } - signal?.throwIfAborted(); return concatBuffers(buffers); } @@ -275,7 +266,6 @@ export { iterSync, read, readAll, - readAllInner, readAllSync, readSync, SeekMode,