10
0

Dirent.js 1.5 KB

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