[Haskell] ANNOUNCE: Codec.Compression.GZip & .BZip

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Thu Sep 21 04:11:28 EDT 2006


I'm pleased to announce two new packages: zlib and bzlib which provide
functions for compression and decompression in the gzip and bzip2
formats:

Both provide pure functions on streams of data represented by lazy
ByteStrings:

compress, decompress :: ByteString -> ByteString

This makes it easy to use either in memory or with disk or network IO.
For example a simple gzip compression program is just:

> import qualified Data.ByteString.Lazy as ByteString
> import qualified Codec.Compression.GZip as GZip
>
> main = ByteString.interact GZip.compress

Or you could lazily read in and decompress @.gz@ file using:

> content <- fmap GZip.decompress (readFile file)

The code is available via darcs:

darcs get http://haskell.org/~duncan/zlib
darcs get http://haskell.org/~duncan/bzlib

(Note that if you are using GHC-6.5 then you'll need to edit the .cabal
file to remove the dependency on fps, since ByteStrings are provided in
the base package in GHC-6.5.)

There is API documentation too:

http://haskell.org/~duncan/zlib/docs
http://haskell.org/~duncan/bzlib/docs

Both packages are bindings to the corresponding C libs, so they depend
on those C libraries. Fortunately both zlib and bzlib2 are available on
every OS. It also means that the compression speed is as you would
expect since it's the C lib that is doing all the work.

I'm very happy to get feedback on the API, the documentation or of
course any bug reports.

Duncan



More information about the Haskell mailing list