Copyright | © 2016 Herbert Valerio Riedel |
---|---|
Maintainer | hvr@gnu.org |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Compression and decompression of data streams in the "Brotli" format (RFC7932)
Synopsis
- compress :: ByteString -> ByteString
- decompress :: ByteString -> ByteString
- newtype BrotliException = BrotliException String
- compressWith :: CompressParams -> ByteString -> ByteString
- decompressWith :: DecompressParams -> ByteString -> ByteString
- data CompressStream (m :: Type -> Type)
- = 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 :: Type -> Type)
- = DecompressInputRequired (ByteString -> m (DecompressStream m))
- | DecompressOutputAvailable !ByteString (m (DecompressStream m))
- | DecompressStreamEnd ByteString
- | DecompressStreamError !BrotliDecoderErrorCode
- decompressIO :: DecompressParams -> IO (DecompressStream IO)
- decompressST :: DecompressParams -> ST s (DecompressStream (ST s))
- newtype BrotliDecoderErrorCode = BrotliDecoderErrorCode Int
- showBrotliDecoderErrorCode :: BrotliDecoderErrorCode -> String
- defaultCompressParams :: CompressParams
- data CompressParams
- compressLevel :: CompressParams -> CompressionLevel
- compressWindowSize :: CompressParams -> CompressionWindowSize
- compressMode :: CompressParams -> CompressionMode
- compressSizeHint :: CompressParams -> Word32
- data CompressionLevel
- data CompressionWindowSize
- = CompressionWindowBits10
- | CompressionWindowBits11
- | CompressionWindowBits12
- | CompressionWindowBits13
- | CompressionWindowBits14
- | CompressionWindowBits15
- | CompressionWindowBits16
- | CompressionWindowBits17
- | CompressionWindowBits18
- | CompressionWindowBits19
- | CompressionWindowBits20
- | CompressionWindowBits21
- | CompressionWindowBits22
- | CompressionWindowBits23
- | CompressionWindowBits24
- data CompressionMode
- defaultDecompressParams :: DecompressParams
- data DecompressParams
- decompressDisableRingBufferReallocation :: DecompressParams -> Bool
Simple (de)compression with default parameters
compress :: ByteString -> ByteString Source #
Compress lazy ByteString
into Brotli stream using defaultCompressParams
.
decompress :: ByteString -> ByteString Source #
Decompress lazy ByteString
from a Brotli stream.
newtype BrotliException Source #
Exception
thrown on decoding errors or internal erros
Note that BrotliDecoderErrorCode
will be thrown instead of
BrotliException
when possible.
BrotliException String |
Instances
Exception BrotliException Source # | |
Defined in Codec.Compression.Brotli toException :: BrotliException -> SomeException fromException :: SomeException -> Maybe BrotliException displayException :: BrotliException -> String backtraceDesired :: BrotliException -> Bool | |
Show BrotliException Source # | |
Defined in Codec.Compression.Brotli showsPrec :: Int -> BrotliException -> ShowS show :: BrotliException -> String showList :: [BrotliException] -> ShowS |
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 :: Type -> Type) Source #
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 :: Type -> Type) Source #
DecompressInputRequired (ByteString -> m (DecompressStream m)) | Decoding process requires input to proceed. An empty |
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 |
DecompressStreamError !BrotliDecoderErrorCode |
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.
newtype BrotliDecoderErrorCode Source #
Errors signalled by the Brotli decoder. Use showBrotliDecoderErrorCode
to convert the numeric code into an error message.
Instances
Exception BrotliDecoderErrorCode Source # | |
Defined in LibBrotli toException :: BrotliDecoderErrorCode -> SomeException fromException :: SomeException -> Maybe BrotliDecoderErrorCode displayException :: BrotliDecoderErrorCode -> String backtraceDesired :: BrotliDecoderErrorCode -> Bool | |
Show BrotliDecoderErrorCode Source # | |
Defined in LibBrotli showsPrec :: Int -> BrotliDecoderErrorCode -> ShowS show :: BrotliDecoderErrorCode -> String showList :: [BrotliDecoderErrorCode] -> ShowS | |
Eq BrotliDecoderErrorCode Source # | |
Defined in LibBrotli (==) :: BrotliDecoderErrorCode -> BrotliDecoderErrorCode -> Bool (/=) :: BrotliDecoderErrorCode -> BrotliDecoderErrorCode -> Bool |
showBrotliDecoderErrorCode :: BrotliDecoderErrorCode -> String Source #
Convert numeric BrotliDecoderErrorCode
into textual error message.
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
.
compressLevel :: CompressParams -> CompressionLevel Source #
CompressParams
field: See documentation of CompressionLevel
compressWindowSize :: CompressParams -> CompressionWindowSize Source #
CompressParams
field: See documentation of CompressionWindowSize
compressMode :: CompressParams -> CompressionMode Source #
CompressParams
field: See documentation of CompressionMode
compressSizeHint :: CompressParams -> Word32 Source #
CompressParams
field: Estimated total input size. The default value is 0
, which means that the total input size is unknown.
data CompressionLevel Source #
Compression quality setting
CompressionLevel0 | fastest/lowest compression level |
CompressionLevel1 | |
CompressionLevel2 | |
CompressionLevel3 | |
CompressionLevel4 | |
CompressionLevel5 | |
CompressionLevel6 | |
CompressionLevel7 | |
CompressionLevel8 | |
CompressionLevel9 | |
CompressionLevel10 | |
CompressionLevel11 | slowest/highest compression level (default) |
Instances
data CompressionWindowSize Source #
Recommended sliding LZ77 window size.
The encoder may reduce this value (if e.g. input is much smaller than window size).
CompressionWindowBits10 | 1008 bytes |
CompressionWindowBits11 | 2032 bytes |
CompressionWindowBits12 | 4080 bytes |
CompressionWindowBits13 | 8176 bytes |
CompressionWindowBits14 | 16368 bytes |
CompressionWindowBits15 | 32752 bytes |
CompressionWindowBits16 | 65520 bytes |
CompressionWindowBits17 | 131056 bytes |
CompressionWindowBits18 | 262128 bytes |
CompressionWindowBits19 | 524272 bytes |
CompressionWindowBits20 | 1048560 bytes |
CompressionWindowBits21 | 2097136 bytes |
CompressionWindowBits22 | 4194288 bytes (default) |
CompressionWindowBits23 | 8388592 bytes |
CompressionWindowBits24 | 16777200 bytes |
Instances
data CompressionMode Source #
Encoding profile
CompressionModeGeneric | Format-agnostic default mode |
CompressionModeText | UTF-8 formatted text data |
CompressionModeFont | Compression mode used in WOFF 2.0 |
Instances
Read CompressionMode Source # | |
Defined in LibBrotli readsPrec :: Int -> ReadS CompressionMode readList :: ReadS [CompressionMode] readPrec :: ReadPrec CompressionMode readListPrec :: ReadPrec [CompressionMode] | |
Show CompressionMode Source # | |
Defined in LibBrotli showsPrec :: Int -> CompressionMode -> ShowS show :: CompressionMode -> String showList :: [CompressionMode] -> ShowS | |
Eq CompressionMode Source # | |
Defined in LibBrotli (==) :: CompressionMode -> CompressionMode -> Bool (/=) :: CompressionMode -> CompressionMode -> Bool |
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
.
decompressDisableRingBufferReallocation :: DecompressParams -> Bool Source #
DecompressParams
field: If True
, ring buffer is allocated according to window size, despite the real size of the content. (default: False
)