Skip to content

Instantly share code, notes, and snippets.

@andykent
Created November 5, 2010 16:34
Show Gist options
  • Save andykent/664408 to your computer and use it in GitHub Desktop.
Save andykent/664408 to your computer and use it in GitHub Desktop.
Test Case that shows a high number of writes getting mangled along with a file to scan over and validate the data.
var fs = require('fs');
var lines = fs.readFileSync('output.json', 'utf8').split("\n");
lines.pop(); // remove the last (empty) new line
for(var n in lines) {
try {
JSON.parse(lines[n]);
} catch (e) {
console.log("Error at line " + (n+1) + " => " + lines[n]);
}
}
var fs = require('fs');
var fd = fs.openSync('output.json', 'a');
var i = 0;
while (i < 100000) fs.write(fd, JSON.stringify({ foo: 'bar', iteration: i++ })+"\n");
fs.closeSync(fd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment