Browse Source

Add read_sized_string()

master
Matteo Cypriani 4 years ago
parent
commit
9c4a93e72e
1 changed files with 10 additions and 4 deletions
  1. +10
    -4
      src/lib.rs

+ 10
- 4
src/lib.rs 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`.
fn read_nrg_chunk_id(fd: &File) -> Result<String, NrgError> {
let mut handle = fd.take(4);
let mut chunk_id = String::new();
try!(handle.read_to_string(&mut chunk_id));
Ok(chunk_id)
read_sized_string(fd, 4)
}
/// 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)
}


Loading…
Cancel
Save