Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | 173x 114x 13107x 913x 913x 302x 302x 109x 13x 65x 65x 22x 84x 84x | /**
* NodeFileSystem
* Default implementation of IFileSystem using Node.js fs module.
*
* This is the production implementation used when no mock is injected.
*/
import {
readFileSync,
writeFileSync,
existsSync,
statSync,
mkdirSync,
readdirSync,
} from "node:fs";
import IFileSystem from "./types/IFileSystem";
/**
* Node.js file system implementation
*/
class NodeFileSystem implements IFileSystem {
readFile(path: string): string {
return readFileSync(path, "utf-8");
}
writeFile(path: string, content: string): void {
writeFileSync(path, content, "utf-8");
}
exists(path: string): boolean {
return existsSync(path);
}
isDirectory(path: string): boolean {
Iif (!existsSync(path)) {
return false;
}
return statSync(path).isDirectory();
}
isFile(path: string): boolean {
Iif (!existsSync(path)) {
return false;
}
return statSync(path).isFile();
}
mkdir(path: string, options?: { recursive?: boolean }): void {
mkdirSync(path, options);
}
readdir(path: string): string[] {
return readdirSync(path);
}
stat(path: string): { mtimeMs: number } {
const stats = statSync(path);
return { mtimeMs: stats.mtimeMs };
}
/** Shared singleton instance for use across all modules */
private static _instance: NodeFileSystem | null = null;
static get instance(): NodeFileSystem {
NodeFileSystem._instance ??= new NodeFileSystem();
return NodeFileSystem._instance;
}
}
export default NodeFileSystem;
|