diff options
Diffstat (limited to 'src/decompress.rs')
-rw-r--r-- | src/decompress.rs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/decompress.rs b/src/decompress.rs index 7ba8559..007edbc 100644 --- a/src/decompress.rs +++ b/src/decompress.rs @@ -1,8 +1,6 @@ use std::fs::File; use std::path::Path; -use compress_tools::*; - use crate::fm_error::{FmError, FmResult}; /// Decompress a compressed file into its parent directory. @@ -10,20 +8,28 @@ use crate::fm_error::{FmError, FmResult}; /// which should be impossible. /// It used `compress_tools` which is a wrapper around `libarchive`. pub fn decompress(source: &Path) -> FmResult<()> { + let file = File::open(source)?; + let mut zip = zip::ZipArchive::new(file)?; + let parent = source .parent() .ok_or_else(|| FmError::custom("decompress", "source should have a parent"))?; - let file = File::open(source)?; - Ok(uncompress_archive(&file, parent, Ownership::Preserve)?) + zip.extract(parent)?; + + Ok(()) } -/// Returns a list of compressed files within the archive. -/// it may fail if the file can't be opened or if libarchive -/// can't read it. pub fn list_files<P>(source: P) -> FmResult<Vec<String>> where P: AsRef<Path>, { let file = File::open(source)?; - Ok(list_archive_files(file)?) + let mut content = vec![]; + let mut zip = zip::ZipArchive::new(file)?; + + for i in 0..zip.len() { + let file = zip.by_index(i)?; + content.push(file.name().to_owned()); + } + Ok(content) } |