#byte #utility #parse #format

bytefmt

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

7 releases

Uses old Rust 2015

0.1.7 Nov 8, 2018
0.1.6 Nov 8, 2018

#278 in Network programming

Download history 310/week @ 2020-06-01 173/week @ 2020-06-08 273/week @ 2020-06-15 381/week @ 2020-06-22 230/week @ 2020-06-29 200/week @ 2020-07-06 227/week @ 2020-07-13 219/week @ 2020-07-20 180/week @ 2020-07-27 510/week @ 2020-08-03 229/week @ 2020-08-10 172/week @ 2020-08-17 169/week @ 2020-08-24 233/week @ 2020-08-31 200/week @ 2020-09-07 189/week @ 2020-09-14

1,393 downloads per month
Used in 7 crates (3 directly)

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
~40K SLoC