mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 11:35:45 +00:00
Update README & minor code cleanup
This commit is contained in:
parent
e08703850c
commit
52afe3afd8
38
README.md
38
README.md
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
`ouch` is the Obvious Unified Compression (and decompression) Helper.
|
`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?
|
## How does it work?
|
||||||
|
|
||||||
`ouch` infers commands from the extensions of its command-line options.
|
`ouch` infers commands from the extensions of its command-line options.
|
||||||
@ -27,9 +33,7 @@ OPTIONS:
|
|||||||
#### Decompressing a bunch of files
|
#### Decompressing a bunch of files
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ ouch -i file{1..5}.zip
|
$ ouch -i file{1..5}.zip another_file.tar.gz yet_another_file.tar.bz
|
||||||
info: attempting to decompress input files into single_folder
|
|
||||||
info: done!
|
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
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.
|
`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
|
||||||
|
```
|
@ -77,7 +77,7 @@ impl ZipDecompressor {
|
|||||||
println!(
|
println!(
|
||||||
"{}: attempting to decompress {:?}",
|
"{}: attempting to decompress {:?}",
|
||||||
"ouch".bright_blue(),
|
"ouch".bright_blue(),
|
||||||
from
|
&from.path
|
||||||
);
|
);
|
||||||
|
|
||||||
match from.contents {
|
match from.contents {
|
||||||
|
@ -2,7 +2,7 @@ use std::{ffi::OsStr, fs, io::Write, path::PathBuf};
|
|||||||
|
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
|
||||||
use crate::{decompressors::Decompressor, extension::Extension};
|
use crate::{decompressors::Decompressor, extension::{self, Extension}};
|
||||||
use crate::decompressors::TarDecompressor;
|
use crate::decompressors::TarDecompressor;
|
||||||
use crate::decompressors::ZipDecompressor;
|
use crate::decompressors::ZipDecompressor;
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -31,23 +31,25 @@ impl Evaluator {
|
|||||||
return Err(error::Error::InvalidInput);
|
return Err(error::Error::InvalidInput);
|
||||||
}
|
}
|
||||||
let extension = Extension::new(&file.path.to_str().unwrap())?;
|
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> {
|
CompressionFormat::Zip => Box::new(ZipDecompressor {}),
|
||||||
match ext {
|
|
||||||
CompressionFormat::Tar => Box::new(TarDecompressor {}),
|
|
||||||
|
|
||||||
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 {
|
CompressionFormat::Zip => Some(Box::new(ZipDecompressor {})),
|
||||||
Some(ext) => Some(decompressor_from_format(ext)),
|
|
||||||
|
_other => None,
|
||||||
|
},
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,6 +99,10 @@ impl Evaluator {
|
|||||||
|
|
||||||
|
|
||||||
let decompression_result = decompressor.decompress(file, output_file)?;
|
let decompression_result = decompressor.decompress(file, output_file)?;
|
||||||
|
if let DecompressionResult::FileInMemory(_) = decompression_result {
|
||||||
|
// Should not be reachable.
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -100,9 +100,6 @@ pub enum CompressionFormat {
|
|||||||
Tar,
|
Tar,
|
||||||
// .zip
|
// .zip
|
||||||
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> {
|
fn extension_from_os_str(ext: &OsStr) -> Result<CompressionFormat, error::Error> {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// TODO: remove tests of CompressionFormat::try_from since that's no longer used anywhere
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod cli {
|
mod cli {
|
||||||
|
|
||||||
@ -125,7 +127,7 @@ mod cli_errors {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod extension_extraction {
|
mod extension_extraction {
|
||||||
use crate::{error::OuchResult, extension::Extension};
|
use crate::{error::OuchResult, extension::Extension} ;
|
||||||
use crate::extension::CompressionFormat;
|
use crate::extension::CompressionFormat;
|
||||||
use std::{convert::TryFrom, path::PathBuf, str::FromStr};
|
use std::{convert::TryFrom, path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user