readFile
Reads a file and returns its binary content.
Example
ts
import { SF } from "@duplojs/server-utils";
import { E, unwrap } from "@duplojs/utils";
const decoder = new TextDecoder();
const result = await SF.readFile("/tmp/file.bin");
// result: FileSystemLeft | Success<Uint8Array>
if (E.isRight(result)) {
const fileBytes = unwrap(result);
const fileContent = decoder.decode(fileBytes);
// fileContent: string
}Syntax
typescript
function readFile(
path: string | URL
): Promise<FileSystemLeft | E.Success<Uint8Array>>Parameters
path: path of the file to read.
Return value
E.Success<Uint8Array>: the file content.FileSystemLeft: if the read fails.
See also
readTextFile- Reads a text file.
