fs.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const promisify = require('./promisify');
  2. const root = require('./root');
  3. const each = require('./each');
  4. const toArr = require('./toArr');
  5. const fs = require('fs');
  6. each(
  7. [
  8. 'access',
  9. 'appendFile',
  10. 'chmod',
  11. 'chown',
  12. 'close',
  13. 'fchmod',
  14. 'fchown',
  15. 'fdatasync',
  16. 'fstat',
  17. 'fsync',
  18. 'ftruncate',
  19. 'futimes',
  20. 'link',
  21. 'lstat',
  22. 'mkdir',
  23. 'mkdtemp',
  24. 'open',
  25. 'read',
  26. 'readFile',
  27. 'readdir',
  28. 'readlink',
  29. 'realpath',
  30. 'rename',
  31. 'rmdir',
  32. 'stat',
  33. 'symlink',
  34. 'truncate',
  35. 'unlink',
  36. 'utimes',
  37. 'write',
  38. 'writeFile'
  39. ],
  40. function(method) {
  41. exports[method] = promisify(fs[method]);
  42. }
  43. );
  44. exports.exists = function() {
  45. const args = toArr(arguments);
  46. return new root.Promise(function(resolve) {
  47. args.push(resolve);
  48. fs.exists.apply(null, args);
  49. });
  50. };
  51. module.exports = exports;