lzma-0.0.1.0: LZMA/XZ compression and decompression

Copyright | © 2015 Herbert Valerio Riedel
License | BSD3
Maintainer | hvr@gnu.org
Stability | experimental
Safe Haskell | Safe-Inferred
Language | Haskell2010

Codec.Compression.Lzma

Contents

- Simple (de)compression
- Extended API with control over parameters
- Monadic incremental (de)compression API
  - Compression
  - Decompression
- Parameters
  - Compression parameters
  - Decompression parameters

Description

Compression and decompression of data streams in the lzma/xz format

See also the XZ Utils home page: http://tukaani.org/xz/

Synopsis

- compress :: ByteString -> ByteString
- decompress :: ByteString -> ByteString
- compressWith :: CompressParams -> ByteString -> ByteString
- decompressWith :: DecompressParams -> ByteString -> ByteString
- data CompressStream m
  - = CompressInputRequired (m (CompressStream m)) (ByteString -> m (CompressStream m))
  - | CompressOutputAvailable !ByteString (m (CompressStream m))
  - | CompressStreamEnd
- compressIO :: CompressParams -> IO (CompressStream IO)
- compressST :: CompressParams -> ST s (CompressStream (ST s))
- data DecompressStream m
  - = DecompressInputRequired (ByteString -> m (DecompressStream m))
  - | DecompressOutputAvailable !ByteString (m (DecompressStream m))
  - | DecompressStreamEnd ByteString
  - | DecompressStreamError !LzmaRet
- decompressIO :: DecompressParams -> IO (DecompressStream IO)
- decompressST :: DecompressParams -> ST s (DecompressStream (ST s))
- data LzmaRet
  - = LzmaRetOK
  - | LzmaRetStreamEnd
  - | LzmaRetUnsupportedCheck
  - | LzmaRetGetCheck
  - | LzmaRetMemError
  - | LzmaRetMemlimitError
  - | LzmaRetFormatError
  - | LzmaRetOptionsError
  - | LzmaRetDataError
  - | LzmaRetBufError
  - | LzmaRetProgError
- defaultCompressParams :: CompressParams
- data CompressParams
- compressIntegrityCheck :: CompressParams -> IntegrityCheck
- compressLevel :: CompressParams -> CompressionLevel
- compressLevelExtreme :: CompressParams -> Bool
- compressThreads :: CompressParams -> Int
- data IntegrityCheck
  - = IntegrityCheckNone
  - | IntegrityCheckCrc32
  - | IntegrityCheckCrc64
  - | IntegrityCheckSha256
- data CompressionLevel
  - = CompressionLevel0
  - | CompressionLevel1
  - | CompressionLevel2
  - | CompressionLevel3
  - | CompressionLevel4
  - | CompressionLevel5
  - | CompressionLevel6
  - | CompressionLevel7
  - | CompressionLevel8
  - | CompressionLevel9
- defaultDecompressParams :: DecompressParams
- data DecompressParams
- decompressTellNoCheck :: DecompressParams -> Bool
- decompressTellUnsupportedCheck :: DecompressParams -> Bool
- decompressTellAnyCheck :: DecompressParams -> Bool
- decompressConcatenated :: DecompressParams -> Bool
- decompressAutoDecoder :: DecompressParams -> Bool
- decompressMemLimit :: DecompressParams -> Word64

# Simple (de)compression

compress :: ByteString -> ByteString Source #

Compress lazy `ByteString` into `.xz` format using `defaultCompressParams`.

decompress :: ByteString -> ByteString Source #

Decompress lazy `ByteString` from the `.xz` format

# Extended API with control over parameters

compressWith :: CompressParams -> ByteString -> ByteString Source #

Like `compress` but with the ability to specify various compression parameters. Typical usage:

    compressWith defaultCompressParams { compress... = ... }

decompressWith :: DecompressParams -> ByteString -> ByteString Source #

Like `decompress` but with the ability to specify various decompression parameters. Typical usage:

    decompressWith defaultDecompressParams { decompress... = ... }

# Monadic incremental (de)compression API

See zlib's incremental API documentation for more information.

## Compression

data CompressStream m Source #

Constructors

CompressInputRequired (m (CompressStream m)) (ByteString -> m (CompressStream m)) | Compression process requires input to proceed. You can either flush the stream (first field), supply an input chunk (second field), or signal the end of input (via empty chunk).
CompressOutputAvailable !ByteString (m (CompressStream m)) | Output chunk available.
CompressStreamEnd |

compressIO :: CompressParams -> IO (CompressStream IO) Source #

Incremental compression in the `IO` monad.

compressST :: CompressParams -> ST s (CompressStream (ST s)) Source #

Incremental compression in the lazy `ST` monad.

## Decompression

data DecompressStream m Source #

Constructors

DecompressInputRequired (ByteString -> m (DecompressStream m)) | Decoding process requires input to proceed. An empty `ByteString` chunk signals end of input.
DecompressOutputAvailable !ByteString (m (DecompressStream m)) | Decompressed output chunk available.
DecompressStreamEnd ByteString | Decoded stream is finished. Any unconsumed leftovers from the input stream are returned via the `ByteString` field
DecompressStreamError !LzmaRet |

decompressIO :: DecompressParams -> IO (DecompressStream IO) Source #

Incremental decompression in the `IO` monad.

decompressST :: DecompressParams -> ST s (DecompressStream (ST s)) Source #

Incremental decompression in the lazy `ST` monad.

data LzmaRet Source #

Constructors

LzmaRetOK |
LzmaRetStreamEnd |
LzmaRetUnsupportedCheck |
LzmaRetGetCheck |
LzmaRetMemError |
LzmaRetMemlimitError |
LzmaRetFormatError |
LzmaRetOptionsError |
LzmaRetDataError |
LzmaRetBufError |
LzmaRetProgError |

#### Instances

Instances details

Exception LzmaRet Source # |
Instance details Defined in LibLzma Methods toException :: LzmaRet -> SomeException Source # fromException :: SomeException -> Maybe LzmaRet Source # displayException :: LzmaRet -> String Source #
Read LzmaRet Source # |
Instance details Defined in LibLzma Methods readsPrec :: Int -> ReadS LzmaRet Source # readList :: ReadS [LzmaRet] Source # readPrec :: ReadPrec LzmaRet Source # readListPrec :: ReadPrec [LzmaRet] Source #
Show LzmaRet Source # |
Instance details Defined in LibLzma Methods showsPrec :: Int -> LzmaRet -> ShowS Source # show :: LzmaRet -> String Source # showList :: [LzmaRet] -> ShowS Source #
Eq LzmaRet Source # |
Instance details Defined in LibLzma Methods (==) :: LzmaRet -> LzmaRet -> Bool Source # (/=) :: LzmaRet -> LzmaRet -> Bool Source #
Ord LzmaRet Source # |
Instance details Defined in LibLzma Methods compare :: LzmaRet -> LzmaRet -> Ordering Source # (<) :: LzmaRet -> LzmaRet -> Bool Source # (<=) :: LzmaRet -> LzmaRet -> Bool Source # (>) :: LzmaRet -> LzmaRet -> Bool Source # (>=) :: LzmaRet -> LzmaRet -> Bool Source # max :: LzmaRet -> LzmaRet -> LzmaRet Source # min :: LzmaRet -> LzmaRet -> LzmaRet Source #

# Parameters

## Compression parameters

defaultCompressParams :: CompressParams Source #

The default set of parameters for compression. This is typically used with the `compressWith` function with specific parameters overridden.

data CompressParams Source #

Set of parameters for compression. The defaults are `defaultCompressParams`.

#### Instances

Instances details

Show CompressParams Source # |
Instance details Defined in LibLzma Methods showsPrec :: Int -> CompressParams -> ShowS Source # show :: CompressParams -> String Source # showList :: [CompressParams] -> ShowS Source #
Eq CompressParams Source # |
Instance details Defined in LibLzma Methods (==) :: CompressParams -> CompressParams -> Bool Source # (/=) :: CompressParams -> CompressParams -> Bool Source #

compressIntegrityCheck :: CompressParams -> IntegrityCheck Source #

`CompressParams` field: Specify type of integrity check

compressLevel :: CompressParams -> CompressionLevel Source #

`CompressParams` field: See documentation of `CompressionLevel`

compressLevelExtreme :: CompressParams -> Bool Source #

`CompressParams` field: Enable slower variant of the `lzmaCompLevel` preset, see `xz(1)` man-page for details.

compressThreads :: CompressParams -> Int Source #

Number of threads to use. It must be greater than zero.

Since: 0.0.1.0

data IntegrityCheck Source #

Integrity check type (only supported when compressing `.xz` files)

Constructors

IntegrityCheckNone | disable integrity check (not recommended)
IntegrityCheckCrc32 | CRC32 using the polynomial from IEEE-802.3
IntegrityCheckCrc64 | CRC64 using the polynomial from ECMA-182
IntegrityCheckSha256 | SHA-256

#### Instances

Instances details

Read IntegrityCheck Source # |
Instance details Defined in LibLzma Methods readsPrec :: Int -> ReadS IntegrityCheck Source # readList :: ReadS [IntegrityCheck] Source # readPrec :: ReadPrec IntegrityCheck Source # readListPrec :: ReadPrec [IntegrityCheck] Source #
Show IntegrityCheck Source # |
Instance details Defined in LibLzma Methods showsPrec :: Int -> IntegrityCheck -> ShowS Source # show :: IntegrityCheck -> String Source # showList :: [IntegrityCheck] -> ShowS Source #
Eq IntegrityCheck Source # |
Instance details Defined in LibLzma Methods (==) :: IntegrityCheck -> IntegrityCheck -> Bool Source # (/=) :: IntegrityCheck -> IntegrityCheck -> Bool Source #
Ord IntegrityCheck Source # |

Instance details

Defined in LibLzma

Methods

compare :: IntegrityCheck -> IntegrityCheck -> Ordering Source #

(<) :: IntegrityCheck -> IntegrityCheck -> Bool Source #

(<=) :: IntegrityCheck -> IntegrityCheck -> Bool Source #

(>) :: IntegrityCheck -> IntegrityCheck -> Bool Source #

(>=) :: IntegrityCheck -> IntegrityCheck -> Bool Source #

max :: IntegrityCheck -> IntegrityCheck -> IntegrityCheck Source #

min :: IntegrityCheck -> IntegrityCheck -> IntegrityCheck Source #

data CompressionLevel Source #

Compression level presets that define the tradeoff between computational complexity and compression ratio

`CompressionLevel0` has the lowest compression ratio as well as the lowest memory requirements, whereas `CompressionLevel9` has the highest compression ratio and can require over 600MiB during compression (and over 60MiB during decompression). The man-page for xz(1) contains more detailed information with tables describing the properties of all compression level presets.

`CompressionLevel6` is the default setting in `defaultCompressParams` as it provides a good trade-off and matches the default of the `xz(1)` tool.

Constructors

CompressionLevel0 |
CompressionLevel1 |
CompressionLevel2 |
CompressionLevel3 |
CompressionLevel4 |
CompressionLevel5 |
CompressionLevel6 |
CompressionLevel7 |
CompressionLevel8 |
CompressionLevel9 |

#### Instances

Instances details

Enum CompressionLevel Source # |

Instance details

Defined in LibLzma

Methods

succ :: CompressionLevel -> CompressionLevel Source #

pred :: CompressionLevel -> CompressionLevel Source #

toEnum :: Int -> CompressionLevel Source #

fromEnum :: CompressionLevel -> Int Source #

enumFrom :: CompressionLevel -> [CompressionLevel] Source #

enumFromThen :: CompressionLevel -> CompressionLevel -> [CompressionLevel] Source #

enumFromTo :: CompressionLevel -> CompressionLevel -> [CompressionLevel] Source #

enumFromThenTo :: CompressionLevel -> CompressionLevel -> CompressionLevel -> [CompressionLevel] Source #

Read CompressionLevel Source # |
Instance details Defined in LibLzma Methods readsPrec :: Int -> ReadS CompressionLevel Source # readList :: ReadS [CompressionLevel] Source # readPrec :: ReadPrec CompressionLevel Source # readListPrec :: ReadPrec [CompressionLevel] Source #
Show CompressionLevel Source # |
Instance details Defined in LibLzma Methods showsPrec :: Int -> CompressionLevel -> ShowS Source # show :: CompressionLevel -> String Source # showList :: [CompressionLevel] -> ShowS Source #
Eq CompressionLevel Source # |
Instance details Defined in LibLzma Methods (==) :: CompressionLevel -> CompressionLevel -> Bool Source # (/=) :: CompressionLevel -> CompressionLevel -> Bool Source #
Ord CompressionLevel Source # |

Instance details

Defined in LibLzma

Methods

compare :: CompressionLevel -> CompressionLevel -> Ordering Source #

(<) :: CompressionLevel -> CompressionLevel -> Bool Source #

(<=) :: CompressionLevel -> CompressionLevel -> Bool Source #

(>) :: CompressionLevel -> CompressionLevel -> Bool Source #

(>=) :: CompressionLevel -> CompressionLevel -> Bool Source #

max :: CompressionLevel -> CompressionLevel -> CompressionLevel Source #

min :: CompressionLevel -> CompressionLevel -> CompressionLevel Source #

## Decompression parameters

defaultDecompressParams :: DecompressParams Source #

The default set of parameters for decompression. This is typically used with the `decompressWith` function with specific parameters overridden.

data DecompressParams Source #

Set of parameters for decompression. The defaults are `defaultDecompressParams`.

#### Instances

Instances details

Show DecompressParams Source # |
Instance details Defined in LibLzma Methods showsPrec :: Int -> DecompressParams -> ShowS Source # show :: DecompressParams -> String Source # showList :: [DecompressParams] -> ShowS Source #
Eq DecompressParams Source # |
Instance details Defined in LibLzma Methods (==) :: DecompressParams -> DecompressParams -> Bool Source # (/=) :: DecompressParams -> DecompressParams -> Bool Source #

decompressTellNoCheck :: DecompressParams -> Bool Source #

`DecompressParams` field: If set, abort if decoded stream has no integrity check.

decompressTellUnsupportedCheck :: DecompressParams -> Bool Source #

`DecompressParams` field: If set, abort (via `LzmaRetGetCheck`) if decoded stream integrity check is unsupported.

decompressTellAnyCheck :: DecompressParams -> Bool Source #

`DecompressParams` field: If set, abort (via `LzmaRetGetCheck`) as soon as the type of the integrity check has been detected.

decompressConcatenated :: DecompressParams -> Bool Source #

`DecompressParams` field: If set, concatenated files as decoded seamless.

decompressAutoDecoder :: DecompressParams -> Bool Source #

`DecompressParams` field: If set, legacy `.lzma`-encoded streams are allowed too.

decompressMemLimit :: DecompressParams -> Word64 Source #

`DecompressParams` field: decompressor memory limit. Set to `maxBound` to disable memory limit.