0 | module Codec.Compression.Zlib.Utilities
2 | import Codec.Compression.Zlib.Proofs
3 | import Control.Monad.Elin
4 | import Control.Monad.MCancel
6 | import Data.Buffer.Core
7 | import System.Posix.Timer
8 | import System.Posix.Timer.Prim
10 | import System.Zlib.Constant
11 | import System.Zlib.Error
12 | import System.Zlib.Types
13 | import System.Zlib.Raw
24 | grabMonotonicTime : Elin World [Errno] (IClock CLOCK_MONOTONIC)
25 | grabMonotonicTime = getTime CLOCK_MONOTONIC
30 | grabRealTime : Elin World [Errno] (IClock CLOCK_REALTIME)
31 | grabRealTime = getTime CLOCK_REALTIME
36 | zlibStatusMessage : Int
38 | zlibStatusMessage status =
39 | if status == (zlibconstantToInt Z_OK) then
41 | else if status == (zlibconstantToInt Z_STREAM_END) then
43 | else if status == (zlibconstantToInt Z_NEED_DICT) then
45 | else if status == (zlibconstantToInt Z_ERRNO) then
47 | else if status == (zlibconstantToInt Z_STREAM_ERROR) then
49 | else if status == (zlibconstantToInt Z_DATA_ERROR) then
51 | else if status == (zlibconstantToInt Z_MEM_ERROR) then
53 | else if status == (zlibconstantToInt Z_BUF_ERROR) then
55 | else if status == (zlibconstantToInt Z_VERSION_ERROR) then
58 | "Unknown zlib status: " ++ show status
68 | -> IO (List ZlibError)
69 | mkError location message = do
70 | now <- runElinIO grabRealTime
81 | (MiscError (show timererr))
92 | statusError : String
94 | -> IO (List ZlibError)
95 | statusError location status =
96 | mkError location (zlibStatusMessage status)
102 | freezeOutput : (used : Nat)
103 | -> IOBuffer capacity
104 | -> {auto 0 bounds : LTE used capacity}
106 | freezeOutput used output = do
107 | frozen <- mbuffer used
108 | runIO (copy output 0 0 used {p1 = bounds} {p2 = lteReflexive used} frozen)
112 | (unsafeFromMBuffer frozen))