example of reading efficiently from a stream