summaryrefslogtreecommitdiff
path: root/std/node/_fs/promises/_fs_readFile.ts
diff options
context:
space:
mode:
authorBenjamin Lupton <b@lupton.cc>2020-06-24 12:32:43 +1000
committerGitHub <noreply@github.com>2020-06-23 22:32:43 -0400
commit49c54c0805ab26410a62e0251fee3a28b98c0e13 (patch)
treeb9fcb2713622f2739557f2caffd51d8bb454300b /std/node/_fs/promises/_fs_readFile.ts
parentd16337cc9c59732fe81655482e08b72d844472e6 (diff)
fix(std/node): fix readFile types, add encoding types (#6451)
Diffstat (limited to 'std/node/_fs/promises/_fs_readFile.ts')
-rw-r--r--std/node/_fs/promises/_fs_readFile.ts22
1 files changed, 17 insertions, 5 deletions
diff --git a/std/node/_fs/promises/_fs_readFile.ts b/std/node/_fs/promises/_fs_readFile.ts
index 9e4a4ed43..83ef9ac50 100644
--- a/std/node/_fs/promises/_fs_readFile.ts
+++ b/std/node/_fs/promises/_fs_readFile.ts
@@ -1,16 +1,28 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { FileOptions } from "../_fs_common.ts";
-import { MaybeEmpty } from "../../_utils.ts";
-
+import {
+ FileOptionsArgument,
+ BinaryOptionsArgument,
+ TextOptionsArgument,
+} from "../_fs_common.ts";
import { readFile as readFileCallback } from "../_fs_readFile.ts";
export function readFile(
path: string | URL,
- options?: FileOptions | string
-): Promise<MaybeEmpty<string | Uint8Array>> {
+ options: TextOptionsArgument
+): Promise<string>;
+export function readFile(
+ path: string | URL,
+ options?: BinaryOptionsArgument
+): Promise<Uint8Array>;
+export function readFile(
+ path: string | URL,
+ options?: FileOptionsArgument
+): Promise<string | Uint8Array> {
return new Promise((resolve, reject) => {
readFileCallback(path, options, (err, data): void => {
if (err) return reject(err);
+ if (data == null)
+ return reject(new Error("Invalid state: data missing, but no error"));
resolve(data);
});
});