#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

#5 in Value formatting

Download history 463/week @ 2018-05-27 691/week @ 2018-06-03 622/week @ 2018-06-10 733/week @ 2018-06-17 697/week @ 2018-06-24 862/week @ 2018-07-01 864/week @ 2018-07-08 1201/week @ 2018-07-15 1029/week @ 2018-07-22 981/week @ 2018-07-29 1135/week @ 2018-08-05 1126/week @ 2018-08-12 1101/week @ 2018-08-19

2,343 downloads per month

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.

MIT/Apache-2.0 license
  • No runtime deps

Reverse deps