Safe Haskell | None |
---|---|
Language | Haskell98 |
Data.Conduit.Zlib
Description
Streaming compression and decompression using conduits.
Parts of this code were taken from zlib-enum and adapted for conduits.
- compress :: (PrimMonad m, MonadThrow m) => Int -> WindowBits -> ConduitT ByteString ByteString m ()
- decompress :: (PrimMonad m, MonadThrow m) => WindowBits -> ConduitT ByteString ByteString m ()
- gzip :: (MonadThrow m, PrimMonad m) => ConduitT ByteString ByteString m ()
- ungzip :: (PrimMonad m, MonadThrow m) => ConduitT ByteString ByteString m ()
- compressFlush :: (PrimMonad m, MonadThrow m) => Int -> WindowBits -> ConduitT (Flush ByteString) (Flush ByteString) m ()
- decompressFlush :: (PrimMonad m, MonadThrow m) => WindowBits -> ConduitT (Flush ByteString) (Flush ByteString) m ()
- multiple :: Monad m => ConduitT ByteString a m () -> ConduitT ByteString a m ()
- data WindowBits :: * = WindowBits Int
- defaultWindowBits :: WindowBits
Conduits
Arguments
:: (PrimMonad m, MonadThrow m) | |
=> Int | Compression level |
-> WindowBits | Zlib parameter (see the zlib-bindings package as well as the zlib C library) |
-> ConduitT ByteString ByteString m () |
Compress (deflate) a stream of ByteString
s. The WindowBits
also control
the format (zlib vs. gzip).
Arguments
:: (PrimMonad m, MonadThrow m) | |
=> WindowBits | Zlib parameter (see the zlib-bindings package as well as the zlib C library) |
-> ConduitT ByteString ByteString m () |
Decompress (inflate) a stream of ByteString
s. For example:
sourceFile "test.z" $= decompress defaultWindowBits $$ sinkFile "test"
gzip :: (MonadThrow m, PrimMonad m) => ConduitT ByteString ByteString m () Source #
Gzip compression with default parameters.
ungzip :: (PrimMonad m, MonadThrow m) => ConduitT ByteString ByteString m () Source #
Gzip decompression with default parameters.
Flushing
Arguments
:: (PrimMonad m, MonadThrow m) | |
=> Int | Compression level |
-> WindowBits | Zlib parameter (see the zlib-bindings package as well as the zlib C library) |
-> ConduitT (Flush ByteString) (Flush ByteString) m () |
Same as compress
, but allows you to explicitly flush the stream.
Arguments
:: (PrimMonad m, MonadThrow m) | |
=> WindowBits | Zlib parameter (see the zlib-bindings package as well as the zlib C library) |
-> ConduitT (Flush ByteString) (Flush ByteString) m () |
Same as decompress
, but allows you to explicitly flush the stream.
Decompression combinators
multiple :: Monad m => ConduitT ByteString a m () -> ConduitT ByteString a m () Source #
The standard decompress
and ungzip
functions will only decompress a
single compressed entity from the stream. This combinator will exhaust the
stream completely of all individual compressed entities. This is useful for
cases where you have a concatenated archive, e.g. cat file1.gz file2.gz >
combined.gz
.
Usage:
sourceFile "combined.gz" $$ multiple ungzip =$ consume
This combinator will not fail on an empty stream. If you want to ensure that at least one compressed entity in the stream exists, consider a usage such as:
sourceFile "combined.gz" $$ (ungzip >> multiple ungzip) =$ consume
Since: 1.1.10