- Enables type-safe and readable byte size variables.
- Simple Haxe abstract over
Float→ no overhead. - Convert sizes to human-readable strings (i.e
40.5 KB). - Parse sizes from human-readable strings.
Installation
haxelib install bytesize
Usage
var s: ByteSize = 5*MB + 213*KB;
trace('$s'); // 5 MB
trace(s.toString(1)); // 5.2 MB
var s: ByteSize = ByteSize.parse("123.4 kilobyte");
trace(s.toString(1)); // 123.4 KB
Math operations can be done with byte sizes.
var ratio: Float = (6 * MB) / (3 * MB); // 2.0
var div: ByteSize = (5 * GB) / 5; // 1 GB
The binary power-2 units are also supported.
var s: ByteSize = 1024*B + 1*KiB;
trace(s.toString(Binary)); // 2 KiB