mirror of
https://github.com/exoticorn/upkr.git
synced 2026-01-20 11:36:42 +01:00
add reverse compression option
This commit is contained in:
22
src/main.rs
22
src/main.rs
@@ -14,6 +14,7 @@ fn main() -> Result<()> {
|
||||
let parity_contexts = args
|
||||
.opt_value_from_str(["-p", "--parity"])?
|
||||
.unwrap_or(1usize);
|
||||
let reverse = args.contains(["-r", "--reverse"]);
|
||||
|
||||
if parity_contexts != 1 && parity_contexts != 2 && parity_contexts != 4 {
|
||||
eprintln!("--parity has to be 1, 2 or 4");
|
||||
@@ -25,10 +26,13 @@ fn main() -> Result<()> {
|
||||
|
||||
let mut data = vec![];
|
||||
File::open(infile)?.read_to_end(&mut data)?;
|
||||
if reverse {
|
||||
data.reverse();
|
||||
}
|
||||
|
||||
let mut pb = pbr::ProgressBar::new(data.len() as u64);
|
||||
pb.set_units(pbr::Units::Bytes);
|
||||
let packed_data = upkr::pack(
|
||||
let mut packed_data = upkr::pack(
|
||||
&data,
|
||||
level,
|
||||
use_bitstream,
|
||||
@@ -39,6 +43,10 @@ fn main() -> Result<()> {
|
||||
);
|
||||
pb.finish();
|
||||
|
||||
if reverse {
|
||||
packed_data.reverse();
|
||||
}
|
||||
|
||||
println!(
|
||||
"Compressed {} bytes to {} bytes ({}%)",
|
||||
data.len(),
|
||||
@@ -52,6 +60,7 @@ fn main() -> Result<()> {
|
||||
let parity_contexts = args
|
||||
.opt_value_from_str(["-p", "--parity"])?
|
||||
.unwrap_or(1usize);
|
||||
let reverse = args.contains(["-r", "--reverse"]);
|
||||
|
||||
if parity_contexts != 1 && parity_contexts != 2 && parity_contexts != 4 {
|
||||
eprintln!("--parity has to be 1, 2 or 4");
|
||||
@@ -63,8 +72,14 @@ fn main() -> Result<()> {
|
||||
|
||||
let mut data = vec![];
|
||||
File::open(infile)?.read_to_end(&mut data)?;
|
||||
let packed_data = upkr::unpack(&data, use_bitstream, parity_contexts);
|
||||
File::create(outfile)?.write_all(&packed_data)?;
|
||||
if reverse {
|
||||
data.reverse();
|
||||
}
|
||||
let mut unpacked_data = upkr::unpack(&data, use_bitstream, parity_contexts);
|
||||
if reverse {
|
||||
unpacked_data.reverse();
|
||||
}
|
||||
File::create(outfile)?.write_all(&unpacked_data)?;
|
||||
}
|
||||
Some(other) => {
|
||||
bail!("Unknown subcommand '{}'", other);
|
||||
@@ -82,5 +97,6 @@ fn print_help() {
|
||||
eprintln!(" -b, --bitstream bitstream mode");
|
||||
eprintln!(" -l, --level N compression level 0-9");
|
||||
eprintln!(" -p, --parity N use N (2/4) parity contexts");
|
||||
eprintln!(" -r, --reverse reverse input & output");
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user