summaryrefslogtreecommitdiff
path: root/std/node/_fs/_fs_readFile.ts
diff options
context:
space:
mode:
authorAli Hasani <a.hassssani@gmail.com>2020-05-03 23:44:38 +0430
committerGitHub <noreply@github.com>2020-05-03 15:14:38 -0400
commit5cc0f056d1af6f76c6ad81a6cd68dcaabba60f35 (patch)
tree4a32cb418ca84aba47e05e6dc6c98e8ef724fcd0 /std/node/_fs/_fs_readFile.ts
parent7e32269f3f230c5b714bbf70aa59d74f9a867373 (diff)
[std/node] add the ability to path argument to be URL type (#5055)
Diffstat (limited to 'std/node/_fs/_fs_readFile.ts')
-rw-r--r--std/node/_fs/_fs_readFile.ts7
1 files changed, 5 insertions, 2 deletions
diff --git a/std/node/_fs/_fs_readFile.ts b/std/node/_fs/_fs_readFile.ts
index 13e82bfe1..8d3c96db0 100644
--- a/std/node/_fs/_fs_readFile.ts
+++ b/std/node/_fs/_fs_readFile.ts
@@ -5,6 +5,7 @@ import {
intoCallbackAPIWithIntercept,
MaybeEmpty,
} from "../_utils.ts";
+import { fromFileUrl } from "../path.ts";
const { readFile: denoReadFile, readFileSync: denoReadFileSync } = Deno;
@@ -51,10 +52,11 @@ function maybeDecode(
}
export function readFile(
- path: string,
+ path: string | URL,
optOrCallback: ReadFileCallback | ReadFileOptions,
callback?: ReadFileCallback
): void {
+ path = path instanceof URL ? fromFileUrl(path) : path;
let cb: ReadFileCallback | undefined;
if (typeof optOrCallback === "function") {
cb = optOrCallback;
@@ -73,8 +75,9 @@ export function readFile(
}
export function readFileSync(
- path: string,
+ path: string | URL,
opt?: ReadFileOptions
): string | Uint8Array {
+ path = path instanceof URL ? fromFileUrl(path) : path;
return maybeDecode(denoReadFileSync(path), getEncoding(opt));
}