1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | exports.Stats = void 0;
|
---|
4 | var constants_1 = require("./constants");
|
---|
5 | var getBigInt_1 = require("./getBigInt");
|
---|
6 | var S_IFMT = constants_1.constants.S_IFMT, S_IFDIR = constants_1.constants.S_IFDIR, S_IFREG = constants_1.constants.S_IFREG, S_IFBLK = constants_1.constants.S_IFBLK, S_IFCHR = constants_1.constants.S_IFCHR, S_IFLNK = constants_1.constants.S_IFLNK, S_IFIFO = constants_1.constants.S_IFIFO, S_IFSOCK = constants_1.constants.S_IFSOCK;
|
---|
7 | /**
|
---|
8 | * Statistics about a file/directory, like `fs.Stats`.
|
---|
9 | */
|
---|
10 | var Stats = /** @class */ (function () {
|
---|
11 | function Stats() {
|
---|
12 | }
|
---|
13 | Stats.build = function (node, bigint) {
|
---|
14 | if (bigint === void 0) { bigint = false; }
|
---|
15 | var stats = new Stats();
|
---|
16 | var uid = node.uid, gid = node.gid, atime = node.atime, mtime = node.mtime, ctime = node.ctime;
|
---|
17 | var getStatNumber = !bigint ? function (number) { return number; } : getBigInt_1.default;
|
---|
18 | // Copy all values on Stats from Node, so that if Node values
|
---|
19 | // change, values on Stats would still be the old ones,
|
---|
20 | // just like in Node fs.
|
---|
21 | stats.uid = getStatNumber(uid);
|
---|
22 | stats.gid = getStatNumber(gid);
|
---|
23 | stats.rdev = getStatNumber(0);
|
---|
24 | stats.blksize = getStatNumber(4096);
|
---|
25 | stats.ino = getStatNumber(node.ino);
|
---|
26 | stats.size = getStatNumber(node.getSize());
|
---|
27 | stats.blocks = getStatNumber(1);
|
---|
28 | stats.atime = atime;
|
---|
29 | stats.mtime = mtime;
|
---|
30 | stats.ctime = ctime;
|
---|
31 | stats.birthtime = ctime;
|
---|
32 | stats.atimeMs = getStatNumber(atime.getTime());
|
---|
33 | stats.mtimeMs = getStatNumber(mtime.getTime());
|
---|
34 | var ctimeMs = getStatNumber(ctime.getTime());
|
---|
35 | stats.ctimeMs = ctimeMs;
|
---|
36 | stats.birthtimeMs = ctimeMs;
|
---|
37 | stats.dev = getStatNumber(0);
|
---|
38 | stats.mode = getStatNumber(node.mode);
|
---|
39 | stats.nlink = getStatNumber(node.nlink);
|
---|
40 | return stats;
|
---|
41 | };
|
---|
42 | Stats.prototype._checkModeProperty = function (property) {
|
---|
43 | return (Number(this.mode) & S_IFMT) === property;
|
---|
44 | };
|
---|
45 | Stats.prototype.isDirectory = function () {
|
---|
46 | return this._checkModeProperty(S_IFDIR);
|
---|
47 | };
|
---|
48 | Stats.prototype.isFile = function () {
|
---|
49 | return this._checkModeProperty(S_IFREG);
|
---|
50 | };
|
---|
51 | Stats.prototype.isBlockDevice = function () {
|
---|
52 | return this._checkModeProperty(S_IFBLK);
|
---|
53 | };
|
---|
54 | Stats.prototype.isCharacterDevice = function () {
|
---|
55 | return this._checkModeProperty(S_IFCHR);
|
---|
56 | };
|
---|
57 | Stats.prototype.isSymbolicLink = function () {
|
---|
58 | return this._checkModeProperty(S_IFLNK);
|
---|
59 | };
|
---|
60 | Stats.prototype.isFIFO = function () {
|
---|
61 | return this._checkModeProperty(S_IFIFO);
|
---|
62 | };
|
---|
63 | Stats.prototype.isSocket = function () {
|
---|
64 | return this._checkModeProperty(S_IFSOCK);
|
---|
65 | };
|
---|
66 | return Stats;
|
---|
67 | }());
|
---|
68 | exports.Stats = Stats;
|
---|
69 | exports.default = Stats;
|
---|