sizefmt ~master
A small library to format file sizes.
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
sizefmt
A small library to format file sizes.
Synopsis
unittest
{
assert("%s".format(Size(0)) == "0 B");
assert("%s".format(Size(1)) == "1 B");
assert("%s".format(Size(42)) == "42 B");
assert("%g".format(Size(1024)) == "1 KB");
assert("%.2f".format(Size(2_590_000)) == "2.47 MB");
}
You can control the formatting by creating a new type with different options:
unittest
{
enum Config config = {
symbol: "O",
unitName: "octet",
unitNamePlural: "octets",
prefixUse: PrefixUse.IEC,
useNameIfNoPrefix: true
};
alias MySize = SizeBase!config;
assert("%4.1f".format(MySize(0)) == " 0 octet");
assert("%4.1f".format(MySize(1)) == " 1 octet");
assert("%4.1f".format(MySize(42)) == " 42 octets");
assert("%4.1f".format(MySize(1024)) == " 1.0 KiO");
assert("%4.1f".format(MySize(2_590_000)) == " 2.5 MiO");
}
License: BSL 1.0
Copyright 2014-2015, Nicolas Sicard
- Registered by Nicolas Sicard
- ~master released 6 years ago
- biozic/sizefmt
- github.com/biozic/sizefmt
- BSL-1.0
- Copyright © 2014, Nicolas Sicard
- Authors:
- Dependencies:
- none
- Versions:
-
0.3.1 2015-Oct-29 0.3.0 2015-Apr-05 0.2.0 2014-Oct-31 0.1.0 2014-Oct-26 ~master 2018-Jan-04 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
536 downloads total
-
- Score:
- 1.3
- Short URL:
- sizefmt.dub.pm