2020-05-20 02:50:48 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-06-23 22:32:43 -04:00
|
|
|
import {
|
|
|
|
FileOptionsArgument,
|
|
|
|
BinaryOptionsArgument,
|
|
|
|
TextOptionsArgument,
|
|
|
|
} from "../_fs_common.ts";
|
2020-05-20 02:50:48 -04:00
|
|
|
import { readFile as readFileCallback } from "../_fs_readFile.ts";
|
|
|
|
|
|
|
|
export function readFile(
|
|
|
|
path: string | URL,
|
2020-06-23 22:32:43 -04:00
|
|
|
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> {
|
2020-05-20 02:50:48 -04:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
readFileCallback(path, options, (err, data): void => {
|
|
|
|
if (err) return reject(err);
|
2020-06-23 22:32:43 -04:00
|
|
|
if (data == null)
|
|
|
|
return reject(new Error("Invalid state: data missing, but no error"));
|
2020-05-20 02:50:48 -04:00
|
|
|
resolve(data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|