blob: 75d9453de29f1eb7423a37501c29d20e3347058f [file] [log] [blame]
gioa71316d2025-05-24 09:41:36 +04001import fs from "fs";
2import path from "path";
3
4export interface FileSystem {
5 exists(path: string): boolean;
6 readFile(path: string, encoding?: BufferEncoding): Promise<string>;
7}
8
9export 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}