diff --git a/README.md b/README.md index a2c47da..6e87aeb 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,12 @@ `ouch` is the Obvious Unified Compression (and decompression) Helper. + +| Supported formats | .tar | .zip | .tar.{.lz, .lzma, .gz, .bz} | .zip.{.lz, .lzma, .gz, .bz} | .bz | .gz | .lz, .lzma | +|-------------------|------|------|------------------------------|------------------------------|-----|-----|------------| +| Decompression | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | +| Compression | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | + ## How does it work? `ouch` infers commands from the extensions of its command-line options. @@ -27,9 +33,7 @@ OPTIONS: #### Decompressing a bunch of files ```bash -$ ouch -i file{1..5}.zip -info: attempting to decompress input files into single_folder -info: done! +$ ouch -i file{1..5}.zip another_file.tar.gz yet_another_file.tar.bz ``` When no output file is supplied, `ouch` infers that it must decompress all of its input files. This will error if any of the input files are not decompressible. @@ -63,5 +67,33 @@ error: file 'some-file' is not decompressible. `ouch` might (TODO!) be able to sniff a file's compression format if it isn't supplied in the future, but that is not currently implemented. +## Installation +### Runtime dependencies +`ouch` depends on a few widespread libraries: +* libbz2 +* liblzma + +Both should be already installed in any mainstream Linux distribution. + +If they're not, then: + +* On Debian-based distros + +`sudo apt install liblzma-dev libbz2-dev` + +* On Arch-based distros + +`sudo pacman -S xz bzip2` + +The last dependency is a recent [Rust](https://www.rust-lang.org/) toolchain. If you don't have one installed, follow the instructions at [rustup.rs](https://rustup.rs/). + +### Build process + +Once the dependency requirements are met: + +```bash +git clone https://github.com/vrmiguel/jacarex # Clone the repo. +cargo install --path ouch # .. and install it +``` \ No newline at end of file diff --git a/src/decompressors/zip.rs b/src/decompressors/zip.rs index 7eb32d9..64405ae 100644 --- a/src/decompressors/zip.rs +++ b/src/decompressors/zip.rs @@ -77,7 +77,7 @@ impl ZipDecompressor { println!( "{}: attempting to decompress {:?}", "ouch".bright_blue(), - from + &from.path ); match from.contents { diff --git a/src/evaluator.rs b/src/evaluator.rs index dbfe03b..644875f 100644 --- a/src/evaluator.rs +++ b/src/evaluator.rs @@ -2,7 +2,7 @@ use std::{ffi::OsStr, fs, io::Write, path::PathBuf}; use colored::Colorize; -use crate::{decompressors::Decompressor, extension::Extension}; +use crate::{decompressors::Decompressor, extension::{self, Extension}}; use crate::decompressors::TarDecompressor; use crate::decompressors::ZipDecompressor; use crate::{ @@ -31,23 +31,25 @@ impl Evaluator { return Err(error::Error::InvalidInput); } let extension = Extension::new(&file.path.to_str().unwrap())?; + + let second_decompressor: Box = match extension.second_ext { + CompressionFormat::Tar => Box::new(TarDecompressor {}), - let decompressor_from_format = |ext| -> Box { - match ext { - CompressionFormat::Tar => Box::new(TarDecompressor {}), + CompressionFormat::Zip => Box::new(ZipDecompressor {}), - CompressionFormat::Zip => Box::new(ZipDecompressor {}), - - CompressionFormat::Gzip | CompressionFormat::Lzma | CompressionFormat::Bzip => { - Box::new(NifflerDecompressor {}) - } + CompressionFormat::Gzip | CompressionFormat::Lzma | CompressionFormat::Bzip => { + Box::new(NifflerDecompressor {}) } }; - let second_decompressor = decompressor_from_format(extension.second_ext); + let first_decompressor: Option> = match extension.first_ext { + Some(ext) => match ext { + CompressionFormat::Tar => Some(Box::new(TarDecompressor {})), - let first_decompressor = match extension.first_ext { - Some(ext) => Some(decompressor_from_format(ext)), + CompressionFormat::Zip => Some(Box::new(ZipDecompressor {})), + + _other => None, + }, None => None, }; @@ -97,6 +99,10 @@ impl Evaluator { let decompression_result = decompressor.decompress(file, output_file)?; + if let DecompressionResult::FileInMemory(_) = decompression_result { + // Should not be reachable. + unreachable!(); + } Ok(()) } diff --git a/src/extension.rs b/src/extension.rs index 30fe428..38e682c 100644 --- a/src/extension.rs +++ b/src/extension.rs @@ -100,9 +100,6 @@ pub enum CompressionFormat { Tar, // .zip Zip, - // Not a supported compressed file extension (any other file) - // TODO: it makes no sense for this variant to exist here - // NotCompressed } fn extension_from_os_str(ext: &OsStr) -> Result { diff --git a/src/test.rs b/src/test.rs index 64fcbbc..e7e1517 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1,3 +1,5 @@ +// TODO: remove tests of CompressionFormat::try_from since that's no longer used anywhere + #[cfg(test)] mod cli { @@ -125,7 +127,7 @@ mod cli_errors { #[cfg(test)] mod extension_extraction { - use crate::{error::OuchResult, extension::Extension}; + use crate::{error::OuchResult, extension::Extension} ; use crate::extension::CompressionFormat; use std::{convert::TryFrom, path::PathBuf, str::FromStr};