Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement --fast and --slow #374

Merged
merged 4 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 11 additions & 1 deletion src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
figsoda marked this conversation as resolved.
Show resolved Hide resolved
#[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")]
Expand Down
10 changes: 10 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down