( path: string | URL, options?: ReadFileOptions, )
| 28 | * @returns A promise that resolves to string of the file content. |
| 29 | */ |
| 30 | export 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. |
no test coverage detected