Skip to content

Commit

Permalink
chore: cleanup readAll() logic (denoland#21862)
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua authored Jan 9, 2024
1 parent be888c0 commit 19c10c0
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions ext/io/12_io.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const {
ArrayPrototypePush,
TypedArrayPrototypeSubarray,
TypedArrayPrototypeSet,
TypedArrayPrototypeGetBuffer,
TypedArrayPrototypeGetByteLength,
} = primordials;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -275,7 +266,6 @@ export {
iterSync,
read,
readAll,
readAllInner,
readAllSync,
readSync,
SeekMode,
Expand Down

0 comments on commit 19c10c0

Please sign in to comment.