ensure that stream is fully read before returning result