From 4d518b70562bf40d7601ad82e44f50b455a57a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20M=2E=20Bezerra?= Date: Sat, 4 Jun 2022 12:47:17 -0300 Subject: [PATCH] small refactor and renamings --- src/archive/zip.rs | 4 ++-- src/commands/decompress.rs | 15 +++++++-------- src/extension.rs | 4 ++-- src/progress.rs | 12 ++++++------ 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/archive/zip.rs b/src/archive/zip.rs index d9d3ee4..183e6a4 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -45,7 +45,7 @@ where let file_path = output_folder.join(file_path); - check_for_comments(&file); + display_zip_comment_if_exists(&file); match (&*file.name()).ends_with('/') { _is_dir @ true => { @@ -191,7 +191,7 @@ where Ok(bytes) } -fn check_for_comments(file: &ZipFile) { +fn display_zip_comment_if_exists(file: &ZipFile) { let comment = file.comment(); if !comment.is_empty() { // Zip file comments seem to be pretty rare, but if they are used, diff --git a/src/commands/decompress.rs b/src/commands/decompress.rs index 98b2a50..aa297f9 100644 --- a/src/commands/decompress.rs +++ b/src/commands/decompress.rs @@ -97,8 +97,7 @@ pub fn decompress_file( reader = chain_reader_decoder(format, reader)?; } - let files_unpacked; - match formats[0].compression_formats[0] { + let files_unpacked = match formats[0].compression_formats[0] { Gzip | Bzip | Lz4 | Lzma | Snappy | Zstd => { reader = chain_reader_decoder(&formats[0].compression_formats[0], reader)?; @@ -116,10 +115,10 @@ pub fn decompress_file( let _progress = Progress::new_accessible_aware(total_input_size, true, Some(current_position_fn)); io::copy(&mut reader, &mut writer)?; - files_unpacked = vec![output_file_path]; + vec![output_file_path] } Tar => { - files_unpacked = if let ControlFlow::Continue(files) = smart_unpack( + if let ControlFlow::Continue(files) = smart_unpack( Box::new(move |output_dir| { let mut progress = Progress::new_accessible_aware(total_input_size, true, None); crate::archive::tar::unpack_archive( @@ -135,7 +134,7 @@ pub fn decompress_file( files } else { return Ok(()); - }; + } } Zip => { if formats.len() > 1 { @@ -151,7 +150,7 @@ pub fn decompress_file( io::copy(&mut reader, &mut vec)?; let zip_archive = zip::ZipArchive::new(io::Cursor::new(vec))?; - files_unpacked = if let ControlFlow::Continue(files) = smart_unpack( + if let ControlFlow::Continue(files) = smart_unpack( Box::new(move |output_dir| { let mut progress = Progress::new_accessible_aware(total_input_size, true, None); crate::archive::zip::unpack_archive( @@ -167,9 +166,9 @@ pub fn decompress_file( files } else { return Ok(()); - }; + } } - } + }; // this is only printed once, so it doesn't result in much text. On the other hand, // having a final status message is important especially in an accessibility context diff --git a/src/extension.rs b/src/extension.rs index e8807d0..77ace4b 100644 --- a/src/extension.rs +++ b/src/extension.rs @@ -23,9 +23,9 @@ impl PartialEq for Extension { impl Extension { /// # Panics: /// Will panic if `formats` is empty - pub fn new(formats: &'static [CompressionFormat], text: impl Into) -> Self { + pub fn new(formats: &'static [CompressionFormat], text: impl ToString) -> Self { assert!(!formats.is_empty()); - Self { compression_formats: formats, display_text: text.into() } + Self { compression_formats: formats, display_text: text.to_string() } } /// Checks if the first format in `compression_formats` is an archive diff --git a/src/progress.rs b/src/progress.rs index 930262d..02dbcd3 100644 --- a/src/progress.rs +++ b/src/progress.rs @@ -78,21 +78,21 @@ impl Progress { t += "({bytes_per_sec}, {eta}) {path}"; t }; - let pb = ProgressBar::new(total_input_size); - pb.set_style(ProgressStyle::default_bar().template(&template).progress_chars("#>-")); + let bar = ProgressBar::new(total_input_size); + bar.set_style(ProgressStyle::default_bar().template(&template).progress_chars("#>-")); while draw_rx.try_recv().is_err() { if let Some(ref pos_fn) = current_position_fn { - pb.set_position(pos_fn()); + bar.set_position(pos_fn()); } else { - pb.tick(); + bar.tick(); } if let Ok(msg) = msg_rx.try_recv() { - pb.set_message(msg); + bar.set_message(msg); } thread::sleep(Duration::from_millis(100)); } - pb.finish(); + bar.finish(); let _ = clean_tx.send(()); });