byteunits-0.4.0.2: 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 ByteUnit Source #

Instances
Eq ByteUnit Source # 
Instance details

Defined in Data.ByteUnits

Show ByteUnit Source # 
Instance details

Defined in Data.ByteUnits

data ByteValue Source #

Constructors

ByteValue Float ByteUnit 
Instances
Eq ByteValue Source # 
Instance details

Defined in Data.ByteUnits

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
Instance details

Defined in Data.ByteUnits

Show ByteValue Source # 
Instance details

Defined in Data.ByteUnits

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"