2020-05-20 02:50:48 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-07-08 05:26:39 -04:00
|
|
|
import type {
|
2020-06-23 22:32:43 -04:00
|
|
|
BinaryOptionsArgument,
|
2020-09-27 06:22:32 -04:00
|
|
|
FileOptionsArgument,
|
2020-06-23 22:32:43 -04:00
|
|
|
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-07-14 15:24:17 -04:00
|
|
|
options: TextOptionsArgument,
|
2020-06-23 22:32:43 -04:00
|
|
|
): Promise<string>;
|
|
|
|
export function readFile(
|
|
|
|
path: string | URL,
|
2020-07-14 15:24:17 -04:00
|
|
|
options?: BinaryOptionsArgument,
|
2020-06-23 22:32:43 -04:00
|
|
|
): Promise<Uint8Array>;
|
|
|
|
export function readFile(
|
|
|
|
path: string | URL,
|
2020-07-14 15:24:17 -04:00
|
|
|
options?: FileOptionsArgument,
|
2020-06-23 22:32:43 -04:00
|
|
|
): 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-07-08 05:26:39 -04:00
|
|
|
if (data == null) {
|
2020-06-23 22:32:43 -04:00
|
|
|
return reject(new Error("Invalid state: data missing, but no error"));
|
2020-07-08 05:26:39 -04:00
|
|
|
}
|
2020-05-20 02:50:48 -04:00
|
|
|
resolve(data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|