Skip to content

Commit be4a17f

Browse files
committed
refactor: use HumanBytes instead
This removes one dependency bytesize as it hasn't yet support controlling precision throught format options.
1 parent ef68902 commit be4a17f

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ anyhow = "1.0.95"
2525
base64 = "0.22.1"
2626
blake3 = "1.5.5"
2727
build-rs = { version = "0.3.0", path = "crates/build-rs" }
28-
bytesize = "1.3"
2928
cargo = { path = "" }
3029
cargo-credential = { version = "0.4.2", path = "credential/cargo-credential" }
3130
cargo-credential-libsecret = { version = "0.4.13", path = "credential/cargo-credential-libsecret" }
@@ -157,7 +156,6 @@ anstyle.workspace = true
157156
anyhow.workspace = true
158157
base64.workspace = true
159158
blake3.workspace = true
160-
bytesize.workspace = true
161159
cargo-credential.workspace = true
162160
cargo-platform.workspace = true
163161
cargo-util-schemas.workspace = true

src/cargo/core/package.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::rc::Rc;
99
use std::time::{Duration, Instant};
1010

1111
use anyhow::Context as _;
12-
use bytesize::ByteSize;
1312
use cargo_util_schemas::manifest::RustVersion;
1413
use curl::easy::Easy;
1514
use curl::multi::{EasyHandle, Multi};
@@ -35,6 +34,7 @@ use crate::util::network::http::http_handle_and_timeout;
3534
use crate::util::network::http::HttpTimeout;
3635
use crate::util::network::retry::{Retry, RetryResult};
3736
use crate::util::network::sleep::SleepTracker;
37+
use crate::util::HumanBytes;
3838
use crate::util::{self, internal, GlobalContext, Progress, ProgressStyle};
3939

4040
/// Information about a package that is available somewhere in the file system.
@@ -914,7 +914,8 @@ impl<'a, 'gctx> Downloads<'a, 'gctx> {
914914
// have a great view into the progress of the extraction. Let's prepare
915915
// the user for this CPU-heavy step if it looks like it'll take some
916916
// time to do so.
917-
if dl.total.get() < ByteSize::kb(400).0 {
917+
let kib_400 = 1024 * 400;
918+
if dl.total.get() < kib_400 {
918919
self.tick(WhyTick::DownloadFinished)?;
919920
} else {
920921
self.tick(WhyTick::Extracting(&dl.id.name()))?;
@@ -1113,7 +1114,7 @@ impl<'a, 'gctx> Downloads<'a, 'gctx> {
11131114
}
11141115
}
11151116
if remaining > 0 && dur > Duration::from_millis(500) {
1116-
msg.push_str(&format!(", remaining bytes: {}", ByteSize(remaining)));
1117+
msg.push_str(&format!(", remaining bytes: {:.1}", HumanBytes(remaining)));
11171118
}
11181119
}
11191120
}
@@ -1153,20 +1154,21 @@ impl<'a, 'gctx> Drop for Downloads<'a, 'gctx> {
11531154
"crates"
11541155
};
11551156
let mut status = format!(
1156-
"{} {} ({}) in {}",
1157+
"{} {} ({:.1}) in {}",
11571158
self.downloads_finished,
11581159
crate_string,
1159-
ByteSize(self.downloaded_bytes),
1160+
HumanBytes(self.downloaded_bytes),
11601161
util::elapsed(self.start.elapsed())
11611162
);
11621163
// print the size of largest crate if it was >1mb
11631164
// however don't print if only a single crate was downloaded
11641165
// because it is obvious that it will be the largest then
1165-
if self.largest.0 > ByteSize::mb(1).0 && self.downloads_finished > 1 {
1166+
let mib_1 = 1024 * 1024;
1167+
if self.largest.0 > mib_1 && self.downloads_finished > 1 {
11661168
status.push_str(&format!(
1167-
" (largest was `{}` at {})",
1169+
" (largest was `{}` at {:.1})",
11681170
self.largest.1,
1169-
ByteSize(self.largest.0),
1171+
HumanBytes(self.largest.0),
11701172
));
11711173
}
11721174
// Clear progress before displaying final summary.

0 commit comments

Comments
 (0)