Skip to content

Displaying human readable byte quantities, supporting binary and SI notations.

License

Notifications You must be signed in to change notification settings

matthieus/human-bytes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

human-bytes: human readable byte quantities

Intro

Package containing utilities to deal with the display of byte quantities.

Features include

  • a DSL to write human readable large quantities of bytes,
  • formatting byte quantities from a Long,
  • parsing byte quantities from a String.
Prefixes used for bytes (B)
Decimal (SI) Binary (IEC)
1000 k (kilo) 1024 Ki (kibi)
10002 M (mega) 10242 Mi (mebi)
10003 G (giga) 10243 Gi (gibi)
10004 T (tera) 10244 Ti (tebi)
10005 P (peta) 10245 Pi (pebi)
10006 E (exa) 10246 Ei (exbi)

See http://en.wikipedia.org/wiki/Byte for a discussion on the subject.

Note: The ambiguous JEDEC standard is not supported.

Usage

The DSL

import com.bizo.bytes._
// if you want to use the postfix notation (space between the value and the unit.)
import scala.language.postfixOps

val sizeSI = 10.kB
val sizeBinary = 10.KiB
// or with the postfix notation
val biggerSizeSI = 10 EB
val biggerSizeBinary = 10 EiB

Formatting a Long as byte quantities

import com.bizo.bytes._

println(SI(123456))  // prints 123.5kB
println(BIN(123456)) // prints 120.6KiB

Parsing byte quantities

import com.bizo.bytes._

val bytes = humanBytesToLong("123kB")  // 123000L
val bytes = humanBytesToLong("123KiB") // 125952L

Building

You need SBT 0.13 or higher.

# Compile and package jars.
sbt package

# Generate API documentation.
sbt doc

Target platform

  • Scala 2.10+

License

human-bytes is is licensed under the terms of the Apache Software License v2.0.

Copyright

Unless otherwise noted, all source files in this repository are Copyright (C) Bizo, inc. 2014

About

Displaying human readable byte quantities, supporting binary and SI notations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published