byteunits-0.4.0.1: Human friendly conversion between byte units (KB, MB, GB...)

Safe HaskellSafe
LanguageHaskell2010

Data.ByteUnits

Description

Here is a quick example:

ByteValue (1024 * 1024 * 3) Bytes
-- the above will evaluate to: ByteValue 3145728.0 Bytes
getShortHand . getAppropriateUnits $ ByteValue (1024 * 1024 * 3) Bytes
-- the above will evaluate to: "3.00 MB"

Synopsis

Documentation

data ByteValue Source #

Constructors

ByteValue Float ByteUnit 

Instances

Eq ByteValue Source # 
Ord ByteValue Source #

Also allows comparing sizes, but because it uses float - it might not be 100% accurate

>>> ByteValue 1024 MegaBytes == ByteValue 1 GigaBytes
False
>>> ByteValue 1023 MegaBytes < ByteValue 1 GigaBytes
True
Show ByteValue Source # 

getBytes :: ByteValue -> Float Source #

Gets the value of bytes from a ByteValue type

convertByteUnit :: ByteValue -> ByteUnit -> ByteValue Source #

Converts the ByteValue to an ByteValue with the specified ByteUnit

>>> convertByteUnit (ByteValue 500 GigaBytes) MegaBytes
ByteValue 512000.0 MegaBytes

getAppropriateUnits :: ByteValue -> ByteValue Source #

Converts to the largest unit size provided the float value is > 1

>>> getAppropriateUnits (ByteValue 1024 Bytes)
ByteValue 1 KiloBytes
>>> getAppropriateUnits (ByteValue (3.5 * 1024* 1024) Bytes)
ByteValue 3.5 MegaBytes

getShortHand :: ByteValue -> String Source #

Converts to a short string representation

>>> getShortHand $ ByteValue 100 MegaBytes
"100.00 MB"