I am bit confused with the different between stat fstat and lstat functions in node.js. Could someone help to understand what is the major difference btwn stat, fstat and lstat functions in node.js and When to use stat, fstat and lstat functions.
lstat() is identical to stat(), except that if pathname is a symbolic link, then it returns information about the link itself, not the file that the link refers to. fstat() is identical to stat(), except that the file about which information is to be retrieved is specified by the file descriptor fd.
fstat() is identical to stat() , except that the file about which information is to be retrieved is specified by a file descriptor (instead of a file name).
stat() stats the file pointed to by path and fills in buf. lstat() is identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the file that it refers to. fstat() is identical to stat(), except that the file to be stat-ed is specified by the file descriptor filedes.
stat() method is used to return information about the given file or directory. The Promise is resolved with the fs. Stats object for the given path.
stat
follows symlinks. When given a path that is a symlink, it returns the stat of the target of the symlink.lstat
doesn't follow symlinks. When given a path that is a symlink it returns the stat of the symlink and not its target.fstat
takes a file descriptor rather than a path.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With