Fixes an issue writing partial data to the output stream

This will manifest in a way where you will get duplicate data because it will
write the same data again and again.