Dirent.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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.path = '';
  14. this.mode = 0;
  15. }
  16. static build(link, encoding) {
  17. const dirent = new Dirent();
  18. const { mode } = link.getNode();
  19. dirent.name = (0, encoding_1.strToEncoding)(link.getName(), encoding);
  20. dirent.mode = mode;
  21. dirent.path = link.getParentPath();
  22. return dirent;
  23. }
  24. _checkModeProperty(property) {
  25. return (this.mode & S_IFMT) === property;
  26. }
  27. isDirectory() {
  28. return this._checkModeProperty(S_IFDIR);
  29. }
  30. isFile() {
  31. return this._checkModeProperty(S_IFREG);
  32. }
  33. isBlockDevice() {
  34. return this._checkModeProperty(S_IFBLK);
  35. }
  36. isCharacterDevice() {
  37. return this._checkModeProperty(S_IFCHR);
  38. }
  39. isSymbolicLink() {
  40. return this._checkModeProperty(S_IFLNK);
  41. }
  42. isFIFO() {
  43. return this._checkModeProperty(S_IFIFO);
  44. }
  45. isSocket() {
  46. return this._checkModeProperty(S_IFSOCK);
  47. }
  48. }
  49. exports.Dirent = Dirent;
  50. exports.default = Dirent;
  51. //# sourceMappingURL=Dirent.js.map