ByteSize

Members

Functions

isNegative
bool isNegative()
opBinary
auto opBinary(ByteSize rhs)
opCmp
int opCmp(ByteSize rhs)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(ByteSize b)
Undocumented in source. Be warned that the author may not have intended to support it.
opUnary
auto opUnary()
toHash
hash_t toHash()
Undocumented in source. Be warned that the author may not have intended to support it.
toString
void toString(void delegate(const(char)[]) sink, FormatSpec!char fmt)

Converts this byte size to a string, use %f for base 1024 or %F for base 1000

toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.
total
T total()

Properties

max
ByteSize max [@property getter]

Largest ByteSize possible.

min
ByteSize min [@property getter]

Most negative ByteSize possible.

zero
ByteSize zero [@property getter]

A ByteSize of 0. It's shorter than doing something like size!"bytes"(0) and more explicit than ByteSize.init.

Variables

bytes
long bytes;

Examples

import std.format;

assert(1.bytes.toString == "1 B");
assert(1.KiB.toString == "1.00 KiB");
assert(1.MiB.toString == "1.00 MiB");
assert(1.GiB.toString == "1.00 GiB");
assert(1.TiB.toString == "1.00 TiB");
assert(1.PiB.toString == "1.00 PiB");
assert(1.EiB.toString == "1.00 EiB");

assert(1.bytes.format!"%S" == "1 B");
assert(1.KB.format!"%S" == "1.00 KB");
assert(1.MB.format!"%S" == "1.00 MB");
assert(1.GB.format!"%S" == "1.00 GB");
assert(1.TB.format!"%S" == "1.00 TB");
assert(1.PB.format!"%S" == "1.00 PB");
assert(1.EB.format!"%S" == "1.00 EB");

assert("%g".format(1024.bytes) == "1 KiB");
assert("%.2f".format(2_590_000.bytes) == "2.47 MiB");

Meta