* Synchronously reads the contents of a directory. * @param {string | Buffer | URL} path * @param {string | { * encoding?: string; * withFileTypes?: boolean; * recursive?: boolean; * }} [options] * @returns {string | Buffer[] | Dirent[]}
(path, options)
| 1866 | * @returns {string | Buffer[] | Dirent[]} |
| 1867 | */ |
| 1868 | function readdirSync(path, options) { |
| 1869 | const h = vfsState.handlers; |
| 1870 | if (h !== null) { |
| 1871 | const result = h.readdirSync(path, options); |
| 1872 | if (result !== undefined) return result; |
| 1873 | } |
| 1874 | options = getOptions(options); |
| 1875 | path = getValidatedPath(path); |
| 1876 | if (options.recursive != null) { |
| 1877 | validateBoolean(options.recursive, 'options.recursive'); |
| 1878 | } |
| 1879 | |
| 1880 | if (options.recursive) { |
| 1881 | return readdirSyncRecursive(path, options); |
| 1882 | } |
| 1883 | |
| 1884 | const result = binding.readdir( |
| 1885 | path, |
| 1886 | options.encoding, |
| 1887 | !!options.withFileTypes, |
| 1888 | ); |
| 1889 | |
| 1890 | return result !== undefined && options.withFileTypes ? getDirents(path, result) : result; |
| 1891 | } |
| 1892 | |
| 1893 | /** |
| 1894 | * Invokes the callback with the `fs.Stats` |
no test coverage detected
searching dependent graphs…