Prevent data loss when input stream has already finished writing

Closes #15.
Merge pull request #18 from ef4/fix-15

Prevent data loss when input stream has already finished writing