1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE EmptyDataDecls #-}
module Codec.Zlib.Lowlevel
( ZStreamStruct
, ZStream'
, zstreamNew
, Strategy(..)
, deflateInit2
, inflateInit2
, c_free_z_stream_inflate
, c_free_z_stream_deflate
, c_set_avail_in
, c_set_avail_out
, c_get_avail_out
, c_get_avail_in
, c_call_inflate_noflush
, c_call_deflate_noflush
, c_call_deflate_finish
, c_call_deflate_flush
, c_call_deflate_set_dictionary
, c_call_inflate_set_dictionary
) where
import Foreign.C
import Foreign.Ptr
import Codec.Compression.Zlib (WindowBits (WindowBits))
data ZStreamStruct
type ZStream' = Ptr ZStreamStruct
data Strategy =
StrategyDefault
| StrategyFiltered
| StrategyHuffman
| StrategyRLE
| StrategyFixed
deriving (Show,Eq,Ord,Enum)
foreign import ccall unsafe "create_z_stream"
zstreamNew :: IO ZStream'
foreign import ccall unsafe "deflate_init2"
c_deflateInit2 :: ZStream' -> CInt -> CInt -> CInt -> CInt
-> IO ()
deflateInit2 :: ZStream' -> Int -> WindowBits -> Int -> Strategy -> IO ()
deflateInit2 zstream level windowBits memlevel strategy =
c_deflateInit2 zstream (fromIntegral level) (wbToInt windowBits)
(fromIntegral memlevel)
(fromIntegral $ fromEnum strategy)
foreign import ccall unsafe "inflate_init2"
c_inflateInit2 :: ZStream' -> CInt -> IO ()
inflateInit2 :: ZStream' -> WindowBits -> IO ()
inflateInit2 zstream wb = c_inflateInit2 zstream (wbToInt wb)
foreign import ccall unsafe "&free_z_stream_inflate"
c_free_z_stream_inflate :: FunPtr (ZStream' -> IO ())
foreign import ccall unsafe "&free_z_stream_deflate"
c_free_z_stream_deflate :: FunPtr (ZStream' -> IO ())
foreign import ccall unsafe "set_avail_in"
c_set_avail_in :: ZStream' -> Ptr CChar -> CUInt -> IO ()
foreign import ccall unsafe "set_avail_out"
c_set_avail_out :: ZStream' -> Ptr CChar -> CUInt -> IO ()
foreign import ccall unsafe "get_avail_out"
c_get_avail_out :: ZStream' -> IO CUInt
foreign import ccall unsafe "get_avail_in"
c_get_avail_in :: ZStream' -> IO CUInt
foreign import ccall unsafe "call_inflate_noflush"
c_call_inflate_noflush :: ZStream' -> IO CInt
foreign import ccall unsafe "call_deflate_noflush"
c_call_deflate_noflush :: ZStream' -> IO CInt
foreign import ccall unsafe "call_deflate_finish"
c_call_deflate_finish :: ZStream' -> IO CInt
foreign import ccall unsafe "call_deflate_flush"
c_call_deflate_flush :: ZStream' -> IO CInt
foreign import ccall unsafe "deflate_set_dictionary"
c_call_deflate_set_dictionary :: ZStream' -> Ptr CChar -> CUInt -> IO ()
foreign import ccall unsafe "inflate_set_dictionary"
c_call_inflate_set_dictionary :: ZStream' -> Ptr CChar -> CUInt -> IO ()
wbToInt :: WindowBits -> CInt
wbToInt (WindowBits i) = fromIntegral i
wbToInt _ = 15
|