Streaming Code Worked in v0.2.3 and 0.4.12, fails in 0.10.25

60 views
Skip to first unread message

P. Douglas Reeder

unread,
Oct 2, 2014, 11:48:02 PM10/2/14
to nod...@googlegroups.com

I can tell the following code executes as far as logging "second piece of index-colorbox.html written", but not to logging "writeUntilBufferFull()".


Any suggestions why the "drain" event doesn't appear to fire under 0.10.25?


writeStream.write("<title>" + title + "</title>\n");

fs.readFile("piece/index-second.html", function (error, buffer) {

//...

writeStream.write(buffer);

console.log("second piece of index-colorbox.html written");


writeStream.addListener("drain", writeUntilBufferFull);


writeStream.write("<table>\n");

});

  

function writeUntilBufferFull() {

var longDate, urlFileName, htmlFileName, row;

console.log("writeUntilBufferFull()   p=", p, "   metadata:", JSON.stringify(pictureMetadata[p]));

//...

}


mscdex

unread,
Oct 3, 2014, 12:42:08 PM10/3/14
to nod...@googlegroups.com
On Thursday, October 2, 2014 11:48:02 PM UTC-4, P. Douglas Reeder wrote:

I can tell the following code executes as far as logging "second piece of index-colorbox.html written", but not to logging "writeUntilBufferFull()".



Have you checked the return values of your `.write()` calls? IIRC you will only see 'drain' if `.write()` returns false.

P. Douglas Reeder

unread,
Oct 5, 2014, 1:01:35 AM10/5/14
to nod...@googlegroups.com
Yes, on the old platform write() always returned false, so my code was not prepared to deal with a true. :-S

the solution was to, at the end of the callback for readFile, to call writeUntilBufferFull directly.
Reply all
Reply to author
Forward
0 new messages