mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-08 12:35:41 +00:00
Remove duplicated if/else branches
This commit is contained in:
parent
0f3bc4f444
commit
91a1054c3c
@ -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<()> {
|
||||
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);
|
||||
|
||||
// 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)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user