Human bytes
human_bytes
is a Rust crate that converts bytes into human-readable values (KB, MB, etc).
Usage
Add to your Cargo.toml
:
[]
= "0.2"
And then
use human_bytes;
assert_eq!;
// or
assert_eq!;
// ________________________________/
// |
// | Needed only when you're using `u64` values,
// | because `f64` doesn't implement `std::convert::From<u64>`
human_bytes
is dependency-free, but if you want an +/- 15% speed improvement, I have a fast
feature (which depends on lexical)
[]
= { = "0.2", = [ "fast" ] }
About
This crate is based on a PHP function I found here.
It is useful because you don't have to provide a prefix, it does it on its own. This means it'll return the correct prefix, and never return "1000 KB", always "1 MB"
It has some tests I wrote to check that the conversion is correct, and it returns decimals (e.g. 16.5 GB
)
Changelog
Check the CHANGELOG.md
License
BSD 2-clause - Copyright (c) 2020 Namkhai B. (forkbomb9)