Dirent.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Dirent = void 0;
  4. const constants_1 = require("./constants");
  5. const encoding_1 = require("./encoding");
  6. const { 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. */
  10. class 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. }
  47. exports.Dirent = Dirent;
  48. exports.default = Dirent;