filesizes 1.1.0
Library for parsing, formatting, and generally working with 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:
filesizes
A library for parsing, formatting, and generally working with file sizes.
Formatting
First, a simple example:
import filesizes;
import std.file : getSize;
import std.stdio;
void main() {
ulong size = getSize("my-large-file.dat");
writefln!"My file is %s"(formatFilesize(size));
}
Assuming my-large-file.dat
is 92874 bytes, we will get the following output:
My file is 92.9 KB
You can provide additional settings to change how things are formatted:
string s = formatFilesize("%.3f", size, false, false);
writefln!"My file is %s"(s);
This will write the following:
My file is 90.687 Kibibytes
Parsing
This library also provides methods to parse filesize expressions.
import filesizes;
import std.stdio;
void main() {
string sizeStr = "45 gigabytes";
writefln!"%s is equal to %d bytes"(sizeStr, parseFilesize(sizeStr));
}
This will write the following:
45 gigabytes is equal to 45000000000 bytes"
Please see the documentation for more details.
- 1.1.0 released 2 years ago
- andrewlalis/filesizes
- MIT
- Copyright © 2022, Andrew Lalis
- Authors:
- Dependencies:
- none
- Versions:
-
1.1.0 2022-Mar-10 1.0.0 2022-Mar-08 ~main 2022-Mar-10 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
13 downloads total
-
- Score:
- 0.7
- Short URL:
- filesizes.dub.pm