Sam Sam - 1 year ago 66
Javascript Question

CreateReadStream creates an extra newline delimiter in chunks?

I have a simple question on readStream in node's fs module.
Here is the simple code:

fs = require('fs');
readStream = fs.createReadStream('somefile.d');
readStream.on('data', function(chunk) {

'somefile.d' is:


Why is there an extra newline at the end of the output? I tried an od -c to get an octal dump and yes there is an extra newline. Is that put by toString?
More importantly, why is chunk delimited by newline? The data event is triggered for every line. I have not specified any option and there is no option to read chunks separated by any specific character. I know that there is the carrier module, for example, to get around this issue.

Any explanation will be appreciated.





Not sure I fully understand, but if you're talking about the actual output of the program, as-written it looks like your only output is coming from console.log. console.log terminates its write with a line ending. If you want to write to stdout without a line terminator, you could just do:


should send them out as-is. You could also pipe the readstream directly to stdout if you wanted to: