(path: string, options?: { encoding?: string })
| 26 | } |
| 27 | |
| 28 | async readFile(path: string, options?: { encoding?: string }): Promise<Uint8Array | string> { |
| 29 | const normalized = path.startsWith('/') ? path.slice(1) : path; |
| 30 | const data = this.files.get(normalized); |
| 31 | |
| 32 | if (!data) { |
| 33 | const error: ErrnoException = new Error(`ENOENT: no such file or directory, open '${path}'`); |
| 34 | error.code = 'ENOENT'; |
| 35 | throw error; |
| 36 | } |
| 37 | |
| 38 | if (options?.encoding === 'utf8') { |
| 39 | return new TextDecoder().decode(data); |
| 40 | } |
| 41 | |
| 42 | return data; |
| 43 | } |
| 44 | |
| 45 | async readdir(dirPath: string): Promise<string[]> { |
| 46 | const normalized = dirPath === '/' ? '' : dirPath.startsWith('/') ? dirPath.slice(1) : dirPath; |
no test coverage detected