LEQADA LEQADA - 10 days ago 6
Node.js Question

How isFile() function from fs.Stats class works?

There are no details about

isFile()
function in documentation of fs.Stats class

How it works? What exactly it checks?

Answer

At the OS level an entry for a given entry is marked as either a file or a directory entry. That information does not appear to be directly surfaced in the fs.Stats data structure, but it is something that the isFile() method can tell from the fs.Stats data structure.

By looking at the code for fs.js in node.js, you can see these:

fs.Stats.prototype._checkModeProperty = function(property) {
  return ((this.mode & constants.S_IFMT) === property);
};

fs.Stats.prototype.isFile = function() {
  return this._checkModeProperty(constants.S_IFREG);
};

Which shows that the information is contained within the mode property of the fs.Stats data structure.

Comments