fn read_to_end<R: Read>(reader: &mut R) -> Result<Vec<u8>>
A helper function to read to the end of the reader