index.js 913 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Module dependencies.
  3. */
  4. var thunk = require('thunkify');
  5. var fs = require('fs');
  6. var stream = require('co-from-stream');
  7. /**
  8. * Methods to wrap.
  9. */
  10. var methods = [
  11. 'rename',
  12. 'ftruncate',
  13. 'chown',
  14. 'fchown',
  15. 'lchown',
  16. 'chmod',
  17. 'fchmod',
  18. 'stat',
  19. 'lstat',
  20. 'fstat',
  21. 'link',
  22. 'symlink',
  23. 'readlink',
  24. 'realpath',
  25. 'unlink',
  26. 'rmdir',
  27. 'mkdir',
  28. 'readdir',
  29. 'close',
  30. 'open',
  31. 'utimes',
  32. 'futimes',
  33. 'fsync',
  34. 'write',
  35. 'read',
  36. 'readFile',
  37. 'writeFile',
  38. 'appendFile'
  39. ];
  40. // wrap
  41. methods.forEach(function(name){
  42. if (!fs[name]) return;
  43. exports[name] = thunk(fs[name]);
  44. });
  45. // .exists is still messed
  46. exports.exists = function(path){
  47. return function(done){
  48. fs.stat(path, function(err, res){
  49. done(null, !err);
  50. });
  51. }
  52. };
  53. // .createReadStream
  54. exports.createReadStream = function(){
  55. return stream(fs.createReadStream.apply(null, arguments));
  56. };