You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.3 KiB

4 years ago
  1. 'use strict';
  2. const fs = require('fs');
  3. const call = require('../call');
  4. /**
  5. * A facade around {@link fs.readdirSync} that allows it to be called
  6. * the same way as {@link fs.readdir}.
  7. *
  8. * @param {string} dir
  9. * @param {function} callback
  10. */
  11. exports.readdir = function (dir, callback) {
  12. // Make sure the callback is only called once
  13. callback = call.once(callback);
  14. try {
  15. let items = fs.readdirSync(dir);
  16. callback(null, items);
  17. }
  18. catch (err) {
  19. callback(err);
  20. }
  21. };
  22. /**
  23. * A facade around {@link fs.statSync} that allows it to be called
  24. * the same way as {@link fs.stat}.
  25. *
  26. * @param {string} path
  27. * @param {function} callback
  28. */
  29. exports.stat = function (path, callback) {
  30. // Make sure the callback is only called once
  31. callback = call.once(callback);
  32. try {
  33. let stats = fs.statSync(path);
  34. callback(null, stats);
  35. }
  36. catch (err) {
  37. callback(err);
  38. }
  39. };
  40. /**
  41. * A facade around {@link fs.lstatSync} that allows it to be called
  42. * the same way as {@link fs.lstat}.
  43. *
  44. * @param {string} path
  45. * @param {function} callback
  46. */
  47. exports.lstat = function (path, callback) {
  48. // Make sure the callback is only called once
  49. callback = call.once(callback);
  50. try {
  51. let stats = fs.lstatSync(path);
  52. callback(null, stats);
  53. }
  54. catch (err) {
  55. callback(err);
  56. }
  57. };