summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/dts/lib.deno.ns.d.ts19
-rw-r--r--cli/tests/unit/read_file_test.ts22
2 files changed, 39 insertions, 2 deletions
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts
index 8ebf16150..da016db8a 100644
--- a/cli/dts/lib.deno.ns.d.ts
+++ b/cli/dts/lib.deno.ns.d.ts
@@ -861,6 +861,15 @@ declare namespace Deno {
mode?: number;
}
+ export interface ReadFileOptions {
+ /**
+ * An abort signal to allow cancellation of the file read operation.
+ * If the signal becomes aborted the readFile operation will be stopped
+ * and the promise returned will be rejected with an AbortError.
+ */
+ signal?: AbortSignal;
+ }
+
/**
*
* Check if a given resource id (`rid`) is a TTY.
@@ -1385,7 +1394,10 @@ declare namespace Deno {
* ```
*
* Requires `allow-read` permission. */
- export function readTextFile(path: string | URL): Promise<string>;
+ export function readTextFile(
+ path: string | URL,
+ options?: ReadFileOptions,
+ ): Promise<string>;
/** Synchronously reads and returns the entire contents of a file as an array
* of bytes. `TextDecoder` can be used to transform the bytes to string if
@@ -1411,7 +1423,10 @@ declare namespace Deno {
* ```
*
* Requires `allow-read` permission. */
- export function readFile(path: string | URL): Promise<Uint8Array>;
+ export function readFile(
+ path: string | URL,
+ options?: ReadFileOptions,
+ ): Promise<Uint8Array>;
/** A FileInfo describes a file and is returned by `stat`, `lstat`,
* `statSync`, `lstatSync`. */
diff --git a/cli/tests/unit/read_file_test.ts b/cli/tests/unit/read_file_test.ts
index 5f8ee2c11..d8d1cddf2 100644
--- a/cli/tests/unit/read_file_test.ts
+++ b/cli/tests/unit/read_file_test.ts
@@ -95,3 +95,25 @@ unitTest(
assertEquals(resourcesBefore, Deno.resources());
},
);
+
+unitTest(
+ { perms: { read: true } },
+ async function readFileWithAbortSignal(): Promise<void> {
+ const ac = new AbortController();
+ queueMicrotask(() => ac.abort());
+ await assertThrowsAsync(async () => {
+ await Deno.readFile("cli/tests/fixture.json", { signal: ac.signal });
+ });
+ },
+);
+
+unitTest(
+ { perms: { read: true } },
+ async function readTextileWithAbortSignal(): Promise<void> {
+ const ac = new AbortController();
+ queueMicrotask(() => ac.abort());
+ await assertThrowsAsync(async () => {
+ await Deno.readTextFile("cli/tests/fixture.json", { signal: ac.signal });
+ });
+ },
+);