From 5cc0f056d1af6f76c6ad81a6cd68dcaabba60f35 Mon Sep 17 00:00:00 2001 From: Ali Hasani Date: Sun, 3 May 2020 23:44:38 +0430 Subject: [std/node] add the ability to path argument to be URL type (#5055) --- std/node/_fs/_fs_readFile.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'std/node/_fs/_fs_readFile.ts') 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)); } -- cgit v1.2.3