#byte #utility #parse #format

bytefmt

an utility to parse byte string into bytes count and vice versa

7 releases

0.1.7 Nov 8, 2018
0.1.6 Nov 8, 2018

#12 in #byte

Download history 92/week @ 2019-11-01 24/week @ 2019-11-08 73/week @ 2019-11-15 92/week @ 2019-11-22 59/week @ 2019-11-29 63/week @ 2019-12-06 195/week @ 2019-12-13 15/week @ 2019-12-20 47/week @ 2019-12-27 30/week @ 2020-01-03 122/week @ 2020-01-10 123/week @ 2020-01-17 109/week @ 2020-01-24 637/week @ 2020-01-31 207/week @ 2020-02-07

423 downloads per month
Used in 2 crates

MIT/Apache

18KB
277 lines

bytefmt

bytefmt on travis bytefmt on crates.io bytefmt on docs.rs

Bytefmt is Rust utility to parse byte string into bytes count and vice versa.

Installation

Put bytefmt to your dependencies in Cargo.toml file:

[dependencies]
bytefmt = "0.1.7"

Usage Examples

extern crate bytefmt;

fn main() {
    let input = "1.23 MB";

    // Parse string into bytes
    let bytes: u64 = bytefmt::parse(input).unwrap();
    assert_eq!(bytes, 1_230_000);

    // Format bytes into string
    let bytes_str = bytefmt::format(bytes);
    assert_eq!(&bytes_str, input);

    // Parse to specific unit
    let kb: f64 = bytefmt::parse_to(input, bytefmt::Unit::KB).unwrap();
    assert_eq!(kb, 1_230 as f64);

    // Format to specific unit
    let kb_str = bytefmt::format_to(bytes, bytefmt::Unit::KB);
    assert_eq!(&kb_str, "1230 KB");
}

Dependencies

~1.5MB
~41K SLoC