UseReadFile
katanakit-js / useReadFile
Function: useReadFile()
Section titled “Function: useReadFile()”function useReadFile(path, encoding?): Promise<FilesystemResult<string>>;Defined in: infrastructure/filesystem/filesystem.service.ts:137
Reads a text file.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
path |
string |
undefined |
File path (relative paths resolve against process.cwd()). |
encoding? |
| "utf-8" | "utf8" | "ascii" | "base64" | "base64url" | "hex" | "latin1" | "binary" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" |
"utf8" |
Text encoding (default: "utf8"). |
Returns
Section titled “Returns”Promise<FilesystemResult<string>>
Safe Result with the file contents as a string.
Example
Section titled “Example”import { useReadFile } from "katanakit-js";
const result = await useReadFile("data/books.json");if (result.ok) console.log(result.data);