mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
feat(core): support AbortSignal in readFile (#10943)
This commit is contained in:
parent
9c0b41e24b
commit
20b0a5125a
4 changed files with 53 additions and 9 deletions
|
@ -110,9 +110,12 @@
|
|||
const READ_PER_ITER = 32 * 1024;
|
||||
|
||||
async function readAll(r) {
|
||||
return await readAllInner(r);
|
||||
}
|
||||
async function readAllInner(r, options) {
|
||||
const buffers = [];
|
||||
|
||||
while (true) {
|
||||
const signal = options?.signal ?? null;
|
||||
while (!signal?.aborted) {
|
||||
const buf = new Uint8Array(READ_PER_ITER);
|
||||
const read = await r.read(buf);
|
||||
if (typeof read == "number") {
|
||||
|
@ -121,6 +124,9 @@
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (signal?.aborted) {
|
||||
throw new DOMException("The read operation was aborted.", "AbortError");
|
||||
}
|
||||
|
||||
let totalLen = 0;
|
||||
for (const buf of buffers) {
|
||||
|
@ -177,6 +183,7 @@
|
|||
write,
|
||||
writeSync,
|
||||
readAll,
|
||||
readAllInner,
|
||||
readAllSync,
|
||||
};
|
||||
})(this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue