From 443a03c8f6b03423f0205594a85eb5ab7ec7b725 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Fri, 14 Jul 2023 13:04:03 +0200 Subject: [PATCH] feat(libarchive): support adding any reader --- libarchive/src/write/file.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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()) {