Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed unused code, fixed 'deprecated' warning

  • Loading branch information...
commit c28fd08e35e1d1367aad82b61ab9a1fe78aa6722 1 parent 878e235
@tanimoto tanimoto authored
Showing with 12 additions and 47 deletions.
  1. +12 −47 Codec/Zlib/Enum.hs
View
59 Codec/Zlib/Enum.hs
@@ -1,37 +1,25 @@
module Codec.Zlib.Enum (
-- * Enumeratees
compress, decompress,
- -- * Re-exported from zlib-bindings
+ -- * Re-exported from zlib-bindings
WindowBits, defaultWindowBits
) where
import Codec.Zlib
import Data.Enumerator as E
+import qualified Data.Enumerator.List as EL
import Control.Monad.Trans (MonadIO, liftIO, lift)
import Data.ByteString (ByteString)
import Control.Monad (join)
-{--
-joinIO :: MonadIO m => IO (m (Step a m b)) -> Iteratee a m b
-joinIO = Iteratee . join . liftIO
-
-enumLoop :: Monad m =>
- ((Stream b -> Iteratee b m c) -> Iteratee b m c)
- -> (a -> (Stream b -> Iteratee b m c) -> Iteratee b m c)
- -> Enumeratee a b m c
-enumLoop done more = checkDone loop where
- loop k = do maybe_x <- E.head
- case maybe_x of
- Nothing -> return $$ done k
- Just x -> checkDone loop $$ more x k
---}
-- |
-- Decompress (inflate) a stream of 'ByteString's. For example:
---
+--
-- > run $ enumFile "test.z" $$ decompress defaultWindowBits $$ printChunks True
-decompress :: MonadIO m
+decompress
+ :: MonadIO m
=> WindowBits -- ^ Zlib parameter (see the zlib-bindings package as well as the zlib C library)
-> Enumeratee ByteString ByteString m a
decompress config inner = do
@@ -40,7 +28,7 @@ decompress config inner = do
decompress' :: MonadIO m => Inflate -> Enumeratee ByteString ByteString m b
decompress' inf (Continue k) = do
- x <- E.head
+ x <- EL.head
case x of
Nothing -> do
chunk <- liftIO $ finishInflate inf
@@ -49,7 +37,7 @@ decompress' inf (Continue k) = do
chunks <- liftIO $ withInflateInput inf bs $ go id
step <- lift $ runIteratee $ k $ Chunks chunks
decompress' inf step
- where
+ where
go front pop = do
x <- pop
case x of
@@ -63,8 +51,8 @@ decompress' _ step = return step
compress
:: MonadIO m
- => Int
- -> WindowBits
+ => Int -- ^ Compression level
+ -> WindowBits -- ^ Zlib parameter (see the zlib-bindings package as well as the zlib C library)
-> Enumeratee ByteString ByteString m a
compress level config inner = do
def <- liftIO $ initDeflate level config
@@ -72,7 +60,7 @@ compress level config inner = do
compress' :: MonadIO m => Deflate -> Enumeratee ByteString ByteString m b
compress' def (Continue k) = do
- x <- E.head
+ x <- EL.head
case x of
Nothing -> do
chunks <- liftIO $ finishDeflate def $ go id
@@ -81,7 +69,7 @@ compress' def (Continue k) = do
chunks <- liftIO $ withDeflateInput def bs $ go id
step <- lift $ runIteratee $ k $ Chunks chunks
compress' def step
- where
+ where
go front pop = do
x <- pop
case x of
@@ -89,29 +77,6 @@ compress' def (Continue k) = do
Just y -> go (front . (:) y) pop
compress' _ step = return step
-{--
-compress :: MonadIO m
- => Int -- ^ Compression level
- -> WindowBits -- ^ Zlib parameter (see the zlib-bindings package as well as the zlib C library)
- -> Enumeratee ByteString ByteString m a
-compress level config step0 = do
- deflate <- liftIO $ initDeflate level config
- let done k = joinIO $ finishDeflate deflate (return . callback k)
- more x k = joinIO $ withDeflateInput deflate x (return . callback k)
- enumLoop done more step0
-
--- A callback function for withInflateInput / withDeflateInput
-callback :: MonadIO m =>
- (Stream a -> Iteratee a m b) -> IO (Maybe a) -> m (Step a m b)
-
-callback k pop = runIteratee . k . Chunks =<< liftIO (go id)
- where
- go front = do
- x <- pop
- case x of
- Nothing -> return $ front []
- Just y -> go (front . (:) y)
---}
-- testInflate = do
-- h <- openBinaryFile "test-out" WriteMode
@@ -119,7 +84,7 @@ callback k pop = runIteratee . k . Chunks =<< liftIO (go id)
-- $$ decompress defaultWindowBits
-- $$ iterHandle h
-- hClose h
---
+--
-- testDeflate = do
-- h <- openBinaryFile "test.z" WriteMode
-- run $ enumFile "test"
Please sign in to comment.
Something went wrong with that request. Please try again.