#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

#7 in Value formatting

Download history 8767/week @ 2019-11-01 7404/week @ 2019-11-08 7383/week @ 2019-11-15 7537/week @ 2019-11-22 9017/week @ 2019-11-29 8647/week @ 2019-12-06 7624/week @ 2019-12-13 4997/week @ 2019-12-20 4669/week @ 2019-12-27 7543/week @ 2020-01-03 7264/week @ 2020-01-10 8407/week @ 2020-01-17 9094/week @ 2020-01-24 9666/week @ 2020-01-31 8892/week @ 2020-02-07

32,147 downloads per month
Used in 121 crates (18 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