summaryrefslogtreecommitdiff
path: root/std/node/_fs/_fs_readFile.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/node/_fs/_fs_readFile.ts')
-rw-r--r--std/node/_fs/_fs_readFile.ts39
1 files changed, 5 insertions, 34 deletions
diff --git a/std/node/_fs/_fs_readFile.ts b/std/node/_fs/_fs_readFile.ts
index 8d3c96db0..6021c84e0 100644
--- a/std/node/_fs/_fs_readFile.ts
+++ b/std/node/_fs/_fs_readFile.ts
@@ -1,10 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import {
- notImplemented,
- intoCallbackAPIWithIntercept,
- MaybeEmpty,
-} from "../_utils.ts";
+import { intoCallbackAPIWithIntercept, MaybeEmpty } from "../_utils.ts";
+
+import { getEncoding, FileOptions } from "./_fs_common.ts";
import { fromFileUrl } from "../path.ts";
const { readFile: denoReadFile, readFileSync: denoReadFileSync } = Deno;
@@ -14,33 +12,6 @@ type ReadFileCallback = (
data: MaybeEmpty<string | Uint8Array>
) => void;
-interface ReadFileOptions {
- encoding?: string | null;
- flag?: string;
-}
-
-function getEncoding(
- optOrCallback?: ReadFileOptions | ReadFileCallback
-): string | null {
- if (!optOrCallback || typeof optOrCallback === "function") {
- return null;
- } else {
- if (optOrCallback.encoding) {
- if (
- optOrCallback.encoding === "utf8" ||
- optOrCallback.encoding === "utf-8"
- ) {
- return "utf8";
- } else if (optOrCallback.encoding === "buffer") {
- return "buffer";
- } else {
- notImplemented();
- }
- }
- return null;
- }
-}
-
function maybeDecode(
data: Uint8Array,
encoding: string | null
@@ -53,7 +24,7 @@ function maybeDecode(
export function readFile(
path: string | URL,
- optOrCallback: ReadFileCallback | ReadFileOptions,
+ optOrCallback: ReadFileCallback | FileOptions,
callback?: ReadFileCallback
): void {
path = path instanceof URL ? fromFileUrl(path) : path;
@@ -76,7 +47,7 @@ export function readFile(
export function readFileSync(
path: string | URL,
- opt?: ReadFileOptions
+ opt?: FileOptions
): string | Uint8Array {
path = path instanceof URL ? fromFileUrl(path) : path;
return maybeDecode(denoReadFileSync(path), getEncoding(opt));