#byte #byte-string #parse #utility #format #vice-versa

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

#1998 in Parser implementations

Download history 3256/week @ 2023-11-24 3118/week @ 2023-12-01 2854/week @ 2023-12-08 3206/week @ 2023-12-15 1365/week @ 2023-12-22 1701/week @ 2023-12-29 3381/week @ 2024-01-05 2939/week @ 2024-01-12 3479/week @ 2024-01-19 3017/week @ 2024-01-26 3200/week @ 2024-02-02 3911/week @ 2024-02-09 3395/week @ 2024-02-16 3312/week @ 2024-02-23 3564/week @ 2024-03-01 1202/week @ 2024-03-08

12,291 downloads per month
Used in 17 crates (13 directly)

MIT/Apache

19KB
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

~2.1–3MB
~53K SLoC