diff --git a/src/reader.rs b/src/reader.rs index c913b1c..c684032 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -63,6 +63,20 @@ pub trait Reader : Handle { } } +impl Read for Reader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + 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,