I upgraded to Node.js v0.10 with the new Streams2 API.
I noticed that now if I pipe to a file, when the "end" event is received the file might be still open and its size is 0.
for exmaple (using pdfkit):
http.get('http://www.example.com/test.jpg', function(res) {
var file = fs.createWriteStream('./test.jpg');
res.on("end", function() {
doc.image('./test.jpg');
};
res.pipe(file);
});
an error is thrown and the file size is 0.
but if I change it to file.on("close".... I get the desired result.
is this the correct behavior? should I use file.on("close") ?