Thank you more one time, worked fine. Do you have examples the better way to generate the csv like you told using output stream?
Em sexta-feira, 17 de janeiro de 2014 14h36min34s UTC-2, willem dhaeseleer escreveu: > > Like documented here: > http://nodejs.org/api/readline.html#readline_event_close > > You need to wait for the close event, in just the same way you wait for > the 'line' event. > > Of Course i can't guarantee if this is going to work. I'm not sure if your > code inside your line handler is going to be any good. > I added a *console.log* there as well so that you can see what gets > added, but you should remove that once everything works. > > And of course, instead of building up your csv file into 1 variable, you > should write through to an actual output stream so that your memory doesn't > skyrocket. Taking that into account I'm not sure if readline is the best > way to do this, since it will might be cumbersome to integrate it into a > backpressured <http://blog.nodejs.org/2012/12/20/streams2/> pipeline. I > think this is because readline is more for terminal interaction than just > trivial line splitting. ( I could be wrong on that, anyone ?) > > > On 17 January 2014 16:07, Felipe Silveira <[email protected]<javascript:> > > wrote: > >> Willem, >> >> Thank you for help, sorry but I'm beginner and still do not understand >> some things, like how I'll wait for the event line finish and so run the >> console.log? >> I changed the code to this, its correct? >> >> var csv; >> var instream = fs.createReadStream(pathLog+req.params.file); >> var outstream = new stream; >> outstream.readable = true; >> outstream.writable = true; >> var rl = readline.createInterface({ >> input: instream, >> output: outstream, >> terminal: false >> }); >> >> rl.on('line', function(lin) { >> if(req.params.id != ''){ >> var re = new RegExp(req.params.id, 'i'); >> if(lin.match(re) != null){ >> var string = lin.substring(143,lin.length); >> > * console.log('Adding Line', string);* > >> csv += ','+string; >> } >> } >> }); >> res.set('Content-Type', 'application/octet-stream'); >> >> > *rl.on('close', function() {* > * console.log('TOTAL CSV', csv);* > * })* > > >> //res.send(exports.csv); >> }); >> >> Em sexta-feira, 17 de janeiro de 2014 10h23min26s UTC-2, Felipe Silveira >> escreveu: >>> >>> Hi everyone, >>> >>> I'm a newbie in nodejs and express, so i'm trying to generate one CSV >>> file reading a content of one log file, something like this: >>> >>> var csv; >>> var instream = fs.createReadStream(pathLog+req.params.file); >>> var outstream = new stream; >>> outstream.readable = true; >>> outstream.writable = true; >>> var rl = readline.createInterface({ >>> input: instream, >>> output: outstream, >>> terminal: false >>> }); >>> >>> rl.on('line', function(lin,csv) { >>> var csv; >>> if(req.params.id != ''){ >>> var re = new RegExp(req.params.id, 'i'); >>> >>> if(lin.match(re) != null){ >>> var string = lin.substring(143,lin.length); >>> csv += ','+string; >>> } >>> } >>> }); >>> res.set('Content-Type', 'application/octet-stream'); >>> console.log(csv); >>> >>> >>> The real problem is, I declared the variable csv and in the event line >>> I'm incrementing that but in the console.log return undefined. >>> >>> Thank you! >>> >>> >>> *Att,* >>> >>> *Felipe Silveira Mendes*Site <http://felipems.com.br> - >>> Twitter<https://twitter.com/felipesmendes>- >>> Blog <http://felipems.com.br/blog> >>> *Web Developer* >>> *(31) 8370-9090 (Claro)* >>> *(31) 9433-9310 (Tim)* >>> *[email protected] <javascript:>* >>> >>> >>> -- >> -- >> Job Board: http://jobs.nodejs.org/ >> Posting guidelines: >> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines >> You received this message because you are subscribed to the Google >> Groups "nodejs" group. >> To post to this group, send email to [email protected]<javascript:> >> To unsubscribe from this group, send email to >> [email protected] <javascript:> >> For more options, visit this group at >> http://groups.google.com/group/nodejs?hl=en?hl=en >> >> --- >> You received this message because you are subscribed to a topic in the >> Google Groups "nodejs" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/nodejs/qQ6prse3r0c/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> [email protected] <javascript:>. >> For more options, visit https://groups.google.com/groups/opt_out. >> > > -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
