Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the different between stat fstat and lstat functions in node js

Tags:

node.js

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.

like image 536
bharath Avatar asked Sep 09 '15 11:09

bharath


People also ask

What is the difference between stat and Lstat?

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.

What is the difference between stat () and fstat ()?

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).

Why stat () fstat () and lstat () functions are used explain the difference between stat () and fstat () functions?

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.

What is the use of the method stat in the File System API of node?

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.


1 Answers

  • 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.
like image 182
Dan D. Avatar answered Sep 16 '22 18:09

Dan D.