conduit-extra-1.3.3: Batteries included conduit: adapters for common libraries.

Safe HaskellNone
LanguageHaskell98

Data.Conduit.Zlib

Contents

Description

Streaming compression and decompression using conduits.

Parts of this code were taken from zlib-enum and adapted for conduits.

Synopsis

Conduits

compress Source #

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 ByteStrings. The WindowBits also control the format (zlib vs. gzip).

decompress Source #

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 ByteStrings. 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

compressFlush Source #

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.

decompressFlush Source #

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

Re-exported from zlib-bindings

data WindowBits #

Constructors

WindowBits Int 
Instances
Eq WindowBits 
Instance details

Defined in Codec.Compression.Zlib.Stream

Methods

(==) :: WindowBits -> WindowBits -> Bool

(/=) :: WindowBits -> WindowBits -> Bool

Ord WindowBits 
Instance details

Defined in Codec.Compression.Zlib.Stream

Show WindowBits 
Instance details

Defined in Codec.Compression.Zlib.Stream

Methods

showsPrec :: Int -> WindowBits -> ShowS

show :: WindowBits -> String

showList :: [WindowBits] -> ShowS

Generic WindowBits 
Instance details

Defined in Codec.Compression.Zlib.Stream

Associated Types

type Rep WindowBits :: Type -> Type

Methods

from :: WindowBits -> Rep WindowBits x

to :: Rep WindowBits x -> WindowBits

type Rep WindowBits 
Instance details

Defined in Codec.Compression.Zlib.Stream

type Rep WindowBits = D1 (MetaData "WindowBits" "Codec.Compression.Zlib.Stream" "zlib-0.6.2-BdOecmQ0rL1HOiGypdSgxY" False) (C1 (MetaCons "WindowBits" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int)) :+: C1 (MetaCons "DefaultWindowBits" PrefixI False) (U1 :: Type -> Type))