Guest User

Untitled

a guest
May 26th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. tmpvar@tmpvar:/tmp$ cat test.js && node test.js
  2. var sys = require("sys"),
  3. fs = require("fs"),
  4. Buffer = require("buffer").Buffer,
  5. self = {
  6. storageLocation: "/tmp/test.txt",
  7. descriptor : null
  8. },
  9. object = { test: "abc"},
  10. id = 1,
  11. action;
  12.  
  13. self.descriptor = fs.openSync(self.storageLocation, 'a', 0644);
  14.  
  15. action = new Buffer(("this.set(\"" + (id) + "\", " + (JSON.stringify(object)) + ");\n"), null);
  16. sys.debug(sys.inspect(action, true));
  17. fs.write(self.descriptor, action, 0, action.length, null, function(err, numBytes) {
  18. if ((err)) {
  19. sys.log('something went wrong');
  20. sys.log(sys.inspect(err));
  21. return process.exit(1);
  22. }
  23. });
  24. DEBUG: { '0': 116
  25. , '1': 104
  26. , '2': 105
  27. , '3': 115
  28. , '4': 46
  29. , '5': 115
  30. , '6': 101
  31. , '7': 116
  32. , '8': 40
  33. , '9': 34
  34. , '10': 49
  35. , '11': 34
  36. , '12': 44
  37. , '13': 32
  38. , '14': 123
  39. , '15': 34
  40. , '16': 116
  41. , '17': 101
  42. , '18': 115
  43. , '19': 116
  44. , '20': 34
  45. , '21': 58
  46. , '22': 34
  47. , '23': 97
  48. , '24': 98
  49. , '25': 99
  50. , '26': 34
  51. , '27': 125
  52. , '28': 41
  53. , '29': 59
  54. , '30': 10
  55. , length: 31
  56. }
Add Comment
Please, Sign In to add comment