bytesize

Abstract type for human-readable byte sizes.
https://gitlab.com/haath/bytesize

To install, run:

haxelib install bytesize 0.2.0 

See using Haxelib in Haxelib documentation for more information.

README.md

  • 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
Contributors
Haath
Version
0.2.0
Published
4 years ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub

⌂