This should be in a `finally` block, to make sure the stream is properly closed.