public
Created

  • Download Gist
append.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
// writing 3 buffers starting from offset 0
// 3 bytes | 5 bytes | 10 bytes
// second | first | third
// last byte of the last buffer should be at offset 18
// file should be 18 bytes long
// this is WRONG on linux, file grows up for 18 bytes after each run
// and every single written buffer can't be read properly
//
// holy fuck, the whole day lost.
 
var fs = require("fs"),
f = fs.openSync("ae", "a+");
 
b1 = new Buffer(5);
b1t = new Buffer(b1.length);
b2 = new Buffer(3);
b2t = new Buffer(b2.length);
b3 = new Buffer(10);
b3t = new Buffer(b3.length);
 
fs.write(f, b1, 0, b1.length, b2.length, function(error) {
if (error) {
return console.log(error);
}
 
fs.write(f, b2, 0, b2.length, 0, function(error) {
if (error) {
return console.log(error);
}
 
fs.write(f, b3, 0, b3.length, b1.length + b2.length, function(error) {
if (error) {
return console.log(error);
}
 
fs.read(f, b1t, 0, b1t.length, b2.length, function(error) {
if (error) {
return console.log(error);
}
 
if (b1t.toString("base64") != b1.toString("base64")) {
console.log("wrong first buffer!", b1, b1t);
}
 
fs.read(f, b2t, 0, b2t.length, 0, function(error) {
if (error) {
return console.log(error);
}
 
if (b2t.toString("base64") != b2.toString("base64")) {
console.log("wrong second buffer!");
}
 
fs.read(f, b3t, 0, b3t.length, b1.length + b2.length, function(error) {
if (error) {
return console.log(error);
}
 
if (b3t.toString("base64") != b3.toString("base64")) {
console.log("wrong third buffer!");
}
});
});
});
});
});
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.