summaryrefslogtreecommitdiff
path: root/runtime/js
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/js')
-rw-r--r--runtime/js/12_io.js11
-rw-r--r--runtime/js/40_read_file.js10
2 files changed, 14 insertions, 7 deletions
diff --git a/runtime/js/12_io.js b/runtime/js/12_io.js
index 8df3de92f..d2b2127a6 100644
--- a/runtime/js/12_io.js
+++ b/runtime/js/12_io.js
@@ -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);
diff --git a/runtime/js/40_read_file.js b/runtime/js/40_read_file.js
index 7eee28d89..75cfd8074 100644
--- a/runtime/js/40_read_file.js
+++ b/runtime/js/40_read_file.js
@@ -4,7 +4,7 @@
((window) => {
const core = window.Deno.core;
const { open, openSync } = window.__bootstrap.files;
- const { readAll, readAllSync } = window.__bootstrap.io;
+ const { readAllInner, readAllSync } = window.__bootstrap.io;
function readFileSync(path) {
const file = openSync(path);
@@ -16,10 +16,10 @@
}
}
- async function readFile(path) {
+ async function readFile(path, options) {
const file = await open(path);
try {
- const contents = await readAll(file);
+ const contents = await readAllInner(file, options);
return contents;
} finally {
file.close();
@@ -36,10 +36,10 @@
}
}
- async function readTextFile(path) {
+ async function readTextFile(path, options) {
const file = await open(path);
try {
- const contents = await readAll(file);
+ const contents = await readAllInner(file, options);
return core.decode(contents);
} finally {
file.close();