Skip to content

Commit

Permalink
update the byte-unit crate
Browse files Browse the repository at this point in the history
  • Loading branch information
magiclen committed Nov 26, 2023
1 parent 2fa59bd commit 3e327fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ terminal_size = "0.3"

anyhow = "1"

byte-unit = "5"
execute = "0.2"
num_cpus = "1"
scanner-rust = "2"

[dependencies.path-absolutize]
version = "3"
features = ["once_cell_cache"]

[dependencies.byte-unit]
version = "4"
features = ["std"]
default-features = false
features = ["once_cell_cache"]
27 changes: 13 additions & 14 deletions src/commands/compression.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{borrow::Cow, fs, fs::File, io, process};

use anyhow::{anyhow, Context};
use byte_unit::{Byte, ByteUnit};
use byte_unit::{Byte, Unit};
use execute::{command_args, Execute};
use path_absolutize::{Absolutize, CWD};

Expand Down Expand Up @@ -703,15 +703,14 @@ pub fn handle_compression(cli_args: CLIArgs) -> anyhow::Result<()> {
}

if let Some(d) = split {
let byte = Byte::from_str(d)?;
let byte = Byte::parse_str(d, true)?;

if byte.get_bytes() < 65536 {
if byte.as_u64() < 65536 {
return Err(anyhow!("The split size is too small."));
} else {
command2.arg(format!(
"-v{}k",
byte.get_adjusted_unit(ByteUnit::KiB).get_value().round()
as u32
byte.get_adjusted_unit(Unit::KiB).get_value().round() as u32
));
}
}
Expand Down Expand Up @@ -1418,15 +1417,15 @@ pub fn handle_compression(cli_args: CLIArgs) -> anyhow::Result<()> {
if let Some(d) = split {
let mut volume = String::from("-v");

let byte = Byte::from_str(d)?;
let byte = Byte::parse_str(d, true)?;

if byte.get_bytes() < 65536 {
if byte.as_u64() < 65536 {
return Err(anyhow!("The split size is too small."));
} else {
volume.push_str(
format!(
"{}k",
byte.get_adjusted_unit(ByteUnit::KiB).get_value().round() as u32
byte.get_adjusted_unit(Unit::KiB).get_value().round() as u32
)
.as_str(),
);
Expand All @@ -1451,9 +1450,9 @@ pub fn handle_compression(cli_args: CLIArgs) -> anyhow::Result<()> {
let password = read_password(cli_args.password)?;

let split = if let Some(d) = split {
let byte = Byte::from_str(d)?;
let byte = Byte::parse_str(d, true)?;

if byte.get_bytes() < 65536 {
if byte.as_u64() < 65536 {
return Err(anyhow!("The split size is too small."));
}

Expand Down Expand Up @@ -1534,7 +1533,7 @@ pub fn handle_compression(cli_args: CLIArgs) -> anyhow::Result<()> {
"-s",
format!(
"{}k",
byte.get_adjusted_unit(ByteUnit::KiB).get_value().round() as u32
byte.get_adjusted_unit(Unit::KiB).get_value().round() as u32
)
);

Expand Down Expand Up @@ -1612,14 +1611,14 @@ pub fn handle_compression(cli_args: CLIArgs) -> anyhow::Result<()> {
}

if let Some(d) = split {
let byte = Byte::from_str(d)?;
let byte = Byte::parse_str(d, true)?;

if byte.get_bytes() < 65536 {
if byte.as_u64() < 65536 {
return Err(anyhow!("The split size is too small."));
} else {
command.arg(format!(
"-v{}k",
byte.get_adjusted_unit(ByteUnit::KiB).get_value().round() as u32
byte.get_adjusted_unit(Unit::KiB).get_value().round() as u32
));
}
}
Expand Down

0 comments on commit 3e327fb

Please sign in to comment.