diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-02-21 21:49:14 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-02-21 21:49:14 +0100 |
commit | 53763ed13a28bbf3d7aefd732d5dd1737083017c (patch) | |
tree | 5d6b60880edf2f3168ba0f1f8e51a514adb7a8d4 /src | |
parent | 23451dbf304b399235e412969aa7e675f89d73a8 (diff) |
refactor list_file_zip and document it.
Diffstat (limited to 'src')
-rw-r--r-- | src/decompress.rs | 12 | ||||
-rw-r--r-- | src/preview.rs | 4 |
2 files changed, 6 insertions, 10 deletions
diff --git a/src/decompress.rs b/src/decompress.rs index a7d3575..d4bc001 100644 --- a/src/decompress.rs +++ b/src/decompress.rs @@ -49,17 +49,13 @@ pub fn decompress_xz(source: &Path) -> FmResult<()> { Ok(()) } +/// List files contained in a ZIP file. +/// Will return an error if the ZIP file is corrupted. pub fn list_files_zip<P>(source: P) -> FmResult<Vec<String>> where P: AsRef<Path>, { let file = File::open(source)?; - 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) + let zip = zip::ZipArchive::new(file)?; + Ok(zip.file_names().map(|f| f.to_owned()).collect()) } diff --git a/src/preview.rs b/src/preview.rs index c63f2ac..b426fc2 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -410,8 +410,8 @@ impl PdfContent { } } -/// Holds a list of file of an archive as returned by `compress_tools::list_files`. -/// It may fail if the archive can't be read properly. +/// Holds a list of file of an archive as returned by `ZipArchive::file_names`. +/// A generic error message prevent it from returning an error. #[derive(Clone)] pub struct ZipContent { length: usize, |