MCPcopy Create free account
hub / github.com/denoland/std / readTextFile

Function readTextFile

fs/unstable_read_text_file.ts:30–47  ·  view source on GitHub ↗
(
  path: string | URL,
  options?: ReadFileOptions,
)

Source from the content-addressed store, hash-verified

28 * @returns A promise that resolves to string of the file content.
29 */
30export async function readTextFile(
31 path: string | URL,
32 options?: ReadFileOptions,
33): Promise<string> {
34 if (isDeno) {
35 return Deno.readTextFile(path, { ...options });
36 } else {
37 const { signal } = options ?? {};
38 try {
39 return await getNodeFs().promises.readFile(path, {
40 encoding: "utf-8",
41 signal,
42 });
43 } catch (error) {
44 throw mapError(error);
45 }
46 }
47}
48
49/**
50 * Synchronously reads and returns the entire contents of a file as an UTF-8 decoded string.

Calls 2

getNodeFsFunction · 0.90
mapErrorFunction · 0.90

Tested by

no test coverage detected