diff options
author | Asher Gomez <ashersaupingomez@gmail.com> | 2024-01-09 23:53:28 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-09 13:53:28 +0100 |
commit | 19c10c024623a227bc68b6606bc2f32d25030ab7 (patch) | |
tree | 1c7752183df08bc7a266c5762bc2602e4872d17b | |
parent | be888c068cbe42c1cb93d9885827dc97aa40d6f6 (diff) |
chore: cleanup `readAll()` logic (#21862)
-rw-r--r-- | ext/io/12_io.js | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/ext/io/12_io.js b/ext/io/12_io.js index 36cde6020..3bf05207d 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, |