2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-09-02 17:07:11 -04:00
|
|
|
import { open, openSync } from "./files.ts";
|
|
|
|
import { readAll, readAllSync } from "./buffer.ts";
|
2019-03-09 12:30:38 -05:00
|
|
|
|
2020-06-11 12:36:20 -04:00
|
|
|
export function readFileSync(path: string | URL): Uint8Array {
|
2020-03-06 11:29:23 -05:00
|
|
|
const file = openSync(path);
|
2019-03-27 23:29:36 -04:00
|
|
|
const contents = readAllSync(file);
|
|
|
|
file.close();
|
|
|
|
return contents;
|
2019-03-09 12:30:38 -05:00
|
|
|
}
|
|
|
|
|
2020-06-11 12:36:20 -04:00
|
|
|
export async function readFile(path: string | URL): Promise<Uint8Array> {
|
2020-03-06 11:29:23 -05:00
|
|
|
const file = await open(path);
|
2019-03-27 23:29:36 -04:00
|
|
|
const contents = await readAll(file);
|
|
|
|
file.close();
|
|
|
|
return contents;
|
2019-03-09 12:30:38 -05:00
|
|
|
}
|