Copyright | (c) 2016-present Facebook Inc. All rights reserved. |
---|---|
License | BSD3 |
Maintainer | bryano@fb.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
Mid-level bindings to the native zstd compression library. These bindings provide a little more safety and ease of use than the lowest-level FFI bindings. Unless you have highly specialized needs, you should use the streaming or other higher-level APIs instead.
Synopsis
- compress :: Ptr dst -> Int -> Ptr src -> Int -> Int -> IO (Either String Int)
- maxCLevel :: Int
- decompress :: Ptr dst -> Int -> Ptr src -> Int -> IO (Either String Int)
- getDecompressedSize :: Ptr src -> Int -> IO (Maybe Word64)
- data CCtx
- withCCtx :: (Ptr CCtx -> IO a) -> IO a
- compressCCtx :: Ptr CCtx -> Ptr dst -> Int -> Ptr src -> CSize -> Int -> IO (Either String Int)
- data DCtx
- withDCtx :: (Ptr DCtx -> IO a) -> IO a
- decompressDCtx :: Ptr DCtx -> Ptr dst -> Int -> Ptr src -> Int -> IO (Either String Int)
- data CStream
- data DStream
- data Buffer io = Buffer {}
- data In
- data Out
- cstreamInSize :: Int
- cstreamOutSize :: Int
- createCStream :: IO CStream
- initCStream :: CStream -> Int -> IO (Either String ())
- compressStream :: CStream -> Ptr (Buffer Out) -> Ptr (Buffer In) -> IO (Either String Int)
- endStream :: CStream -> Ptr (Buffer Out) -> IO (Either String Int)
- dstreamInSize :: Int
- dstreamOutSize :: Int
- createDStream :: IO DStream
- initDStream :: DStream -> IO (Either String ())
- decompressStream :: DStream -> Ptr (Buffer Out) -> Ptr (Buffer In) -> IO (Either String Int)
- trainFromBuffer :: Ptr dict -> Int -> Ptr samples -> Ptr Int -> Int -> IO (Either String Int)
- getDictID :: Ptr dict -> Int -> IO (Maybe Word)
- compressUsingDict :: Ptr CCtx -> Ptr dst -> Int -> Ptr src -> Int -> Ptr dict -> Int -> Int -> IO (Either String Int)
- decompressUsingDict :: Ptr DCtx -> Ptr dst -> Int -> Ptr src -> Int -> Ptr dict -> Int -> IO (Either String Int)
- data CDict
- createCDict :: Ptr dict -> Int -> Int -> IO CDict
- compressUsingCDict :: Ptr CCtx -> Ptr dst -> Int -> Ptr src -> Int -> CDict -> IO (Either String Int)
- data DDict
- createDDict :: Ptr dict -> Int -> IO DDict
- decompressUsingDDict :: Ptr DCtx -> Ptr dst -> Int -> Ptr src -> Int -> DDict -> IO (Either String Int)
One-shot functions
:: Ptr dst | Destination buffer. |
-> Int | Capacity of destination buffer. |
-> Ptr src | Source buffer. |
-> Int | Size of source buffer. |
-> Int | Compression level. |
-> IO (Either String Int) |
Compress bytes from source buffer into destination buffer. The destination buffer must be already allocated.
Returns the number of bytes written into destination buffer, or an error description if it fails.
:: Ptr dst | Destination buffer. |
-> Int | Capacity of destination buffer. |
-> Ptr src | Source buffer. |
-> Int | Size of compressed input. This must be exact, so for example supplying the size of a buffer that is larger than the compressed input will cause a failure. |
-> IO (Either String Int) |
Decompress a buffer. The destination buffer must be already allocated.
Returns the number of bytes written into destination buffer, or an error description if it fails.
getDecompressedSize :: Ptr src -> Int -> IO (Maybe Word64) Source #
Returns the decompressed size of a compressed payload if known.
To discover precisely why a result is not known, follow up with
getFrameParams
.
Cheaper operations using contexts
Compression
withCCtx :: (Ptr CCtx -> IO a) -> IO a Source #
Allocate a compression context, run an action that may reuse the context as many times as it needs, then free the context.
:: Ptr CCtx | Compression context. |
-> Ptr dst | Destination buffer. |
-> Int | Capacity of destination buffer. |
-> Ptr src | Source buffer. |
-> CSize | Size of source buffer. |
-> Int | Compression level. |
-> IO (Either String Int) |
Compress bytes from source buffer into destination buffer. The destination buffer must be already allocated.
Returns the number of bytes written into destination buffer, or an error description if it fails.
Decompression
withDCtx :: (Ptr DCtx -> IO a) -> IO a Source #
Allocate a decompression context, run an action that may reuse the context as many times as it needs, then free the context.
:: Ptr DCtx | Decompression context. |
-> Ptr dst | Destination buffer. |
-> Int | Capacity of destination buffer. |
-> Ptr src | Source buffer. |
-> Int | Size of compressed input. This must be exact, so for example supplying the size of a buffer that is larger than the compressed input will cause a failure. |
-> IO (Either String Int) |
Decompress a buffer. The destination buffer must be already allocated.
Returns the number of bytes written into destination buffer, or an error description if it fails.
Streaming operations
Streaming types
A streaming buffer type. The type parameter statically indicates whether the buffer is used to track an input or output buffer.
Buffer | |
|
Instances
Storable (Buffer io) Source # | |
Defined in Codec.Compression.Zstd.FFI.Types |
Streaming compression
cstreamInSize :: Int Source #
Recommended size for input buffer.
cstreamOutSize :: Int Source #
Recommended size for output buffer.
createCStream :: IO CStream Source #
Create a CStream
value. After use, this will eventually be
freed via a finalizer.
Begin a new streaming compression operation.
compressStream :: CStream -> Ptr (Buffer Out) -> Ptr (Buffer In) -> IO (Either String Int) Source #
Consume part or all of an input.
endStream :: CStream -> Ptr (Buffer Out) -> IO (Either String Int) Source #
End a compression stream. This performs a flush and writes a frame epilogue.
Streaming decompression
dstreamInSize :: Int Source #
Recommended size for input buffer.
dstreamOutSize :: Int Source #
Recommended size for output buffer.
createDStream :: IO DStream Source #
Create a streaming decompression context. After use, this will eventually be freed via a finalizer.
initDStream :: DStream -> IO (Either String ()) Source #
Begin a new streaming decompression operation.
decompressStream :: DStream -> Ptr (Buffer Out) -> Ptr (Buffer In) -> IO (Either String Int) Source #
Consume part or all of an input.
Dictionary compression
:: Ptr dict | Preallocated dictionary buffer. |
-> Int | Capacity of dictionary buffer. |
-> Ptr samples | Concatenated samples. |
-> Ptr Int | Array of sizes of samples. |
-> Int | Number of samples. |
-> IO (Either String Int) |
Train a dictionary from a collection of samples. Returns the number size of the resulting dictionary.
getDictID :: Ptr dict -> Int -> IO (Maybe Word) Source #
Return the identifier for the given dictionary, or Nothing
if
not a valid dictionary.
:: Ptr CCtx | |
-> Ptr dst | Destination buffer. |
-> Int | Capacity of destination buffer. |
-> Ptr src | Source buffer. |
-> Int | Size of source buffer. |
-> Ptr dict | Dictionary. |
-> Int | Size of dictionary. |
-> Int | Compression level. |
-> IO (Either String Int) |
Compress bytes from source buffer into destination buffer. The destination buffer must be already allocated.
Returns the number of bytes written into destination buffer, or an error description if it fails.
:: Ptr DCtx | |
-> Ptr dst | Destination buffer. |
-> Int | Capacity of destination buffer. |
-> Ptr src | Source buffer. |
-> Int | Size of compressed input. This must be exact, so for example supplying the size of a buffer that is larger than the compressed input will cause a failure. |
-> Ptr dict | Dictionary. |
-> Int | Size of dictionary. |
-> IO (Either String Int) |
Decompress a buffer. The destination buffer must be already allocated.
Returns the number of bytes written into destination buffer, or an error description if it fails.
Pre-digested dictionaries
Compression
Create a pre-digested compression dictionary. After use, this will eventually be freed via a finalizer.
:: Ptr CCtx | Compression context. |
-> Ptr dst | Destination buffer. |
-> Int | Capacity of destination buffer. |
-> Ptr src | Source buffer. |
-> Int | Size of source buffer. |
-> CDict | Dictionary. |
-> IO (Either String Int) |
Compress bytes from source buffer into destination buffer, using a pre-digested dictionary. The destination buffer must be already allocated.
Returns the number of bytes written into destination buffer, or an error description if it fails.
Decompression
Create a pre-digested decompression dictionary. After use, this will eventually be freed via a finalizer.
:: Ptr DCtx | Compression context. |
-> Ptr dst | Destination buffer. |
-> Int | Capacity of destination buffer. |
-> Ptr src | Source buffer. |
-> Int | Size of source buffer. |
-> DDict | Dictionary. |
-> IO (Either String Int) |
Decompress bytes from source buffer into destination buffer, using a pre-digested dictionary. The destination buffer must be already allocated.
Returns the number of bytes written into destination buffer, or an error description if it fails.