summaryrefslogtreecommitdiff
path: root/std/node/_fs/_fs_readFile.ts
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-02-02 19:05:46 +0800
committerGitHub <noreply@github.com>2021-02-02 12:05:46 +0100
commit6abf126c2a7a451cded8c6b5e6ddf1b69c84055d (patch)
treefd94c013a19fcb38954844085821ec1601c20e18 /std/node/_fs/_fs_readFile.ts
parenta2b5d44f1aa9d64f448a2a3cc2001272e2f60b98 (diff)
chore: remove std directory (#9361)
This removes the std folder from the tree. Various parts of the tests are pretty tightly dependent on std (47 direct imports and 75 indirect imports, not counting the cli tests that use them as fixtures) so I've added std as a submodule for now.
Diffstat (limited to 'std/node/_fs/_fs_readFile.ts')
-rw-r--r--std/node/_fs/_fs_readFile.ts97
1 files changed, 0 insertions, 97 deletions
diff --git a/std/node/_fs/_fs_readFile.ts b/std/node/_fs/_fs_readFile.ts
deleted file mode 100644
index 4ad763e25..000000000
--- a/std/node/_fs/_fs_readFile.ts
+++ /dev/null
@@ -1,97 +0,0 @@
-// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-import {
- BinaryOptionsArgument,
- FileOptionsArgument,
- getEncoding,
- TextOptionsArgument,
-} from "./_fs_common.ts";
-import { Buffer } from "../buffer.ts";
-import { fromFileUrl } from "../path.ts";
-import { BinaryEncodings, Encodings, TextEncodings } from "../_utils.ts";
-
-function maybeDecode(data: Uint8Array, encoding: TextEncodings): string;
-function maybeDecode(
- data: Uint8Array,
- encoding: BinaryEncodings | null,
-): Buffer;
-function maybeDecode(
- data: Uint8Array,
- encoding: Encodings | null,
-): string | Buffer {
- const buffer = new Buffer(data.buffer, data.byteOffset, data.byteLength);
- if (encoding && encoding !== "binary") return buffer.toString(encoding);
- return buffer;
-}
-
-type TextCallback = (err: Error | null, data?: string) => void;
-type BinaryCallback = (err: Error | null, data?: Buffer) => void;
-type GenericCallback = (err: Error | null, data?: string | Buffer) => void;
-type Callback = TextCallback | BinaryCallback | GenericCallback;
-
-export function readFile(
- path: string | URL,
- options: TextOptionsArgument,
- callback: TextCallback,
-): void;
-export function readFile(
- path: string | URL,
- options: BinaryOptionsArgument,
- callback: BinaryCallback,
-): void;
-export function readFile(
- path: string | URL,
- options: null | undefined | FileOptionsArgument,
- callback: BinaryCallback,
-): void;
-export function readFile(path: string | URL, callback: BinaryCallback): void;
-export function readFile(
- path: string | URL,
- optOrCallback?: FileOptionsArgument | Callback | null | undefined,
- callback?: Callback,
-): void {
- path = path instanceof URL ? fromFileUrl(path) : path;
- let cb: Callback | undefined;
- if (typeof optOrCallback === "function") {
- cb = optOrCallback;
- } else {
- cb = callback;
- }
-
- const encoding = getEncoding(optOrCallback);
-
- const p = Deno.readFile(path);
-
- if (cb) {
- p.then((data: Uint8Array) => {
- if (encoding && encoding !== "binary") {
- const text = maybeDecode(data, encoding);
- return (cb as TextCallback)(null, text);
- }
- const buffer = maybeDecode(data, encoding);
- (cb as BinaryCallback)(null, buffer);
- }, (err) => cb && cb(err));
- }
-}
-
-export function readFileSync(
- path: string | URL,
- opt: TextOptionsArgument,
-): string;
-export function readFileSync(
- path: string | URL,
- opt?: BinaryOptionsArgument,
-): Buffer;
-export function readFileSync(
- path: string | URL,
- opt?: FileOptionsArgument,
-): string | Buffer {
- path = path instanceof URL ? fromFileUrl(path) : path;
- const data = Deno.readFileSync(path);
- const encoding = getEncoding(opt);
- if (encoding && encoding !== "binary") {
- const text = maybeDecode(data, encoding);
- return text;
- }
- const buffer = maybeDecode(data, encoding);
- return buffer;
-}