iteratee-compress 0.3.1.0 → 0.3.2.0
raw patch · 3 files changed
+77/−92 lines, 3 filesdep ~iterateenew-uploaderPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: iteratee
API changes (from Hackage documentation)
- Data.Iteratee.ZLib: blockFlush :: Monad m => Iteratee ByteString m ()
- Data.Iteratee.ZLib: fullFlush :: Monad m => Iteratee ByteString m ()
- Data.Iteratee.ZLib: syncFlush :: Monad m => Iteratee ByteString m ()
- Data.Iteratee.ZLib: defaultDecompressParams :: Maybe ByteString -> DecompressParams
+ Data.Iteratee.ZLib: defaultDecompressParams :: DecompressParams
Files
- Data/Iteratee/BZip.hsc +33/−32
- Data/Iteratee/ZLib.hsc +38/−54
- iteratee-compress.cabal +6/−6
Data/Iteratee/BZip.hsc view
@@ -1,9 +1,11 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE ForeignFunctionInterface #-}++{-# OPTIONS -Wall -fno-warn-unused-do-bind #-} module Data.Iteratee.BZip (- -- * Enumerators+ -- * Enumeratees enumCompress, enumDecompress, -- * Exceptions@@ -20,13 +22,11 @@ where #include <bzlib.h> -import Control.Applicative import Control.Exception import Control.Monad.Trans import Data.ByteString as BS import Data.ByteString.Internal import Data.Iteratee-import Data.Iteratee.IO import Data.Typeable import Foreign import Foreign.C@@ -98,9 +98,6 @@ withBZStream :: BZStream -> (Ptr BZStream -> IO a) -> IO a withBZStream (BZStream fptr) = withForeignPtr fptr -mallocBZStream :: IO BZStream-mallocBZStream = BZStream <$> mallocForeignPtrBytes #{size bz_stream}- -- Following code is copied from Duncan Coutts bzlib haskell library version -- 0.5.2.0 ((c) 2006-2008 Duncan Coutts, published on BSD licence) and adapted @@ -114,6 +111,7 @@ compressBufferSize :: !Int } +defaultCompressParams :: CompressParams defaultCompressParams = CompressParams DefaultBlockSize DefaultWorkFactor (8*1024) @@ -126,6 +124,7 @@ decompressBufferSize :: !Int } +defaultDecompressParams :: DecompressParams defaultDecompressParams = DecompressParams False (8*1024) -- | The compression level specify the tradeoff between speed and compression.@@ -287,19 +286,19 @@ -> (BZStream -> CInt -> IO CInt) -> Initial -> Enumeratee ByteString ByteString m a-insertOut size run (Initial bzstr) iter = do+insertOut size runf (Initial bzstr) iter = do _out <- liftIO $ putOutBuffer size bzstr #ifdef DEBUG liftIO $ IO.hPutStrLn stderr $ "Inserted out buffer of size " ++ show size #endif- fill size run (EmptyIn bzstr _out) iter+ fill size runf (EmptyIn bzstr _out) iter fill :: MonadIO m => Int -> (BZStream -> CInt -> IO CInt) -> EmptyIn -> Enumeratee ByteString ByteString m a-fill size run (EmptyIn bzstr _out) iter+fill size runf (EmptyIn bzstr _out) iter = let fill' (Chunk _in) | not (BS.null _in) = do liftIO $ putInBuffer bzstr _in@@ -307,15 +306,15 @@ liftIO $ IO.hPutStrLn stderr $ "Inserted in buffer of size " ++ show (BS.length _in) #endif- doRun size run (Invalid bzstr _in _out) iter+ doRun size runf (Invalid bzstr _in _out) iter | otherwise = fillI fill' (EOF Nothing) = do out <- liftIO $ pullOutBuffer bzstr _out iter' <- lift $ enumPure1Chunk out iter- finish size run (Finishing bzstr BS.empty) iter'+ finish size runf (Finishing bzstr BS.empty) iter' fill' (EOF (Just err)) = case fromException err of- Just err' -> flush size run (Flushing bzstr err' _out) iter+ Just err' -> flush size runf (Flushing bzstr err' _out) iter Nothing -> throwRecoverableErr err fill' #ifdef DEBUG fillI = do@@ -331,24 +330,24 @@ -> (BZStream -> CInt -> IO CInt) -> FullOut -> Enumeratee ByteString ByteString m a-swapOut size run (FullOut bzstr _in) iter = do+swapOut size runf (FullOut bzstr _in) iter = do _out <- liftIO $ putOutBuffer size bzstr #ifdef DEBUG liftIO $ IO.hPutStrLn stderr $ "Swapped out buffer of size " ++ show size #endif- doRun size run (Invalid bzstr _in _out) iter+ doRun size runf (Invalid bzstr _in _out) iter doRun :: MonadIO m => Int -> (BZStream -> CInt -> IO CInt) -> Invalid -> Enumeratee ByteString ByteString m a-doRun size run (Invalid bzstr _in _out) iter = do+doRun size runf (Invalid bzstr _in _out) iter = do #ifdef DEBUG liftIO $ IO.hPutStrLn stderr $ "About to run" liftIO $ dumpZStream bzstr #endif- status <- liftIO $ run bzstr #{const BZ_RUN}+ status <- liftIO $ runf bzstr #{const BZ_RUN} #ifdef DEBUG liftIO $ IO.hPutStrLn stderr $ "Runned" #endif@@ -371,10 +370,10 @@ out <- liftIO $ pullOutBuffer bzstr _out iter' <- lift $ enumPure1Chunk out iter case avail_in of- 0 -> insertOut size run (Initial bzstr) iter'- _ -> swapOut size run (FullOut bzstr _in) iter'+ 0 -> insertOut size runf (Initial bzstr) iter'+ _ -> swapOut size runf (FullOut bzstr _in) iter' _ -> case avail_in of- 0 -> fill size run (EmptyIn bzstr _out) iter+ 0 -> fill size runf (EmptyIn bzstr _out) iter _ -> do _ <- joinIM $ enumErr IncorrectState iter throwErr (toException IncorrectState)@@ -384,8 +383,8 @@ -> (BZStream -> CInt -> IO CInt) -> Flushing -> Enumeratee ByteString ByteString m a-flush size run fin@(Flushing bzstr _flush _out) iter = do- status <- liftIO $ run bzstr (fromFlush _flush)+flush size runf (Flushing bzstr _flush _out) iter = do+ status <- liftIO $ runf bzstr (fromFlush _flush) case fromErrno status of Left err -> do _ <- joinIM $ enumErr err iter@@ -395,7 +394,8 @@ iter' <- lift $ enumPure1Chunk out iter idone iter' (Chunk BS.empty) Right True -> do- (avail_in, avail_out) <- liftIO $ withBZStream bzstr $ \bzptr -> do+ -- TODO: avail_in unused (4th time!)+ (_avail_in, avail_out) <- liftIO $ withBZStream bzstr $ \bzptr -> do avail_in <- liftIO $ #{peek bz_stream, avail_in} bzptr avail_out <- liftIO $ #{peek bz_stream, avail_out} bzptr return (avail_in, avail_out) :: IO (CInt, CInt)@@ -404,21 +404,21 @@ out <- liftIO $ pullOutBuffer bzstr _out iter' <- lift $ enumPure1Chunk out iter out' <- liftIO $ putOutBuffer size bzstr- flush size run (Flushing bzstr _flush out') iter'- _ -> insertOut size run (Initial bzstr) iter+ flush size runf (Flushing bzstr _flush out') iter'+ _ -> insertOut size runf (Initial bzstr) iter finish :: MonadIO m => Int -> (BZStream -> CInt -> IO CInt) -> Finishing -> Enumeratee ByteString ByteString m a-finish size run fin@(Finishing bzstr _in) iter = do+finish size runf fin@(Finishing bzstr _in) iter = do #ifdef DEBUG liftIO $ IO.hPutStrLn stderr $ "Finishing with out buffer of size " ++ show size #endif _out <- liftIO $ putOutBuffer size bzstr- status <- liftIO $ run bzstr #{const BZ_FINISH}+ status <- liftIO $ runf bzstr #{const BZ_FINISH} case fromErrno status of Left err -> do _ <- lift $ enumErr err iter@@ -429,16 +429,17 @@ iter' <- lift $ enumPure1Chunk out iter idone iter' (Chunk remaining) Right True -> do- (avail_in, avail_out) <- liftIO $ withBZStream bzstr $ \bzptr -> do+ -- TODO: avail_in is unused, is this an error or can it be removed?+ -- same thing in ZLib.hsc+ (_avail_in, avail_out) <- liftIO $ withBZStream bzstr $ \bzptr -> do avail_in <- liftIO $ #{peek bz_stream, avail_in} bzptr avail_out <- liftIO $ #{peek bz_stream, avail_out} bzptr return (avail_in, avail_out) :: IO (CInt, CInt) case avail_out of 0 -> do- out <- liftIO $ withBZStream bzstr $ \bzptr ->- pullOutBuffer bzstr _out+ out <- liftIO $ pullOutBuffer bzstr _out iter' <- lift $ enumPure1Chunk out iter- finish size run fin iter'+ finish size runf fin iter' _ -> do _ <- lift $ enumErr (toException IncorrectState) iter throwErr $! toException IncorrectState@@ -517,7 +518,7 @@ Left err -> do _ <- lift $ enumErr err iter throwErr (toException err)- Right init -> insertOut size compress' init iter+ Right init' -> insertOut size compress' init' iter -- | Decompress the input and send to inner iteratee. If there is end of -- zlib stream it is left unprocessed.@@ -530,4 +531,4 @@ Left err -> do _ <- lift $ enumErr err iter throwErr (toException err)- Right init -> insertOut size decompress' init iter+ Right init' -> insertOut size decompress' init' iter
Data/Iteratee/ZLib.hsc view
@@ -1,9 +1,11 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE ForeignFunctionInterface #-}++{-# OPTIONS -Wall -fno-warn-unused-do-bind #-} module Data.Iteratee.ZLib (- -- * Enumerators+ -- * Enumeratees enumInflate, enumDeflate, -- * Exceptions@@ -23,9 +25,6 @@ enumSyncFlush, enumFullFlush, enumBlockFlush,- syncFlush,- fullFlush,- blockFlush, ) where #include <zlib.h>@@ -36,7 +35,6 @@ import Data.ByteString as BS import Data.ByteString.Internal import Data.Iteratee-import Data.Iteratee.IO import Data.Foldable import Data.Typeable import Foreign@@ -132,8 +130,6 @@ withZStream :: ZStream -> (Ptr ZStream -> IO a) -> IO a withZStream (ZStream fptr) = withForeignPtr fptr -mallocZStream :: IO ZStream-mallocZStream = ZStream <$> mallocForeignPtrBytes #{size z_stream} -- Following code is copied from Duncan Coutts zlib haskell library version -- 0.5.2.0 ((c) 2006-2008 Duncan Coutts, published on BSD licence) and adapted@@ -152,6 +148,7 @@ compressDictionary :: !(Maybe ByteString) } +defaultCompressParams :: CompressParams defaultCompressParams = CompressParams DefaultCompression Deflated DefaultWindowBits DefaultMemoryLevel DefaultStrategy (8*1024) Nothing@@ -171,7 +168,8 @@ decompressDictionary :: !(Maybe ByteString) } -defaultDecompressParams = DecompressParams DefaultWindowBits (8*1024)+defaultDecompressParams :: DecompressParams+defaultDecompressParams = DecompressParams DefaultWindowBits (8*1024) Nothing -- | Specify the format for compression and decompression data Format@@ -443,19 +441,19 @@ -> (ZStream -> CInt -> IO CInt) -> Initial -> Enumeratee ByteString ByteString m a-insertOut size run (Initial zstr) iter = do+insertOut size runf (Initial zstr) iter = do _out <- liftIO $ putOutBuffer size zstr #ifdef DEBUG liftIO $ IO.hPutStrLn stderr $ "Inserted out buffer of size " ++ show size #endif- fill size run (EmptyIn zstr _out) iter+ fill size runf (EmptyIn zstr _out) iter fill :: MonadIO m => Int -> (ZStream -> CInt -> IO CInt) -> EmptyIn -> Enumeratee ByteString ByteString m a-fill size run (EmptyIn zstr _out) iter+fill size run' (EmptyIn zstr _out) iter = let fill' (Chunk _in) | not (BS.null _in) = do liftIO $ putInBuffer zstr _in@@ -463,15 +461,15 @@ liftIO $ IO.hPutStrLn stderr $ "Inserted in buffer of size " ++ show (BS.length _in) #endif- doRun size run (Invalid zstr _in _out) iter+ doRun size run' (Invalid zstr _in _out) iter | otherwise = fillI fill' (EOF Nothing) = do out <- liftIO $ pullOutBuffer zstr _out iter' <- lift $ enumPure1Chunk out iter- finish size run (Finishing zstr BS.empty) iter'+ finish size run' (Finishing zstr BS.empty) iter' fill' (EOF (Just err)) = case fromException err of- Just err' -> flush size run (Flushing zstr err' _out) iter+ Just err' -> flush size run' (Flushing zstr err' _out) iter Nothing -> throwRecoverableErr err fill' #ifdef DEBUG fillI = do@@ -487,24 +485,24 @@ -> (ZStream -> CInt -> IO CInt) -> FullOut -> Enumeratee ByteString ByteString m a-swapOut size run (FullOut zstr _in) iter = do+swapOut size run' (FullOut zstr _in) iter = do _out <- liftIO $ putOutBuffer size zstr #ifdef DEBUG liftIO $ IO.hPutStrLn stderr $ "Swapped out buffer of size " ++ show size #endif- doRun size run (Invalid zstr _in _out) iter+ doRun size run' (Invalid zstr _in _out) iter doRun :: MonadIO m => Int -> (ZStream -> CInt -> IO CInt) -> Invalid -> Enumeratee ByteString ByteString m a-doRun size run (Invalid zstr _in _out) iter = do+doRun size run' (Invalid zstr _in _out) iter = do #ifdef DEBUG liftIO $ IO.hPutStrLn stderr $ "About to run" liftIO $ dumpZStream zstr #endif- status <- liftIO $ run zstr #{const Z_NO_FLUSH}+ status <- liftIO $ run' zstr #{const Z_NO_FLUSH} #ifdef DEBUG liftIO $ IO.hPutStrLn stderr $ "Runned" #endif@@ -527,10 +525,10 @@ out <- liftIO $ pullOutBuffer zstr _out iter' <- lift $ enumPure1Chunk out iter case avail_in of- 0 -> insertOut size run (Initial zstr) iter'- _ -> swapOut size run (FullOut zstr _in) iter'+ 0 -> insertOut size run' (Initial zstr) iter'+ _ -> swapOut size run' (FullOut zstr _in) iter' _ -> case avail_in of- 0 -> fill size run (EmptyIn zstr _out) iter+ 0 -> fill size run' (EmptyIn zstr _out) iter _ -> do _ <- joinIM $ enumErr IncorrectState iter throwErr (toException IncorrectState)@@ -540,8 +538,8 @@ -> (ZStream -> CInt -> IO CInt) -> Flushing -> Enumeratee ByteString ByteString m a-flush size run fin@(Flushing zstr _flush _out) iter = do- status <- liftIO $ run zstr (fromFlush _flush)+flush size run' (Flushing zstr _flush _out) iter = do+ status <- liftIO $ run' zstr (fromFlush _flush) case fromErrno status of Left err -> do _ <- joinIM $ enumErr err iter@@ -551,7 +549,9 @@ iter' <- lift $ enumPure1Chunk out iter idone iter' (Chunk BS.empty) Right True -> do- (avail_in, avail_out) <- liftIO $ withZStream zstr $ \zptr -> do+ -- TODO: avail_in is unused, can it be completely removed?+ -- or should it be used?+ (_avail_in, avail_out) <- liftIO $ withZStream zstr $ \zptr -> do avail_in <- liftIO $ #{peek z_stream, avail_in} zptr avail_out <- liftIO $ #{peek z_stream, avail_out} zptr return (avail_in, avail_out) :: IO (CInt, CInt)@@ -560,21 +560,21 @@ out <- liftIO $ pullOutBuffer zstr _out iter' <- lift $ enumPure1Chunk out iter out' <- liftIO $ putOutBuffer size zstr- flush size run (Flushing zstr _flush out') iter'- _ -> insertOut size run (Initial zstr) iter+ flush size run' (Flushing zstr _flush out') iter'+ _ -> insertOut size run' (Initial zstr) iter finish :: MonadIO m => Int -> (ZStream -> CInt -> IO CInt) -> Finishing -> Enumeratee ByteString ByteString m a-finish size run fin@(Finishing zstr _in) iter = do+finish size run' fin@(Finishing zstr _in) iter = do #ifdef DEBUG liftIO $ IO.hPutStrLn stderr $ "Finishing with out buffer of size " ++ show size #endif _out <- liftIO $ putOutBuffer size zstr- status <- liftIO $ run zstr #{const Z_FINISH}+ status <- liftIO $ run' zstr #{const Z_FINISH} case fromErrno status of Left err -> do _ <- lift $ enumErr err iter@@ -585,16 +585,16 @@ iter' <- lift $ enumPure1Chunk out iter idone iter' (Chunk remaining) Right True -> do- (avail_in, avail_out) <- liftIO $ withZStream zstr $ \zptr -> do+ -- TODO: avail_in is unused, is this an error or can it be removed?+ (_avail_in, avail_out) <- liftIO $ withZStream zstr $ \zptr -> do avail_in <- liftIO $ #{peek z_stream, avail_in} zptr avail_out <- liftIO $ #{peek z_stream, avail_out} zptr return (avail_in, avail_out) :: IO (CInt, CInt) case avail_out of 0 -> do- out <- liftIO $ withZStream zstr $ \zptr ->- pullOutBuffer zstr _out+ out <- liftIO $ pullOutBuffer zstr _out iter' <- lift $ enumPure1Chunk out iter- finish size run fin iter'+ finish size run' fin iter' _ -> do _ <- lift $ enumErr (toException IncorrectState) iter throwErr $! toException IncorrectState@@ -662,7 +662,7 @@ mkDecompress :: Format -> DecompressParams -> IO (Either ZLibParamsException (Initial, Maybe ByteString))-mkDecompress frm cp@(DecompressParams w _ md)+mkDecompress frm (DecompressParams w _ md) = case fromWindowBits frm w of Left err -> return $! Left err Right wB' -> do@@ -694,7 +694,7 @@ Left err -> do _ <- lift $ enumErr err iter throwErr (toException err)- Right init -> insertOut size deflate' init iter+ Right init' -> insertOut size deflate' init' iter -- | Decompress the input and send to inner iteratee. If there is end of -- zlib stream it is left unprocessed.@@ -702,14 +702,14 @@ => Format -> DecompressParams -> Enumeratee ByteString ByteString m a-enumInflate f dp@(DecompressParams _ size md) iter = do+enumInflate f dp@(DecompressParams _ size _md) iter = do dcmp <- liftIO $ mkDecompress f dp case dcmp of Left err -> do _ <- lift $ enumErr err iter throwErr (toException err)- Right (init, Nothing) -> insertOut size inflate' init iter- Right (init, (Just (PS fp off len))) ->+ Right (init', Nothing) -> insertOut size inflate' init' iter+ Right (init', (Just (PS fp off len))) -> let inflate'' zstr param = do ret <- inflate' zstr param case fromErrno ret of@@ -720,17 +720,13 @@ (fromIntegral len) inflate' zstr param _ -> return ret- in insertOut size inflate'' init iter+ in insertOut size inflate'' init' iter enumSyncFlush :: Monad m => Enumerator ByteString m a -- ^ Enumerate synchronise flush. It cause the all pending output to be flushed -- and all available input is sent to inner Iteratee. enumSyncFlush = enumErr SyncFlush -syncFlush :: Monad m => Iteratee ByteString m ()--- ^ Flushes the stream requesting as much data as possible.-syncFlush = throwRecoverableErr (toException SyncFlush) (const identity)- enumFullFlush :: Monad m => Enumerator ByteString m a -- ^ Enumerate full flush. It flushes all pending output and reset the -- compression. It allows to restart from this point if compressed data was@@ -739,21 +735,9 @@ -- It may be only used during compression. enumFullFlush = enumErr FullFlush -fullFlush :: Monad m => Iteratee ByteString m ()--- ^ Flush all pending output and reset the compression. It allows to restart--- from this point if compressed data was corrupted but it can affect the--- compression rate.------ It may be only used during compression.-fullFlush = throwRecoverableErr (toException FullFlush) (const identity)- enumBlockFlush :: Monad m => Enumerator ByteString m a -- ^ Enumerate block flush. If the enumerator is compressing it allows to -- finish current block. If the enumerator is decompressing it forces to stop -- on next block boundary. enumBlockFlush = enumErr Block -blockFlush :: Monad m => Iteratee ByteString m ()--- ^ If the enumerator is compressing it allows to finish current block. If--- the enumerator is decompressing it forces to stop on next block boundary.-blockFlush = throwRecoverableErr (toException Block) (const identity)
iteratee-compress.cabal view
@@ -1,11 +1,11 @@ Name: iteratee-compress-Version: 0.3.1.0-Synopsis: An enumerators for compressing and decompressing streams-Description: An enumerators for compressing and decompressing streams+Version: 0.3.2.0+Synopsis: Enumeratees for compressing and decompressing streams+Description: Enumeratees for compressing and decompressing streams License: BSD3 License-file: LICENSE Author: Maciej Piechotka-Maintainer: uzytkownik2@gmail.com+Maintainer: iteratee-compress@tsurucapital.com Copyright: 2010 (c) Maciej Piechotka Category: Codec, Data Build-type: Simple@@ -21,7 +21,7 @@ Data.Iteratee.ZLib Build-depends: base >= 4 && < 5, bytestring >= 0.9 && < 0.10,- iteratee >= 0.8.7 && < 0.9,+ iteratee >= 0.8.4 && < 0.9, mtl >= 2.0 && < 2.2 Build-tools: c2hs Extensions: CPP,@@ -33,4 +33,4 @@ Source-Repository head Type: git- Location: git://gitorious.org/iteratee-compress/iteratee-compress.git+ Location: git://github.com/tsurucapital/iteratee-compress.git