Update README & minor code cleanup

This commit is contained in:
Vinícius Rodrigues Miguel 2021-03-22 15:12:11 -03:00
parent e08703850c
commit 52afe3afd8
5 changed files with 57 additions and 20 deletions

View File

@ -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
```

View File

@ -77,7 +77,7 @@ impl ZipDecompressor {
println!(
"{}: attempting to decompress {:?}",
"ouch".bright_blue(),
from
&from.path
);
match from.contents {

View File

@ -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<dyn Decompressor> = match extension.second_ext {
CompressionFormat::Tar => Box::new(TarDecompressor {}),
let decompressor_from_format = |ext| -> Box<dyn Decompressor> {
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<Box<dyn Decompressor>> = 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(())
}

View File

@ -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<CompressionFormat, error::Error> {

View File

@ -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};