Created
September 4, 2012 08:25
-
-
Save bobrik/3618478 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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