Skip to content

Instantly share code, notes, and snippets.

@tmpvar
Created May 23, 2010 05:50
Show Gist options
  • Select an option

  • Save tmpvar/410676 to your computer and use it in GitHub Desktop.

Select an option

Save tmpvar/410676 to your computer and use it in GitHub Desktop.
tmpvar@tmpvar:/tmp$ cat test.js && node test.js
var sys = require("sys"),
fs = require("fs"),
Buffer = require("buffer").Buffer,
self = {
storageLocation: "/tmp/test.txt",
descriptor : null
},
object = { test: "abc"},
id = 1,
action;
self.descriptor = fs.openSync(self.storageLocation, 'a', 0644);
action = new Buffer(("this.set(\"" + (id) + "\", " + (JSON.stringify(object)) + ");\n"), null);
sys.debug(sys.inspect(action, true));
fs.write(self.descriptor, action, 0, action.length, null, function(err, numBytes) {
if ((err)) {
sys.log('something went wrong');
sys.log(sys.inspect(err));
return process.exit(1);
}
});
DEBUG: { '0': 116
, '1': 104
, '2': 105
, '3': 115
, '4': 46
, '5': 115
, '6': 101
, '7': 116
, '8': 40
, '9': 34
, '10': 49
, '11': 34
, '12': 44
, '13': 32
, '14': 123
, '15': 34
, '16': 116
, '17': 101
, '18': 115
, '19': 116
, '20': 34
, '21': 58
, '22': 34
, '23': 97
, '24': 98
, '25': 99
, '26': 34
, '27': 125
, '28': 41
, '29': 59
, '30': 10
, length: 31
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment