Fixes an issue writing partial data to output stream

This will manifest in a way where you will get duplicate data because it will
write the same data again and again.
Merge pull request #1539 from kylef/output-stream

Fixes an issue writing partial data to the output stream