( path: string | URL, options?: ReadFileOptions, )
| 25 | * @returns A promise that resolves to a `Uint8Array` of the file contents. |
| 26 | */ |
| 27 | export async function readFile( |
| 28 | path: string | URL, |
| 29 | options?: ReadFileOptions, |
| 30 | ): Promise<Uint8Array> { |
| 31 | if (isDeno) { |
| 32 | return Deno.readFile(path, { ...options }); |
| 33 | } else { |
| 34 | const { signal } = options ?? {}; |
| 35 | try { |
| 36 | const buf = await getNodeFs().promises.readFile(path, { signal }); |
| 37 | return new Uint8Array(buf.buffer, buf.byteOffset, buf.length); |
| 38 | } catch (error) { |
| 39 | throw mapError(error); |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Synchronously reads and returns the entire contents of a file as an array |
no test coverage detected