MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / format_bytes

Function format_bytes

crates/openshell-core/src/progress.rs:44–60  ·  view source on GitHub ↗

Format a byte count as a human-readable string (B / KB / MB / GB). Used by compute drivers when reporting image pull progress.

(bytes: u64)

Source from the content-addressed store, hash-verified

42///
43/// Used by compute drivers when reporting image pull progress.
44pub fn format_bytes(bytes: u64) -> String {
45 const KB: u64 = 1024;
46 const MB: u64 = 1024 * KB;
47 const GB: u64 = 1024 * MB;
48
49 if bytes >= GB {
50 #[allow(clippy::cast_precision_loss)]
51 let gb = bytes as f64 / GB as f64;
52 format!("{gb:.1} GB")
53 } else if bytes >= MB {
54 format!("{} MB", bytes / MB)
55 } else if bytes >= KB {
56 format!("{} KB", bytes / KB)
57 } else {
58 format!("{bytes} B")
59 }
60}

Callers 1

format_progress_detailFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected