#file #size #humanize #bytes #sizes

humansize

A configurable crate to easily represent file sizes in a human-readable format

6 releases (stable)

1.1.0 Dec 23, 2017
1.0.2 Nov 22, 2017
1.0.1 Mar 15, 2017
1.0.0 Jan 17, 2017
0.1.1 Nov 19, 2016

#8 in Value formatting

Download history 6727/week @ 2019-12-17 4639/week @ 2019-12-24 4775/week @ 2019-12-31 8614/week @ 2020-01-07 6853/week @ 2020-01-14 9183/week @ 2020-01-21 9929/week @ 2020-01-28 9924/week @ 2020-02-04 7581/week @ 2020-02-11 8871/week @ 2020-02-18 9040/week @ 2020-02-25 8488/week @ 2020-03-03 7939/week @ 2020-03-10 8896/week @ 2020-03-17 9620/week @ 2020-03-24 9450/week @ 2020-03-31

32,147 downloads per month
Used in 126 crates (19 directly)

MIT/Apache

13KB
227 lines

Humansize travis badge

Documentation

Humansize lets you easily represent file sizes in a human-friendly format. You can specify your own formatting style or pick among the three defaults provided by the library:

  • Decimal (Multiples of 1000, KB units)
  • Binary (Multiples of 1024, KiB units)
  • Conventional (Multiples of 1024, KB units)

How to use it

Cargo.Toml:

[dependencies]
humansize = "1.0.1"

Simply import the FileSize trait and the options module and call the file_size method on any positive integer, using one of the three standards provided by the options module.

extern crate humansize;
use humansize::{FileSize, file_size_opts as options};

fn main() {
	let size = 1000;
	println!("Size is {}", size.file_size(options::DECIMAL).unwrap());

	println!("Size is {}", size.file_size(options::BINARY).unwrap());

	println!("Size is {}", size.file_size(options::CONVENTIONAL).unwrap());
}

If you wish to customize the way sizes are displayed, you may create your own custom FileSizeOpts struct and pass that to the method. See the custom_options.rs file in the example folder.

No runtime deps