Created
December 3, 2012 18:46
-
-
Save banacorn/4197021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adapter :: (Ptr CUChar -> CUInt -> Ptr CUChar -> Ptr CUInt -> IO CInt) -> Int -> String -> String | |
adapter function chunkSize content = map cuchar2char $ unsafePerformIO $ do | |
-- allocate buffers | |
inputBuffer <- mallocArray chunkSize | |
outputBuffer <- mallocArray chunkSize | |
outputSize <- mallocBytes 32 | |
-- put it in | |
pokeArray inputBuffer (map char2cuchar content) | |
poke outputSize (fromIntegral chunkSize) | |
-- compress | |
function inputBuffer (fromIntegral chunkSize) outputBuffer outputSize | |
-- take it out | |
output <- peekArray chunkSize outputBuffer | |
-- free buffers | |
free inputBuffer | |
free outputBuffer | |
free outputSize | |
return output | |
compress :: Int -> String -> String | |
compress = adapter c_compress | |
decompress :: Int -> String -> String | |
decompress = adapter c_decompress |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment