mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
chore: cleanup readAll()
logic (#21862)
This commit is contained in:
parent
be888c068c
commit
19c10c0246
1 changed files with 3 additions and 13 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue