diff --git a/std/node/_fs/_fs_readFile.ts b/std/node/_fs/_fs_readFile.ts index 6021c84e02..900d69f89d 100644 --- a/std/node/_fs/_fs_readFile.ts +++ b/std/node/_fs/_fs_readFile.ts @@ -24,7 +24,7 @@ function maybeDecode( export function readFile( path: string | URL, - optOrCallback: ReadFileCallback | FileOptions, + optOrCallback: ReadFileCallback | FileOptions | string, callback?: ReadFileCallback ): void { path = path instanceof URL ? fromFileUrl(path) : path; @@ -47,7 +47,7 @@ export function readFile( export function readFileSync( path: string | URL, - opt?: FileOptions + opt?: FileOptions | string ): string | Uint8Array { path = path instanceof URL ? fromFileUrl(path) : path; return maybeDecode(denoReadFileSync(path), getEncoding(opt)); diff --git a/std/node/_fs/_fs_readFile_test.ts b/std/node/_fs/_fs_readFile_test.ts index 429ceb3f54..1a850c91a0 100644 --- a/std/node/_fs/_fs_readFile_test.ts +++ b/std/node/_fs/_fs_readFile_test.ts @@ -35,6 +35,20 @@ test("readFileEncodeUtf8Success", async function () { assertEquals(data as string, "hello world"); }); +test("readFileEncodingAsString", async function () { + const data = await new Promise((res, rej) => { + readFile(testData, "utf8", (err, data) => { + if (err) { + rej(err); + } + res(data); + }); + }); + + assertEquals(typeof data, "string"); + assertEquals(data as string, "hello world"); +}); + test("readFileSyncSuccess", function () { const data = readFileSync(testData); assert(data instanceof Uint8Array); @@ -46,3 +60,9 @@ test("readFileEncodeUtf8Success", function () { assertEquals(typeof data, "string"); assertEquals(data as string, "hello world"); }); + +test("readFileEncodeAsString", function () { + const data = readFileSync(testData, "utf8"); + assertEquals(typeof data, "string"); + assertEquals(data as string, "hello world"); +});