mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -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,
|
ArrayPrototypePush,
|
||||||
TypedArrayPrototypeSubarray,
|
TypedArrayPrototypeSubarray,
|
||||||
TypedArrayPrototypeSet,
|
TypedArrayPrototypeSet,
|
||||||
TypedArrayPrototypeGetBuffer,
|
|
||||||
TypedArrayPrototypeGetByteLength,
|
TypedArrayPrototypeGetByteLength,
|
||||||
} = primordials;
|
} = primordials;
|
||||||
|
|
||||||
|
@ -112,26 +111,18 @@ function write(rid, data) {
|
||||||
|
|
||||||
const READ_PER_ITER = 64 * 1024; // 64kb
|
const READ_PER_ITER = 64 * 1024; // 64kb
|
||||||
|
|
||||||
function readAll(r) {
|
async function readAll(r) {
|
||||||
return readAllInner(r);
|
|
||||||
}
|
|
||||||
async function readAllInner(r, options) {
|
|
||||||
const buffers = [];
|
const buffers = [];
|
||||||
const signal = options?.signal ?? null;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
signal?.throwIfAborted();
|
|
||||||
const buf = new Uint8Array(READ_PER_ITER);
|
const buf = new Uint8Array(READ_PER_ITER);
|
||||||
const read = await r.read(buf);
|
const read = await r.read(buf);
|
||||||
if (typeof read == "number") {
|
if (typeof read == "number") {
|
||||||
ArrayPrototypePush(
|
ArrayPrototypePush(buffers, TypedArrayPrototypeSubarray(buf, 0, read));
|
||||||
buffers,
|
|
||||||
new Uint8Array(TypedArrayPrototypeGetBuffer(buf), 0, read),
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
signal?.throwIfAborted();
|
|
||||||
|
|
||||||
return concatBuffers(buffers);
|
return concatBuffers(buffers);
|
||||||
}
|
}
|
||||||
|
@ -275,7 +266,6 @@ export {
|
||||||
iterSync,
|
iterSync,
|
||||||
read,
|
read,
|
||||||
readAll,
|
readAll,
|
||||||
readAllInner,
|
|
||||||
readAllSync,
|
readAllSync,
|
||||||
readSync,
|
readSync,
|
||||||
SeekMode,
|
SeekMode,
|
||||||
|
|
Loading…
Add table
Reference in a new issue