#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

#4 in Value formatting

Download history 1101/week @ 2018-09-04 1244/week @ 2018-09-11 1191/week @ 2018-09-18 1150/week @ 2018-09-25 1333/week @ 2018-10-02 1388/week @ 2018-10-09 1287/week @ 2018-10-16 1275/week @ 2018-10-23 1440/week @ 2018-10-30 1927/week @ 2018-11-06 1990/week @ 2018-11-13 2233/week @ 2018-11-20 1765/week @ 2018-11-27

2,343 downloads per month
Used in 55 crates (10 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