-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
A proposal to add fs.scandir method to FS module #15699
Copy link
Copy link
Closed
Labels
blockedPRs that are blocked by other issues or PRs.PRs that are blocked by other issues or PRs.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.libuvIssues and PRs related to the libuv dependency or the uv binding.Issues and PRs related to the libuv dependency or the uv binding.
Metadata
Metadata
Assignees
Labels
blockedPRs that are blocked by other issues or PRs.PRs that are blocked by other issues or PRs.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.libuvIssues and PRs related to the libuv dependency or the uv binding.Issues and PRs related to the libuv dependency or the uv binding.
Problem
Now any interaction with files and directories in the File System is as follows:
The problem here is that we are call File System a second time due to the fact that we don't know the directory in front of us, or file (or symlink).
But we can reduce twice File System calls by creating
fs.scandirmethod that can returnd_nameandd_type. This information is returned fromuv_dirent_t(scandir) (libuv). For example, this is implemented in theLuvitandpyuv(also uselibuv).Motivation
String→Object→d_name+d_typefs.readdir: return convertedObjecttoStringfs.scandir: return As isnode-glob(also for each package that usesfs.readdirfor traversing directories) in most cases (needfs.statwhend_typeis aDT_UNKNOWNon the old FS)Proposed solution
Add a methods
fs.scandirandfs.scandirSyncin a standard Fyle System module.Where
entriesis an array of objects:name{String} – filename (d_nameinlibuv)type{Number} –fs.constants.S_*(d_typeinlibuv)Final words
Now I solved this problem by creating C++ Addon but... But I don't speak C++ or speak but very bad (i try 😅 ) and it requires you compile when you install a package that requires additional manipulation to the end user (like https://github.com/nodejs/node-gyp#on-windows).