aheckmann / gridfs-stream

Easily stream files to and from MongoDB
MIT License
615 stars 120 forks source link

Read streams randomly not reading the whole file #46

Closed ceari closed 10 years ago

ceari commented 10 years ago

I stumbled upon an issue with the readstreams sometimes not reading the whole file. I tracked it down to the 'hacked' pause implementation in readstream.js#L182. Bypassing the native driver pause() method sometimes causes the driver stream to emit an 'end' event before emitting the last chunk of data. Replacing the implementation with stream.pause(); self.paused = stream.paused; seems to fix the problem but I don't know about side-effects - I guess the 'hack' is in there for a reason. Changing this also seems to improve the read performance to native levels as mentioned in issue #44 Is it critical to force the driver stream to pause like that?

I created a small script at https://github.com/ceari/gridfs-issue to reproduce the issue. Thank you for your time!

Reggino commented 10 years ago

Should be fixed in 0.5.2, thanks.