Portability | portable |
---|---|
Stability | experimental |
Maintainer | mwotton@gmail.com |
Safe Haskell | None |
This module provides a high level ByteString
interface to the
lz4 library. More information about lz4 can be found here:
http://code.google.com/p/lz4/.
This module prefixes the buffer that is compressed with the
uncompressed length (as lz4 can't recover this information
itself.) It also has this property: all functions when
called with an empty string return Just Data.ByteString.empty
- compress :: ByteString -> Maybe ByteString
- decompress :: ByteString -> Maybe ByteString
- compressHC :: ByteString -> Maybe ByteString
- compressPlusHC :: ByteString -> Maybe ByteString
- decompressPlusHC :: ByteString -> Maybe ByteString
- c_LZ4_compress :: Ptr CChar -> Ptr Word8 -> CInt -> IO CInt
- c_LZ4_compressHC :: Ptr CChar -> Ptr Word8 -> CInt -> IO CInt
- c_LZ4_uncompress :: Ptr CChar -> Ptr Word8 -> CInt -> IO CInt
- c_LZ4_compressBound :: CInt -> CInt
High level interface
Compressing and decompressing strict ByteString
s
compress :: ByteString -> Maybe ByteStringSource
Compresses the input ByteString
.
Will return Nothing
if the compression fails. Otherwise, returns
Just xs
with the compressed string (and additionally, if xs ==
empty
then compress empty == Just empty
.)
decompress :: ByteString -> Maybe ByteStringSource
Decompress the input ByteString
.
High-compression mode
compressHC :: ByteString -> Maybe ByteStringSource
Compress the input ByteString
as much as possible, but comes
with a massive speed drop in compression. Decompression is faster
however and can be done with decompress
.
Will return Nothing
if the compression fails. Otherwise, returns
Just xs
with the compressed string (and additionally, if xs ==
empty
then compressHC empty == Just empty
.)
Compression + HC mode
compressPlusHC :: ByteString -> Maybe ByteStringSource
Essentially defined as:
compressPlusHC xs = compress xs >>= compressHC
This is an experimental interface. After regular compression, due
to output encoding, things like relative offsets in the compression
buffer or artifacts from number encoding can end up the same in the
output buffer for often repeated data. Therefore, further savings
are possible in the input buffer by compressing again. lz4 even in
high compression mode will quickly ignore already-compressed data
and remain quite fast. Thus, this interface is designed to give a
better compression/speed tradeoff than compressHC
: it doesn't
compress as well, but is nowhere near as slow. Some context:
http://www.reddit.com/r/programming/comments/vyu7r/compressing_log_files_twice_improves_ratio/c58svj3?context=3
Must be decompressed with decompressPlusHC
.
Will return Nothing
if the compression fails. Otherwise, returns
Just xs
with the compressed string (and additionally, if xs ==
empty
then compressPlusHC empty == Just empty
.)
decompressPlusHC :: ByteString -> Maybe ByteStringSource
Decompress a string compressed with compressPlusHC
. Essentially
defined as:
decompressPlusHC xs = decompress xs >>= decompress
FFI functions
Compresses a string.
Compresses a string with very high compression.
Decompresses a string. Works for both c_LZ4_compress
and
c_LZ4_compressHC
.
Worst case compression bounds on an input string.