| 16 | constructor(private base: string) {} |
| 17 | |
| 18 | async list(_path: string): Promise<string[]> { |
| 19 | const dir = this.canonical(_path); |
| 20 | const entries = fs |
| 21 | .readdirSync(dir) |
| 22 | .map((entry: string) => ({entry, stats: fs.statSync(path.join(dir, entry))})); |
| 23 | const files = entries |
| 24 | .filter((entry: any) => !entry.stats.isDirectory()) |
| 25 | .map((entry: any) => path.posix.join(_path, entry.entry)); |
| 26 | |
| 27 | return entries |
| 28 | .filter((entry: any) => entry.stats.isDirectory()) |
| 29 | .map((entry: any) => path.posix.join(_path, entry.entry)) |
| 30 | .reduce( |
| 31 | async (list: Promise<string[]>, subdir: string) => |
| 32 | (await list).concat(await this.list(subdir)), |
| 33 | Promise.resolve(files), |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | async read(_path: string): Promise<string> { |
| 38 | const file = this.canonical(_path); |