Don't ever use `capacity` for reading, as the capacity of the buffer could be a lot bigger. Just check if you have as many bytes `available` as you need.