In node v10.10.0 with merge request #22020 was added a new flag withFileTypes to fs.readdir:
If options.withFileTypes is set to true, the files array will contain fs.Dirent objects.
It is really great addition and I have a couple ideas to share.
Would be great if fs.Dirent contain all information fs.Stat has. I can see no reason to create new entity for such simple data structure which is half duplicated.
Lets compare them:
fs.Dirent
dirent.isBlockDevice()
dirent.isCharacterDevice()
dirent.isDirectory()
dirent.isFIFO()
dirent.isFile()
dirent.isSocket()
dirent.isSymbolicLink()
dirent.name
fs.Stats
stats.isBlockDevice()
stats.isCharacterDevice()
stats.isDirectory()
stats.isFIFO()
stats.isFile()
stats.isSocket()
stats.isSymbolicLink()
stats.dev
stats.ino
stats.mode
stats.nlink
stats.uid
stats.gid
stats.rdev
stats.size
stats.blksize
stats.blocks
stats.atimeMs
stats.mtimeMs
stats.ctimeMs
stats.birthtimeMs
stats.atime
stats.mtime
stats.ctime
stats.birthtime
The only thing that missing in fs.Stats it's name.
Is your feature request related to a problem? Please describe.
I'm working on file manager for the web Cloud Commander, so I do such things all the time: read directory content and then get stat of every file. Now this all done in readify. And I would like to use the new approach of reading files with stats, it can simplify my code a lot, and make node API cleaner.
Right now if I use a flag withFileTypes I will need to call fs.stat anyways because I need not only divide files and directories but also get their size, mode, uid and mtime.
Describe the solution you'd like
I suggest to change withFileTypes behavior to get real stat information: like size, mtime, uid in method call:
fs.readdirSync('/', {withFileTypes: true});
And remove this fs.Dirent.
Describe alternatives you've considered
Also we can use something like withFileStats to get full stats (maybe with names).
fs.readdirSync('/', {withFileStats: true})
In node v10.10.0 with merge request #22020 was added a new flag
withFileTypesto fs.readdir:It is really great addition and I have a couple ideas to share.
Would be great if fs.Dirent contain all information fs.Stat has. I can see no reason to create new entity for such simple data structure which is half duplicated.
Lets compare them:
fs.Dirent
dirent.isBlockDevice()dirent.isCharacterDevice()dirent.isDirectory()dirent.isFIFO()dirent.isFile()dirent.isSocket()dirent.isSymbolicLink()dirent.namefs.Stats
stats.isBlockDevice()stats.isCharacterDevice()stats.isDirectory()stats.isFIFO()stats.isFile()stats.isSocket()stats.isSymbolicLink()stats.devstats.inostats.modestats.nlinkstats.uidstats.gidstats.rdevstats.sizestats.blksizestats.blocksstats.atimeMsstats.mtimeMsstats.ctimeMsstats.birthtimeMsstats.atimestats.mtimestats.ctimestats.birthtimeThe only thing that missing in
fs.Statsit's name.Is your feature request related to a problem? Please describe.
I'm working on file manager for the web Cloud Commander, so I do such things all the time: read directory content and then get stat of every file. Now this all done in readify. And I would like to use the new approach of reading files with stats, it can simplify my code a lot, and make node
APIcleaner.Right now if I use a flag
withFileTypesI will need to callfs.statanyways because I need not only divide files and directories but also get theirsize,mode,uidandmtime.Describe the solution you'd like
I suggest to change
withFileTypesbehavior to get realstatinformation: likesize,mtime,uidin method call:And remove this
fs.Dirent.Describe alternatives you've considered
Also we can use something like
withFileStatsto get full stats (maybe with names).