0 | module System.Zlib.Types
  1 |
  2 | import Derive.Prelude
  3 |
  4 | %language ElabReflection
  5 |
  6 | ||| An opaque handle to a zlib `z_stream` structure.
  7 | |||
  8 | ||| The structure is allocated and managed by the zlib implementation and is never inspected directly by Idris code.
  9 | |||
 10 | ||| The contained pointer is passed to the low-level zlib FFI functions.
 11 | |||
 12 | public export
 13 | record ZStreamHandle where
 14 |   constructor MkZStreamHandle
 15 |   ptr : AnyPtr
 16 |
 17 | ||| Represents the compression level supplied to zlib.
 18 | |||
 19 | ||| `NoCompression`, `BestSpeed`, `BestCompression`, and `DefaultCompression` correspond to zlib's predefined compression levels.
 20 | |||
 21 | ||| `CompressionLevel` allows an explicit zlib compression level to be supplied.
 22 | |||
 23 | public export
 24 | data ZlibCompressionLevel
 25 |   = NoCompression
 26 |   | BestSpeed
 27 |   | BestCompression
 28 |   | DefaultCompression
 29 |   | CompressionLevel Int
 30 |
 31 | %runElab derive "ZlibCompressionLevel" [Show,Eq]
 32 |
 33 | ||| Converts an Idris compression-level value to the integer expected by the zlib compression API.
 34 | |||
 35 | export
 36 | zlibCompressionLevelValue : ZlibCompressionLevel -> Int
 37 | zlibCompressionLevelValue NoCompression = 0
 38 | zlibCompressionLevelValue BestSpeed = 1
 39 | zlibCompressionLevelValue BestCompression = 9
 40 | zlibCompressionLevelValue DefaultCompression = (-1)
 41 | zlibCompressionLevelValue (CompressionLevel n) = n
 42 |
 43 | ||| Specifies when zlib should flush pending compressed output.
 44 | |||
 45 | public export
 46 | data FlushMode
 47 |   = NoFlush
 48 |   | PartialFlush
 49 |   | SyncFlush
 50 |   | FullFlush
 51 |   | Finish
 52 |   | Block
 53 |
 54 | %runElab derive "FlushMode" [Show,Eq]
 55 |
 56 | ||| Converts an Idris flush mode to the integer constant expected by the zlib compression API.
 57 | |||
 58 | export
 59 | flushModeValue : FlushMode -> Int
 60 | flushModeValue NoFlush = 0
 61 | flushModeValue PartialFlush = 1
 62 | flushModeValue SyncFlush = 2
 63 | flushModeValue FullFlush = 3
 64 | flushModeValue Finish = 4
 65 | flushModeValue Block = 5
 66 |
 67 | ||| Specifies the wrapper format used around a DEFLATE stream.
 68 | |||
 69 | ||| `ZlibWrapper` selects the standard zlib format.
 70 | |||
 71 | ||| `GZipWrapper` selects the gzip format.
 72 | |||
 73 | ||| `RawWrapper` selects a raw DEFLATE stream without a zlib or gzip wrapper.
 74 | |||
 75 | public export
 76 | data Wrapper
 77 |   = ZlibWrapper
 78 |   | GZipWrapper
 79 |   | RawWrapper
 80 |
 81 | %runElab derive "Wrapper" [Show,Eq]
 82 |
 83 | ||| The default zlib window size used by the standard zlib wrapper.
 84 | |||
 85 | export
 86 | defaultWindowBits : Int
 87 | defaultWindowBits = 15
 88 |
 89 | ||| Converts a wrapper format to the corresponding `windowBits` value required by zlib's `deflateInit2` and `inflateInit2` functions.
 90 | |||
 91 | export
 92 | windowBits : Wrapper -> Int
 93 | windowBits ZlibWrapper = 15
 94 | windowBits GZipWrapper = 31
 95 | windowBits RawWrapper = (-15)
 96 |
 97 | ||| Specifies the compression strategy used by zlib.
 98 | |||
 99 | public export
100 | data Strategy
101 |   = DefaultStrategy
102 |   | Filtered
103 |   | HuffmanOnly
104 |   | RLE
105 |   | Fixed
106 |
107 | %runElab derive "Strategy" [Show,Eq]
108 |
109 | ||| Converts an Idris compression strategy to the integer constant expected by zlib.
110 | |||
111 | export
112 | strategyValue : Strategy -> Int
113 | strategyValue DefaultStrategy = 0
114 | strategyValue Filtered = 1
115 | strategyValue HuffmanOnly = 2
116 | strategyValue RLE = 3
117 | strategyValue Fixed = 4
118 |