pause causes subsequent stream chunked together
Closed this issue · 2 comments
Hello, I encounter this behavior while using byline, using node v0.10. Not really sure whether it's one feature or a bug. The script will read one file and print the content line by line. Without stream.pause, the lines are print one by one. However, if I use pause, the lines are chunked together.
fs = require 'fs'
byline = require 'byline'
readfile = (filename) ->
stream = byline fs.createReadStream(filename)
stream.on 'data', (line) ->
console.log line.toString()
stream.pause()
setTimeout((-> stream.resume()), 1000)
readfile 'line.coffee'
It prints:
fs = require 'fs'
byline = require 'byline'readfile = (filename) -> stream = byline fs.createReadStream(filename) stream.on 'data', (line) -> console.log line.toString() stream.pause() setTimeout((-> stream.resume()), 1000)readfile 'line.coffee'
The first line is print properly, but the rest are all chunked together.
Yep, this is a bug introduced by the new v0.10 code. Node's new Writable stream buffers output, which causes the lines to be concatenated. The fix was to use the new objectStream feature which treats writes as opaque objects which are to be emitted one-by-one.
Fixed in 3.1.2 f6f9596
I got expected behavior using 3.1.2. Thank you very much.