Skip to content

Commit

Permalink
Implement Read for Reader, wrapping archive_read_data()
Browse files Browse the repository at this point in the history
  • Loading branch information
Yorhel committed Oct 23, 2016
1 parent 3f723cf commit b8608b4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ pub trait Reader : Handle {
}
}

impl Read for Reader {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let cbuf = buf.as_mut_ptr() as *mut c_void;
unsafe {
match ffi::archive_read_data(self.handle(), cbuf, buf.len()) {
n if n >= 0 => Ok(n as usize),
// Libarchive returns OS errors, but has more specific error strings (err_msg()).
// Not sure how to include that in the io::Error struct.
_ => Err(io::Error::from_raw_os_error(self.err_code().0)),
}
}
}
}

pub struct FileReader {
handle: *mut ffi::Struct_archive,
entry: ReaderEntry,
Expand Down

0 comments on commit b8608b4

Please sign in to comment.