node.js - Writing into a Stream ends up overflowing -


i using readline read large file line line able of detecting places can split meaningful pieces several other files. use writestream write files. when regular expression detects place cut, end() open writestream , open new 1 line read. problem files end truncated if end() call didn't job.

i checked success of write() , pause input stream when buffer full. relevant part of code:

var rl = readline.createinterface({     input: fs.createreadstream('basesystem.js',{encoding:'utf8'}),     output: process.stdout }); rl.on('line', function (line) {     var match = rexp.exec(line);     if (match) {         out.end();         console.log(path.join(path, match[2],'.js'));         out = fs.createwritestream(path.join(path,match[2]) + '.js', {encoding:'utf8'});      }     if (!out.write(line + '\n')) {         console.log('***** paused **** ');         rl.pause();         out.once('drain', function () {             console.log('***** resume **** ');             rl.resume();         });     } }); 

when find write() fails, puase input stream on readline , listen 'drain' event when resume it. tried leaving listener 'drain' permanent, seems lines readline keep coming. files end truncated. readline doesn't seem stop sending 'line' events when paused.

the initial writestream (out) created before sample , listen 'close' event on readline stream end() final file, anyway, files, not last one, truncated.

the display shows ** pause * signs on console along lines being read no resume . resume ** lines come @ once @ end.

thanks in advance

i found out, readline's fault. when readline receives pause(), pauses own input stream if has buffer split in lines, keep emitting 'line' events each of lines split previous buffer. stop when array of lines finished. i've filed bug report on node's site.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -