You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
I recently stumbled upon a pretty weird issue with file streams in node v0.3.3-pre (pulled from git master) on OS X (10.6.5). The following script (which should just read in.txt and dump everything to out.txt) leads to different results when the resume/pause pair is commented out:
var FS = require("fs");
var System = require("sys");
var inStream = FS.createReadStream("./in.txt", {mode:0600, flags:"r"});
var outFD = FS.openSync("./out.txt", "w");
var bytes = 0;
inStream.addListener("data", function(chunk) {
inStream.pause();
if(chunk) {
try {
bytes += chunk.length;
FS.writeSync(outFD, chunk.toString());
}
catch(e) {
System.puts("Error: "+e);
System.puts(e.stack);
}
}
inStream.resume();
});
inStream.addListener("error", function(err) {
System.puts("Error event: "+err);
});
inStream.addListener("end", function() {
System.puts("END of streaming: "+bytes+" bytes");
this.destroy();
FS.closeSync(outFD);
});
Without the resume/pause pair, the MD5 of out.txt is exactly equal to the one of in.txt in all cases. However, when running with pause/resume, the MD5 of out.txt is different all the time. Also, I get two 'end' events.
I recently stumbled upon a pretty weird issue with file streams in node v0.3.3-pre (pulled from git master) on OS X (10.6.5). The following script (which should just read in.txt and dump everything to out.txt) leads to different results when the resume/pause pair is commented out:
Without the resume/pause pair, the MD5 of out.txt is exactly equal to the one of in.txt in all cases. However, when running with pause/resume, the MD5 of out.txt is different all the time. Also, I get two 'end' events.
Without resume/pause:
tommy$ md5 in.txt
MD5 (in.txt) = 9c91b3f1cc60b8bf42aec04861ed942f
tommy$ node ./bugtest.js
END of streaming: 4727845 bytes
Error event: Error: EBADF, Bad file descriptor
tommy$ md5 out.txt
MD5 (out.txt) = 9c91b3f1cc60b8bf42aec04861ed942f
With pause/resume:
tommy$ node ./bugtest.js
END of streaming: 4745290 bytes
END of streaming: 4745290 bytes
Also, the EBADF is kind of weird...
The text was updated successfully, but these errors were encountered: