* Return a flat list of all the files nested inside a directory * * Based on an elegant concurrent recursive solution from SO * https://stackoverflow.com/a/45130990/2168416 * * @param {string} dir - The directory to read. * @returns {Promise } - A flat list of all files in
(dir)
| 245 | * @returns {Promise<string[]>} - A flat list of all files in the directory. |
| 246 | */ |
| 247 | async readdirDeep(dir) { |
| 248 | const subdirs = await this._readdir(dir) |
| 249 | const files = await Promise.all( |
| 250 | subdirs.map(async subdir => { |
| 251 | const res = dir + '/' + subdir |
| 252 | return (await this._stat(res)).isDirectory() |
| 253 | ? this.readdirDeep(res) |
| 254 | : res |
| 255 | }) |
| 256 | ) |
| 257 | return files.reduce((a, f) => a.concat(f), []) |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Return the Stats of a file/symlink if it exists, otherwise returns null. |
no outgoing calls