Dirent.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Dirent = void 0;
  4. const fs_node_utils_1 = require("@jsonjoy.com/fs-node-utils");
  5. const { S_IFMT, S_IFDIR, S_IFREG, S_IFBLK, S_IFCHR, S_IFLNK, S_IFIFO, S_IFSOCK } = fs_node_utils_1.constants;
  6. /**
  7. * A directory entry, like `fs.Dirent`.
  8. */
  9. class Dirent {
  10. constructor() {
  11. this.name = '';
  12. this.parentPath = '';
  13. this.mode = 0;
  14. /**
  15. * @deprecated Will be removed at any time.
  16. * @see https://nodejs.org/api/deprecations.html#DEP0178
  17. */
  18. this.path = '';
  19. }
  20. static build(link, encoding) {
  21. const dirent = new Dirent();
  22. const { mode } = link.getNode();
  23. dirent.name = (0, fs_node_utils_1.strToEncoding)(link.getName(), encoding);
  24. dirent.mode = mode;
  25. dirent.parentPath = link.getParentPath();
  26. dirent.path = dirent.parentPath;
  27. return dirent;
  28. }
  29. _checkModeProperty(property) {
  30. return (this.mode & S_IFMT) === property;
  31. }
  32. isDirectory() {
  33. return this._checkModeProperty(S_IFDIR);
  34. }
  35. isFile() {
  36. return this._checkModeProperty(S_IFREG);
  37. }
  38. isBlockDevice() {
  39. return this._checkModeProperty(S_IFBLK);
  40. }
  41. isCharacterDevice() {
  42. return this._checkModeProperty(S_IFCHR);
  43. }
  44. isSymbolicLink() {
  45. return this._checkModeProperty(S_IFLNK);
  46. }
  47. isFIFO() {
  48. return this._checkModeProperty(S_IFIFO);
  49. }
  50. isSocket() {
  51. return this._checkModeProperty(S_IFSOCK);
  52. }
  53. }
  54. exports.Dirent = Dirent;
  55. exports.default = Dirent;
  56. //# sourceMappingURL=Dirent.js.map