diff --git a/libarchive/src/write/file.rs b/libarchive/src/write/file.rs index 2bdbd62..08f2b45 100644 --- a/libarchive/src/write/file.rs +++ b/libarchive/src/write/file.rs @@ -31,11 +31,7 @@ impl FileWriter { } } - pub fn append_path>( - &mut self, - entry: &mut WriteEntry, - path: P, - ) -> crate::Result<()> { + pub fn append_data(&mut self, entry: &mut WriteEntry, r: &mut R) -> crate::Result<()> { unsafe { match ffi::archive_write_header(self.handle_mut(), entry.entry_mut()) { ffi::ARCHIVE_OK => (), @@ -43,11 +39,10 @@ impl FileWriter { } } - let mut f = fs::File::open(path)?; let mut buf = [0; 8192]; loop { - match f.read(&mut buf) { + match r.read(&mut buf) { Ok(0) => return Ok(()), Ok(written) => unsafe { match ffi::archive_write_data( @@ -68,6 +63,15 @@ impl FileWriter { } } + pub fn append_path>( + &mut self, + entry: &mut WriteEntry, + path: P, + ) -> crate::Result<()> { + let mut f = fs::File::open(path)?; + self.append_data(entry, &mut f) + } + pub fn close(&mut self) -> crate::Result<()> { unsafe { match ffi::archive_write_close(self.handle_mut()) {