Extra newline while sending data to a stream using through2 in Node.js -


i going through stream-adventure workshopper nodeschool. write program piped process.stdin stream stream created using through2 module , pipe process.stdout. stream created using through2 module convert input stream characters uppercase , pipe process.stdout. below source code:

var through = require('through2'); var write = function(buffer,encoding,next){         var data = buffer.tostring();         this.push(data.touppercase() + '\n');         next(); } var end = function (done){         done(); } var stream = through(write,end); process.stdin.pipe(stream).pipe(process.stdout); 

the problem after every 8th chunk of word sent stream, newline printed. below 3 test outputs verification workshopper did:

test 1:

tap version 13 # (anonymous) ok 1 stream-adventure verify yourfile.js not ok 2 should equal   ---     operator: equal     expected:       'metalkind\nkorven\nosirian\nthe ergon\ntythonian\nland of fiction beings\nsirian\nkraal\nthe flood\njadondan\n'     actual:       'metalkind\nkorven\nosirian\nthe ergon\ntythonian\nland of fiction beings\nsirian\nkraal\n\nthe flood\n\njadondan\n\n'   ... ok 3 successful exit code  1..3 # tests 3 # pass  2 # fail  1  ######################################### ###   solution not correct!   ### ######################################### 

test 2:

tap version 13 # (anonymous) ok 1 stream-adventure verify yourfile.js not ok 2 should equal   ---     operator: equal     expected:       'the beast\nandrozani tree\ngaztak\nraxacoricofallapatorian\nmayfly\nstigorax\nthe trickster\nmegara\nmentor\nhand of omega\n'     actual:       'the beast\nandrozani tree\ngaztak\nraxacoricofallapatorian\nmayfly\nstigorax\nthe trickster\nmegara\nmentor\n\nhand of omega\n\n'   ... ok 3 successful exit code  1..3 # tests 3 # pass  2 # fail  1  ######################################### ###   solution not correct!   ### ######################################### 

test 3:

tap version 13 # (anonymous) ok 1 stream-adventure verify yourfile.js not ok 2 should equal   ---     operator: equal     expected:       'qetesh\npelushi\nlurman\neve\natraxi\nfleshkind\ndalek\ngee-jee fly\nheadless monk\nthe destroyer\n'     actual:       'qetesh\npelushi\nlurman\neve\natraxi\nfleshkind\ndalek\ngee-jee fly\n\nheadless monk\n\nthe destroyer\n\n'   ... ok 3 successful exit code  1..3 # tests 3 # pass  2 # fail  1  ######################################### ###   solution not correct!   ### ######################################### 

what cause of mysterious newline , how fix it?

the newline being added line 4 in code. fix change line 4 this:

this.push(data.touppercase() + '\n'); 

to this:

this.push(data.touppercase()); 

also stream-adventure lesson print reference solution when type in terminal

stream-adventure solution  

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -