Merge pull request #374 from figsoda/fast

This commit is contained in:
figsoda 2023-03-20 09:05:18 -04:00 committed by GitHub
commit 2b142ff442
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View File

@ -20,6 +20,12 @@ Categories Used:
## [Unreleased](https://github.com/ouch-org/ouch/compare/0.4.1...HEAD)
### New Features
- Add flags to configure the compression level
- `--level` to precisely set the compression level [\#372](https://github.com/ouch-org/ouch/pull/372) ([xgdgsc](https://github.com/xgdgsc))
- `--fast` and `--slow` [\#374](https://github.com/ouch-org/ouch/pull/374) ([figsoda](https://github.com/figsoda))
### Improvements
- Multi-threaded compression for gzip and snappy using gzp [\#348](https://github.com/ouch-org/ouch/pull/348) ([figsoda](https://github.com/figsoda))

View File

@ -61,8 +61,18 @@ pub enum Subcommand {
output: PathBuf,
/// Compression level, applied to all formats
#[arg(short, long)]
#[arg(short, long, group = "compression-level")]
level: Option<i16>,
/// Fastest compression level possible,
/// conflicts with --level and --slow
#[arg(long, group = "compression-level")]
fast: bool,
/// Slowest (and best) compression level possible,
/// conflicts with --level and --fast
#[arg(long, group = "compression-level")]
slow: bool,
},
/// Decompresses one or more files, optionally into another folder
#[command(visible_alias = "d")]

View File

@ -45,6 +45,8 @@ pub fn run(
files,
output: output_path,
level,
fast,
slow,
} => {
// After cleaning, if there are no input files left, exit
if files.is_empty() {
@ -73,6 +75,14 @@ pub fn run(
None => return Ok(()),
};
let level = if fast {
Some(1) // Lowest level of compression
} else if slow {
Some(i16::MAX) // Highest level of compression
} else {
level
};
let compress_result = compress_files(
files,
formats,