-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvirtual-stats.js
98 lines (78 loc) · 1.92 KB
/
virtual-stats.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* Used to cache a stats object for the virtual file.
* Extracted from the `mock-fs` package.
*
* @author Tim Schaub http://tschaub.net/
* @link https://github.com/tschaub/mock-fs/blob/master/lib/binding.js
* @link https://github.com/tschaub/mock-fs/blob/master/license.md
*/
/* eslint-disable no-restricted-syntax, no-prototype-builtins, no-continue */
/* eslint-disable no-bitwise, no-underscore-dangle */
'use strict';
const constants = require('constants');
class VirtualStats {
/**
* Create a new stats object.
* @param {Object} config Stats properties.
* @constructor
*/
constructor(config) {
for (const key in config) {
if (!config.hasOwnProperty(key)) {
continue;
}
this[key] = config[key];
}
}
/**
* Check if mode indicates property.
* @param {number} property Property to check.
* @return {boolean} Property matches mode.
*/
_checkModeProperty(property) {
return ((this.mode & constants.S_IFMT) === property);
}
/**
* @return {Boolean} Is a directory.
*/
isDirectory() {
return this._checkModeProperty(constants.S_IFDIR);
}
/**
* @return {Boolean} Is a regular file.
*/
isFile() {
return this._checkModeProperty(constants.S_IFREG);
}
/**
* @return {Boolean} Is a block device.
*/
isBlockDevice() {
return this._checkModeProperty(constants.S_IFBLK);
}
/**
* @return {Boolean} Is a character device.
*/
isCharacterDevice() {
return this._checkModeProperty(constants.S_IFCHR);
}
/**
* @return {Boolean} Is a symbolic link.
*/
isSymbolicLink() {
return this._checkModeProperty(constants.S_IFLNK);
}
/**
* @return {Boolean} Is a named pipe.
*/
isFIFO() {
return this._checkModeProperty(constants.S_IFIFO);
}
/**
* @return {Boolean} Is a socket.
*/
isSocket() {
return this._checkModeProperty(constants.S_IFSOCK);
}
}
module.exports = VirtualStats;