1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

chore: cleanup readAll() logic (#21862)

This commit is contained in:
Asher Gomez 2024-01-09 23:53:28 +11:00 committed by GitHub
parent be888c068c
commit 19c10c0246
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,