Skip to content

Instantly share code, notes, and snippets.

@bobrik
Created September 4, 2012 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobrik/3618478 to your computer and use it in GitHub Desktop.
Save bobrik/3618478 to your computer and use it in GitHub Desktop.
var fs = require("fs"),
file = fs.openSync("aa", "a+"),
bufs = {},
off = fs.fstatSync(file).size,
offs = {};
Object.keys(offs).forEach(function(o) {
offs[o] += off;
});
function buf(size) {
if (!bufs[size]) {
bufs[size] = new Buffer(size);
}
return bufs[size];
}
function write(size, callback) {
var offset = off;
offs[size] = offset;
off += size;
fs.write(file, buf(size), 0, buf(size).length, offset, callback);
}
function reader() {
console.log(bufs);
console.log(offs)
Object.keys(bufs).forEach(function(size) {
size = +size;
var offset = offs[size],
test = new Buffer(size);
fs.read(file, test, 0, test.length, offset, function() {
if (test.toString("base64") != buf(size).toString("base64")) {
console.log("WTF? " + test.length + ":" + buf(size).length);
console.log(buf(size).slice(0,4).toString("base64"), test.slice(0, 4).toString("base64"))
}
});
});
}
for (var i = 3900; i < 4000; i++) {
write(i);
}
setTimeout(reader, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment