diff options
Diffstat (limited to 'packages/core/src/filesystem.ts')
| -rw-r--r-- | packages/core/src/filesystem.ts | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/packages/core/src/filesystem.ts b/packages/core/src/filesystem.ts index 44346be8f..8a1cc3a08 100644 --- a/packages/core/src/filesystem.ts +++ b/packages/core/src/filesystem.ts @@ -24,6 +24,7 @@ export namespace AppFileSystem { readonly isDir: (path: string) => Effect.Effect<boolean> readonly isFile: (path: string) => Effect.Effect<boolean> readonly existsSafe: (path: string) => Effect.Effect<boolean> + readonly readFileStringSafe: (path: string) => Effect.Effect<string | undefined, Error> readonly readJson: (path: string) => Effect.Effect<unknown, Error> readonly writeJson: (path: string, data: unknown, mode?: number) => Effect.Effect<void, Error> readonly ensureDir: (path: string) => Effect.Effect<void, Error> @@ -47,6 +48,12 @@ export namespace AppFileSystem { return yield* fs.exists(path).pipe(Effect.orElseSucceed(() => false)) }) + const readFileStringSafe = Effect.fn("FileSystem.readFileStringSafe")(function* (path: string) { + return yield* fs + .readFileString(path) + .pipe(Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed(undefined))) + }) + const isDir = Effect.fn("FileSystem.isDir")(function* (path: string) { const info = yield* fs.stat(path).pipe(Effect.catch(() => Effect.void)) return info?.type === "Directory" @@ -163,6 +170,7 @@ export namespace AppFileSystem { return Service.of({ ...fs, existsSafe, + readFileStringSafe, isDir, isFile, readDirectoryEntries, |
