Add read_sized_string()

This commit is contained in:
Matteo Cypriani 2016-12-05 12:52:31 -05:00
parent f22f7fdbc3
commit 9c4a93e72e
1 changed files with 10 additions and 4 deletions

View File

@ -261,10 +261,16 @@ fn read_nrg_chunks(mut fd: &mut File, nm: &mut NrgMetadata) -> Result<u16, NrgEr
/// Reads an NRG chunk ID (i.e. a 4-byte string) from `fd`. /// Reads an NRG chunk ID (i.e. a 4-byte string) from `fd`.
fn read_nrg_chunk_id(fd: &File) -> Result<String, NrgError> { fn read_nrg_chunk_id(fd: &File) -> Result<String, NrgError> {
let mut handle = fd.take(4); read_sized_string(fd, 4)
let mut chunk_id = String::new(); }
try!(handle.read_to_string(&mut chunk_id));
Ok(chunk_id)
/// Reads a String of size `size` from `fd`.
fn read_sized_string(fd: &File, size: u64) -> Result<String, NrgError> {
let mut handle = fd.take(size);
let mut string = String::new();
try!(handle.read_to_string(&mut string));
Ok(string)
} }