SyncAsyncFileSystemDecorator.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. function SyncAsyncFileSystemDecorator(fs) {
  6. this.fs = fs;
  7. if(fs.statSync) {
  8. this.stat = function(arg, callback) {
  9. try {
  10. var result = fs.statSync(arg);
  11. } catch(e) {
  12. return callback(e);
  13. }
  14. callback(null, result);
  15. };
  16. }
  17. if(fs.readdirSync) {
  18. this.readdir = function(arg, callback) {
  19. try {
  20. var result = fs.readdirSync(arg);
  21. } catch(e) {
  22. return callback(e);
  23. }
  24. callback(null, result);
  25. };
  26. }
  27. if(fs.readFileSync) {
  28. this.readFile = function(arg, callback) {
  29. try {
  30. var result = fs.readFileSync(arg);
  31. } catch(e) {
  32. return callback(e);
  33. }
  34. callback(null, result);
  35. };
  36. }
  37. if(fs.readlinkSync) {
  38. this.readlink = function(arg, callback) {
  39. try {
  40. var result = fs.readlinkSync(arg);
  41. } catch(e) {
  42. return callback(e);
  43. }
  44. callback(null, result);
  45. };
  46. }
  47. if(fs.readJsonSync) {
  48. this.readJson = function(arg, callback) {
  49. try {
  50. var result = fs.readJsonSync(arg);
  51. } catch(e) {
  52. return callback(e);
  53. }
  54. callback(null, result);
  55. };
  56. }
  57. }
  58. module.exports = SyncAsyncFileSystemDecorator;