summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2020-05-14 13:04:07 +0200
committerGitHub <noreply@github.com>2020-05-14 07:04:07 -0400
commit524b1547b7c291763d6ca066ce8e10ae6398190b (patch)
tree19a072a0c57ff7cfd9b6e17c31453d484f47e85a
parentb60cde4c0a3e2a14e543ac0436c2147b43bdfb24 (diff)
std/node fs.readFile should take string as option (#5316)
-rw-r--r--std/node/_fs/_fs_readFile.ts4
-rw-r--r--std/node/_fs/_fs_readFile_test.ts20
2 files changed, 22 insertions, 2 deletions
diff --git a/std/node/_fs/_fs_readFile.ts b/std/node/_fs/_fs_readFile.ts
index 6021c84e0..900d69f89 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 429ceb3f5..1a850c91a 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");
+});