Move Network.Units into Common
This commit is contained in:
parent
c1d966e0cd
commit
66e8d902c5
|
@ -67,6 +67,7 @@ executable chandlr
|
||||||
Network.Http
|
Network.Http
|
||||||
Common.Network.HttpTypes
|
Common.Network.HttpTypes
|
||||||
Network.Client
|
Network.Client
|
||||||
|
Common.Network.Units
|
||||||
Common.Network.ClientTypes
|
Common.Network.ClientTypes
|
||||||
Common.Network.CatalogPostType
|
Common.Network.CatalogPostType
|
||||||
Common.Network.BoardType
|
Common.Network.BoardType
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5ca701e30861498565fd4927ea1c9ea3ea105b8c
|
Subproject commit 0e5547e7475679cd5a3a449b6f09f0f6d063244e
|
|
@ -1,19 +0,0 @@
|
||||||
module Network.Units where
|
|
||||||
|
|
||||||
import Text.Printf (printf)
|
|
||||||
|
|
||||||
data Unit = KiB | MiB | GiB | TiB | PiB | EiB | ZiB | YiB
|
|
||||||
| KB | MB | GB | TB | PB | EB | ZB | YB
|
|
||||||
deriving (Enum, Show, Bounded)
|
|
||||||
|
|
||||||
bytesToHumanReadable :: Integral a => a -> Bool -> String
|
|
||||||
bytesToHumanReadable bytes binaryPrefix = printf "%.2f %s" size (show unit)
|
|
||||||
where
|
|
||||||
(factor, units) = if binaryPrefix
|
|
||||||
then (1024.0, enumFrom KiB) -- Binary prefix, 1024 base, explicitly Double
|
|
||||||
else (1000.0, enumFrom KB) -- Decimal prefix, 1000 base, explicitly Double
|
|
||||||
(size, unit) = foldl (\(accSize, accUnit) u ->
|
|
||||||
if accSize < factor then (accSize, accUnit)
|
|
||||||
else (accSize / factor, u))
|
|
||||||
(fromIntegral bytes :: Double, if binaryPrefix then KiB else KB) -- Explicitly Double
|
|
||||||
units
|
|
Loading…
Reference in New Issue