UNPKG

1.38 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Dirent = void 0;
4const constants_1 = require("./constants");
5const encoding_1 = require("./encoding");
6const { S_IFMT, S_IFDIR, S_IFREG, S_IFBLK, S_IFCHR, S_IFLNK, S_IFIFO, S_IFSOCK } = constants_1.constants;
7/**
8 * A directory entry, like `fs.Dirent`.
9 */
10class Dirent {
11 constructor() {
12 this.name = '';
13 this.mode = 0;
14 }
15 static build(link, encoding) {
16 const dirent = new Dirent();
17 const { mode } = link.getNode();
18 dirent.name = (0, encoding_1.strToEncoding)(link.getName(), encoding);
19 dirent.mode = mode;
20 return dirent;
21 }
22 _checkModeProperty(property) {
23 return (this.mode & S_IFMT) === property;
24 }
25 isDirectory() {
26 return this._checkModeProperty(S_IFDIR);
27 }
28 isFile() {
29 return this._checkModeProperty(S_IFREG);
30 }
31 isBlockDevice() {
32 return this._checkModeProperty(S_IFBLK);
33 }
34 isCharacterDevice() {
35 return this._checkModeProperty(S_IFCHR);
36 }
37 isSymbolicLink() {
38 return this._checkModeProperty(S_IFLNK);
39 }
40 isFIFO() {
41 return this._checkModeProperty(S_IFIFO);
42 }
43 isSocket() {
44 return this._checkModeProperty(S_IFSOCK);
45 }
46}
47exports.Dirent = Dirent;
48exports.default = Dirent;
49//# sourceMappingURL=Dirent.js.map
\No newline at end of file