diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-05-20 08:50:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-20 02:50:48 -0400 |
commit | eb5acb39d5936d3e0fde44a33357cda88a5ff55f (patch) | |
tree | 8595b6fea985fcedffc1a92cd2f3de49c1c7ceb4 /std/node/_fs/promises/_fs_readFile.ts | |
parent | 62c34bc21e8864ec5701ad493c73224367627580 (diff) |
feat(std/node): Add fs.promises.readFile (#5656)
Diffstat (limited to 'std/node/_fs/promises/_fs_readFile.ts')
-rw-r--r-- | std/node/_fs/promises/_fs_readFile.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/std/node/_fs/promises/_fs_readFile.ts b/std/node/_fs/promises/_fs_readFile.ts new file mode 100644 index 000000000..9e4a4ed43 --- /dev/null +++ b/std/node/_fs/promises/_fs_readFile.ts @@ -0,0 +1,17 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +import { FileOptions } from "../_fs_common.ts"; +import { MaybeEmpty } from "../../_utils.ts"; + +import { readFile as readFileCallback } from "../_fs_readFile.ts"; + +export function readFile( + path: string | URL, + options?: FileOptions | string +): Promise<MaybeEmpty<string | Uint8Array>> { + return new Promise((resolve, reject) => { + readFileCallback(path, options, (err, data): void => { + if (err) return reject(err); + resolve(data); + }); + }); +} |