Copyright | (c) 2013 Kim Altintop <kim.altintop@gmail.com> |
---|---|
License | This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. A copy of the MPL can be found in the LICENSE file or you can obtain it at http://mozilla.org/MPL/2.0/. |
Maintainer | Kim Altintop <kim.altintop@gmail.com> |
Stability | experimental |
Portability | non-portable (GHC extensions) |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- type Checksum = Word32
- data Chunk
- type DecodeError = (ByteOffset, String)
- encode :: ByteString -> (Chunk, Maybe ByteString)
- encode' :: ByteString -> (Chunk, Maybe ByteString)
- decode :: ByteString -> (Either DecodeError Chunk, Maybe ByteString)
- decode' :: ByteString -> (Either DecodeError Chunk, Maybe ByteString)
- decodeVerify :: ByteString -> (Either DecodeError Chunk, Maybe ByteString)
- decodeVerify' :: ByteString -> (Either DecodeError Chunk, Maybe ByteString)
- decodeM :: Monad m => m (Maybe ByteString) -> m (Either DecodeError Chunk, Maybe ByteString)
- decodeVerifyM :: Monad m => m (Maybe ByteString) -> m (Either DecodeError Chunk, Maybe ByteString)
- checksum :: ByteString -> Checksum
- streamIdentifier :: ByteString
- verify :: Chunk -> Maybe Chunk
Exported Types
StreamIdentifier | |
Compressed !Checksum !ByteString | |
Uncompressed !Checksum !ByteString | |
Skippable !Word8 | |
Unskippable !Word8 |
type DecodeError = (ByteOffset, String) Source #
Encoding and Decoding
encode :: ByteString -> (Chunk, Maybe ByteString) Source #
Encode a lazy ByteString
into a Chunk
If the input is longer than minCompressible
bytes, the resulting chunk is
Compressed
otherwise Uncompressed
. If the input size exceeds
maxUncompressed
bytes, the leftover input is returned in a Just
.
encode' :: ByteString -> (Chunk, Maybe ByteString) Source #
Encode a strict ByteString
into a Chunk
If the input is longer than minCompressible
bytes, the resulting chunk is
Compressed
otherwise Uncompressed
. If the input size exceeds
maxUncompressed
bytes, the leftover input is returned in a Just
.
decode :: ByteString -> (Either DecodeError Chunk, Maybe ByteString) Source #
Decode a lazy ByteString
into a Chunk
decode' :: ByteString -> (Either DecodeError Chunk, Maybe ByteString) Source #
Decode a strict ByteString
into a Chunk
decodeVerify :: ByteString -> (Either DecodeError Chunk, Maybe ByteString) Source #
Decode a lazy ByteString
into a Chunk
and verify
the result
decodeVerify' :: ByteString -> (Either DecodeError Chunk, Maybe ByteString) Source #
Decode a strict ByteString
into a Chunk
and verify
the result
:: Monad m | |
=> m (Maybe ByteString) | And action that will be run to provide input. If it returns
|
-> m (Either DecodeError Chunk, Maybe ByteString) | Either a parse error or a |
Decode drawing input from the given monadic action as needed
decodeVerifyM :: Monad m => m (Maybe ByteString) -> m (Either DecodeError Chunk, Maybe ByteString) Source #
Utility functions
checksum :: ByteString -> Checksum Source #
Compute a masked CRC32C checksum of the input
streamIdentifier :: ByteString Source #
Yield a stream identifier (start-of-stream marker)
verify :: Chunk -> Maybe Chunk Source #
Verify a Chunk
Returns Nothing
if the input is an Unskippable
chunk, or the checksum
verification fails (if the input is a Compressed
or Uncompressed
chunk).
Otherwise, the input Chunk
is returned in a Just
. Note that Compressed
chunks are decompressed into Uncompressed
chunks on the fly.