Guest User

Untitled

a guest
Apr 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. var Seq = require('seq');
  2. var fs = require('fs');
  3.  
  4. Seq()
  5. .seq(function() {
  6. fs.stat('./dir', this);
  7. })
  8. .catch(function (err) {
  9. fs.mkdir('./dir', 0700, function (err) {
  10. if (err) {
  11. console.log("Couldn't mkdir ./dir: " + err);
  12. process.exit(1);
  13. }
  14. });
  15. })
  16. .seq(function () {
  17. fs.open('./dir/file', 'a+', this.into('fd'));
  18. })
  19. .catch(function (err) {
  20. console.log("Couldn't open file for appending: " + err);
  21. process.exit(1);
  22. })
  23. .seq(function () {
  24. var towrite = Buffer("hello world\n");
  25. fs.write(this.vars.fd, towrite, 0, towrite.length, null, this)
  26. })
  27. .catch(function (err) {
  28. console.log("Failed appending to file: " + err);
  29. process.exit(1);
  30. })
  31. .seq(function () {
  32. console.log("Successfully appended to file!");
  33. })
  34. ;
Add Comment
Please, Sign In to add comment