Function
tryReadFile
(
filePath: string,
defaultValue: string | null = null,
)
Source from the content-addressed store, hash-verified
| 2 | import * as path from "path"; |
| 3 | |
| 4 | export function tryReadFile( |
| 5 | filePath: string, |
| 6 | defaultValue: string | null = null, |
| 7 | ): string | null { |
| 8 | try { |
| 9 | const content = fs.readFileSync(filePath, "utf-8"); |
| 10 | return content; |
| 11 | } catch (error) { |
| 12 | return defaultValue; |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | export function writeFile(filePath: string, content: string) { |
| 17 | // create dirs |
Tested by
no test coverage detected