Skip to main content

parse_byte_size

Function parse_byte_size 

Source
pub fn parse_byte_size(value: &str) -> Result<Option<u64>>
Expand description

Parse a byte size such as 5MB, 500KB, 2M, 500K, 4096, or 0.

The scale letter (k/m/g/t) is case-insensitive; the unit letter distinguishes bytes (B) from bits (b). So 5KB is 5000 bytes while 5Kb is 5000 bits (625 bytes), and bare scales such as 2M mean bytes. A trailing /s is accepted for backward compatibility but ignored.

ยงErrors

Returns an error if the value is not a whole number of bytes with a supported suffix.