Avoid buffering entire input when hashing

Also ensure that we close the InputStream.