Remove duplicated if/else branches

This commit is contained in:
Spyros Roum 2021-10-22 02:05:38 +03:00
parent 0f3bc4f444
commit 91a1054c3c

View File

@ -188,25 +188,6 @@ pub fn run(args: Opts, skip_questions_positively: Option<bool>) -> crate::Result
fn compress_files(files: Vec<PathBuf>, formats: Vec<CompressionFormat>, output_file: fs::File) -> crate::Result<()> { fn compress_files(files: Vec<PathBuf>, formats: Vec<CompressionFormat>, output_file: fs::File) -> crate::Result<()> {
let file_writer = BufWriter::with_capacity(BUFFER_CAPACITY, output_file); let file_writer = BufWriter::with_capacity(BUFFER_CAPACITY, output_file);
if let [Tar | Tgz | Zip] = *formats.as_slice() {
match formats[0] {
Tar => {
let mut bufwriter = archive::tar::build_archive_from_paths(&files, file_writer)?;
bufwriter.flush()?;
}
Tgz => {
// Wrap it into an gz_decoder, and pass to the tar archive builder
let gz_decoder = flate2::write::GzEncoder::new(file_writer, Default::default());
let mut bufwriter = archive::tar::build_archive_from_paths(&files, gz_decoder)?;
bufwriter.flush()?;
}
Zip => {
let mut bufwriter = archive::zip::build_archive_from_paths(&files, file_writer)?;
bufwriter.flush()?;
}
_ => unreachable!(),
};
} else {
let mut writer: Box<dyn Write> = Box::new(file_writer); let mut writer: Box<dyn Write> = Box::new(file_writer);
// Grab previous encoder and wrap it inside of a new one // Grab previous encoder and wrap it inside of a new one
@ -277,7 +258,6 @@ fn compress_files(files: Vec<PathBuf>, formats: Vec<CompressionFormat>, output_f
io::copy(&mut vec_buffer.as_slice(), &mut writer)?; io::copy(&mut vec_buffer.as_slice(), &mut writer)?;
} }
} }
}
Ok(()) Ok(())
} }