2014-05-23 18:14:06 +00:00
|
|
|
var Constants = require('./constants.js');
|
2018-05-26 20:57:57 +00:00
|
|
|
var Path = require('./path.js');
|
2014-03-18 16:29:20 +00:00
|
|
|
|
2014-03-29 19:21:53 +00:00
|
|
|
// https://github.com/nodejs/node/blob/4f1297f259b09d129ac01afbd4c674263b7ac124/lib/internal/fs/utils.js#L231
|
|
|
|
function dateFromNumeric(num) {
|
|
|
|
return new Date(Number(num) * 1000);
|
|
|
|
}
|
|
|
|
|
2018-05-26 20:57:57 +00:00
|
|
|
function Stats(path, fileNode, devName) {
|
2014-05-23 18:14:06 +00:00
|
|
|
this.dev = devName;
|
2018-05-24 19:41:54 +00:00
|
|
|
this.node = fileNode.id;
|
|
|
|
this.type = fileNode.type;
|
2014-05-23 18:14:06 +00:00
|
|
|
this.size = fileNode.size;
|
|
|
|
this.nlinks = fileNode.nlinks;
|
2014-03-29 19:21:53 +00:00
|
|
|
// Date objects
|
|
|
|
this.atime = dateFromNumeric(fileNode.atime);
|
|
|
|
this.mtime = dateFromNumeric(fileNode.mtime);
|
|
|
|
this.ctime = dateFromNumeric(fileNode.ctime);
|
|
|
|
// Unix timestamp Numbers
|
|
|
|
this.atimeMs = fileNode.atime;
|
|
|
|
this.mtimeMs = fileNode.mtime;
|
|
|
|
this.ctimeMs = fileNode.ctime;
|
2018-05-24 19:41:54 +00:00
|
|
|
this.version = fileNode.version;
|
|
|
|
this.mode = fileNode.mode;
|
|
|
|
this.uid = fileNode.uid;
|
|
|
|
this.gid = fileNode.gid;
|
2018-05-26 20:57:57 +00:00
|
|
|
this.name = Path.basename(path);
|
2014-05-23 18:14:06 +00:00
|
|
|
}
|
2014-03-18 16:29:20 +00:00
|
|
|
|
2014-05-23 18:14:06 +00:00
|
|
|
Stats.prototype.isFile = function() {
|
2018-05-24 18:15:09 +00:00
|
|
|
return this.type === Constants.NODE_TYPE_FILE;
|
2014-05-23 18:14:06 +00:00
|
|
|
};
|
2014-03-18 16:29:20 +00:00
|
|
|
|
2014-05-23 18:14:06 +00:00
|
|
|
Stats.prototype.isDirectory = function() {
|
2018-05-24 18:15:09 +00:00
|
|
|
return this.type === Constants.NODE_TYPE_DIRECTORY;
|
2014-05-23 18:14:06 +00:00
|
|
|
};
|
2014-03-18 16:29:20 +00:00
|
|
|
|
2014-05-23 18:14:06 +00:00
|
|
|
Stats.prototype.isSymbolicLink = function() {
|
2018-05-24 18:15:09 +00:00
|
|
|
return this.type === Constants.NODE_TYPE_SYMBOLIC_LINK;
|
2014-05-23 18:14:06 +00:00
|
|
|
};
|
2014-03-18 16:29:20 +00:00
|
|
|
|
2014-05-23 18:14:06 +00:00
|
|
|
// These will always be false in Filer.
|
|
|
|
Stats.prototype.isSocket =
|
|
|
|
Stats.prototype.isFIFO =
|
|
|
|
Stats.prototype.isCharacterDevice =
|
|
|
|
Stats.prototype.isBlockDevice =
|
|
|
|
function() {
|
|
|
|
return false;
|
|
|
|
};
|
2014-03-18 16:29:20 +00:00
|
|
|
|
2014-05-23 18:14:06 +00:00
|
|
|
module.exports = Stats;
|