| gio | a71316d | 2025-05-24 09:41:36 +0400 | [diff] [blame] | 1 | import fs from "fs"; |
| 2 | import path from "path"; |
| 3 | |
| 4 | export interface FileSystem { |
| 5 | exists(path: string): boolean; |
| 6 | readFile(path: string, encoding?: BufferEncoding): Promise<string>; |
| 7 | } |
| 8 | |
| 9 | export class RealFileSystem implements FileSystem { |
| 10 | constructor(private readonly root: string) {} |
| 11 | |
| 12 | exists(p: string): boolean { |
| 13 | return fs.existsSync(path.join(this.root, p)); |
| 14 | } |
| 15 | |
| 16 | async readFile(p: string, encoding?: BufferEncoding): Promise<string> { |
| 17 | const contents = await fs.promises.readFile(path.join(this.root, p)); |
| 18 | return contents.toString(encoding); |
| 19 | } |
| 20 | } |