fs.Stats类的isFile()函数如何工作?

时间:2016-11-24 15:42:26

标签: node.js

documentation of fs.Stats class

中没有关于isFile()功能的详细信息

它是如何工作的?究竟检查了什么?

1 个答案:

答案 0 :(得分:1)

在OS级别,给定条目的条目被标记为文件或目录条目。该信息似乎并未在fs.Stats数据结构中直接显示,但isFile()方法可以从fs.Stats数据结构中了解该信息。

通过查看node.js中的code for fs.js,您可以看到以下内容:

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

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

这表明该信息包含在mode数据结构的fs.Stats属性中。