lz4-0.2.3.1: LZ4 compression for ByteStrings

Portabilityportable
Stabilityexperimental
Maintainermwotton@gmail.com
Safe HaskellNone

Codec.Compression.LZ4

Contents

Description

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

Synopsis

High level interface

Compressing and decompressing strict ByteStrings

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

c_LZ4_compressSource

Arguments

:: Ptr CChar

Source

-> Ptr Word8

Dest

-> CInt

Input size

-> IO CInt

Result

Compresses a string.

c_LZ4_compressHCSource

Arguments

:: Ptr CChar

Source

-> Ptr Word8

Dest

-> CInt

Input size

-> IO CInt

Result

Compresses a string with very high compression.

c_LZ4_uncompressSource

Arguments

:: Ptr CChar

Source

-> Ptr Word8

Dest

-> CInt

Size of ORIGINAL INPUT

-> IO CInt

Result

Decompresses a string. Works for both c_LZ4_compress and c_LZ4_compressHC.

c_LZ4_compressBoundSource

Arguments

:: CInt

String length

-> CInt

Worst-case size

Worst case compression bounds on an input string.