on cdff1db help sign in
Idris-dev/src/Util/Zlib.hs
15 lines 689 B history raw
1module Util.Zlib (decompressEither) where
3-- From http://stackoverflow.com/questions/10043102/how-to-catch-the-decompress-ioerror/10045963#10045963
4import Codec.Compression.Zlib.Internal
5import Data.ByteString.Lazy (ByteString, fromChunks)
6import Control.Arrow (right)
8decompressEither :: ByteString -> Either (DecompressError, String) ByteString
9decompressEither = finalise
10 . foldDecompressStream cons nil err
11 . decompressWithErrors zlibFormat defaultDecompressParams
12 where err errorCode errorString = Left (errorCode, errorString)
13 nil = Right []
14 cons chunk = right (chunk :)
15 finalise = right fromChunks