diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-02-15 21:43:43 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-02-15 21:43:43 +0100 |
commit | 13d6b9ac1ca17315c975e7a6d10ace21f879ceb4 (patch) | |
tree | c410305c921a5fb24de9ed5e305264e73cd8b802 /src/decompress.rs | |
parent | 08fd2bd54802c803e20edcdbde78d6b53b5af541 (diff) |
decompress zip with same crate. Clippy
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) } |