* An iterative algorithm for reading the entire contents of the `basePath` directory. * This function does not validate `basePath` as a directory. It is passed directly to * `binding.readdir`. * @param {string} basePath * @param {{ encoding: string, withFileTypes: boolean }} options * @returns
(basePath, options)
| 1764 | * @returns {string[] | Dirent[]} |
| 1765 | */ |
| 1766 | function readdirSyncRecursive(basePath, options) { |
| 1767 | const context = { |
| 1768 | withFileTypes: Boolean(options.withFileTypes), |
| 1769 | encoding: options.encoding, |
| 1770 | basePath, |
| 1771 | readdirResults: [], |
| 1772 | pathsQueue: [basePath], |
| 1773 | }; |
| 1774 | |
| 1775 | function read(path) { |
| 1776 | const readdirResult = binding.readdir( |
| 1777 | path, |
| 1778 | context.encoding, |
| 1779 | context.withFileTypes, |
| 1780 | ); |
| 1781 | |
| 1782 | if (readdirResult === undefined) { |
| 1783 | return; |
| 1784 | } |
| 1785 | |
| 1786 | processReaddirResult({ |
| 1787 | result: readdirResult, |
| 1788 | currentPath: path, |
| 1789 | context, |
| 1790 | }); |
| 1791 | } |
| 1792 | |
| 1793 | for (let i = 0; i < context.pathsQueue.length; i++) { |
| 1794 | read(context.pathsQueue[i]); |
| 1795 | } |
| 1796 | |
| 1797 | return context.readdirResults; |
| 1798 | } |
| 1799 | |
| 1800 | /** |
| 1801 | * Reads the contents of a directory. |
no test coverage detected
searching dependent graphs…