fattr.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. var fs = require("./fileSystem").require(),
  2. pth = require("path");
  3. fs.existsSync = fs.existsSync || pth.existsSync;
  4. module.exports = function(/*String*/path) {
  5. var _path = path || "",
  6. _permissions = 0,
  7. _obj = newAttr(),
  8. _stat = null;
  9. function newAttr() {
  10. return {
  11. directory : false,
  12. readonly : false,
  13. hidden : false,
  14. executable : false,
  15. mtime : 0,
  16. atime : 0
  17. }
  18. }
  19. if (_path && fs.existsSync(_path)) {
  20. _stat = fs.statSync(_path);
  21. _obj.directory = _stat.isDirectory();
  22. _obj.mtime = _stat.mtime;
  23. _obj.atime = _stat.atime;
  24. _obj.executable = !!(1 & parseInt ((_stat.mode & parseInt ("777", 8)).toString (8)[0]));
  25. _obj.readonly = !!(2 & parseInt ((_stat.mode & parseInt ("777", 8)).toString (8)[0]));
  26. _obj.hidden = pth.basename(_path)[0] === ".";
  27. } else {
  28. console.warn("Invalid path: " + _path)
  29. }
  30. return {
  31. get directory () {
  32. return _obj.directory;
  33. },
  34. get readOnly () {
  35. return _obj.readonly;
  36. },
  37. get hidden () {
  38. return _obj.hidden;
  39. },
  40. get mtime () {
  41. return _obj.mtime;
  42. },
  43. get atime () {
  44. return _obj.atime;
  45. },
  46. get executable () {
  47. return _obj.executable;
  48. },
  49. decodeAttributes : function(val) {
  50. },
  51. encodeAttributes : function (val) {
  52. },
  53. toString : function() {
  54. return '{\n' +
  55. '\t"path" : "' + _path + ",\n" +
  56. '\t"isDirectory" : ' + _obj.directory + ",\n" +
  57. '\t"isReadOnly" : ' + _obj.readonly + ",\n" +
  58. '\t"isHidden" : ' + _obj.hidden + ",\n" +
  59. '\t"isExecutable" : ' + _obj.executable + ",\n" +
  60. '\t"mTime" : ' + _obj.mtime + "\n" +
  61. '\t"aTime" : ' + _obj.atime + "\n" +
  62. '}';
  63. }
  64. }
  65. };