* Reads the contents of a directory. * @param {string | Buffer | URL} path * @param {string | { * encoding?: string; * withFileTypes?: boolean; * recursive?: boolean; * }} [options] * @param {( * err?: Error, * files?: string[] | Buffer[] | Dirent[] * ) => any} callback * @ret
(path, options, callback)
| 1812 | * @returns {void} |
| 1813 | */ |
| 1814 | function readdir(path, options, callback) { |
| 1815 | if (typeof options === 'function') { |
| 1816 | callback = options; |
| 1817 | options = undefined; |
| 1818 | } |
| 1819 | |
| 1820 | const h = vfsState.handlers; |
| 1821 | if (h !== null && vfsResult(h.readdir(path, options), callback)) return; |
| 1822 | |
| 1823 | callback = makeCallback(callback); |
| 1824 | options = getOptions(options); |
| 1825 | path = getValidatedPath(path); |
| 1826 | if (options.recursive != null) { |
| 1827 | validateBoolean(options.recursive, 'options.recursive'); |
| 1828 | } |
| 1829 | |
| 1830 | if (options.recursive) { |
| 1831 | // Make shallow copy to prevent mutating options from affecting results |
| 1832 | options = copyObject(options); |
| 1833 | |
| 1834 | readdirRecursive(path, options, callback); |
| 1835 | return; |
| 1836 | } |
| 1837 | |
| 1838 | const req = new FSReqCallback(); |
| 1839 | if (!options.withFileTypes) { |
| 1840 | req.oncomplete = callback; |
| 1841 | } else { |
| 1842 | req.oncomplete = (err, result) => { |
| 1843 | if (err) { |
| 1844 | callback(err); |
| 1845 | return; |
| 1846 | } |
| 1847 | getDirents(path, result, callback); |
| 1848 | }; |
| 1849 | } |
| 1850 | binding.readdir( |
| 1851 | path, |
| 1852 | options.encoding, |
| 1853 | !!options.withFileTypes, |
| 1854 | req, |
| 1855 | ); |
| 1856 | } |
| 1857 | |
| 1858 | /** |
| 1859 | * Synchronously reads the contents of a directory. |
nothing calls this directly
no test coverage detected
searching dependent graphs…