blob: 75d9453de29f1eb7423a37501c29d20e3347058f [file] [log] [blame]
import fs from "fs";
import path from "path";
export interface FileSystem {
exists(path: string): boolean;
readFile(path: string, encoding?: BufferEncoding): Promise<string>;
}
export class RealFileSystem implements FileSystem {
constructor(private readonly root: string) {}
exists(p: string): boolean {
return fs.existsSync(path.join(this.root, p));
}
async readFile(p: string, encoding?: BufferEncoding): Promise<string> {
const contents = await fs.promises.readFile(path.join(this.root, p));
return contents.toString(encoding);
}
}