Only read the necessary amount of data from the input stream (fixes #39)
Merge pull request #40 from sharwell/fix-39

Only read the necessary amount of data from the input stream (fixes #39)