LZ4 Frame Format APIs - 5.2 English - 68552

AOCL API Guide (68552)

Document ID
68552
Release Date
2025-12-29
Version
5.2 English
group LZ4FRAME_API

LZ4F is a stand-alone API able to create and decode LZ4 frames conformant with specification v1.6.1 in lz4/lz4 . Generated frames are compatible with lz4 CLI, and designed to be interoperable with any system.

lz4frame.h implements LZ4 frame specification: see doc/lz4_Frame_format.md . * LZ4F also offers streaming capabilities.

lz4.h is not required when using lz4frame.h, except to extract common constants such as LZ4_VERSION_NUMBER.

Defines

LZ4F_VERSION 100#

This number can be used to check for an incompatible API breaking change.

Typedefs

typedef struct LZ4F_cctx_s LZ4F_cctx#
typedef struct LZ4F_CDict_s LZ4F_CDict#
typedef LZ4F_cctx *LZ4F_compressionContext_t#
typedef struct LZ4F_dctx_s LZ4F_dctx#
typedef LZ4F_dctx *LZ4F_decompressionContext_t#
typedef size_t LZ4F_errorCode_t#

Enums

enum LZ4F_blockChecksum_t#

Values:

enumerator LZ4F_noBlockChecksum#
enumerator LZ4F_blockChecksumEnabled#
enum LZ4F_blockMode_t#

Values:

enumerator LZ4F_blockLinked#
enumerator LZ4F_blockIndependent#
enum LZ4F_blockSizeID_t#

The larger the block size, the (slightly) better the compression ratio, though there are diminishing returns. Larger blocks also increase memory usage on both compression and decompression sides.

Values:

enumerator LZ4F_default#
enumerator LZ4F_max64KB#
enumerator LZ4F_max256KB#
enumerator LZ4F_max1MB#
enumerator LZ4F_max4MB#
enum LZ4F_contentChecksum_t#

Values:

enumerator LZ4F_noContentChecksum#
enumerator LZ4F_contentChecksumEnabled#
enum LZ4F_frameType_t#

Values:

enumerator LZ4F_frame#
enumerator LZ4F_skippableFrame#

Functions

size_t LZ4F_compressBegin(LZ4F_cctx *cctx, void *dstBuffer, size_t dstCapacity, const LZ4F_preferences_t *prefsPtr)#

will write the frame header into dstBuffer.

Parameters

Direction

Description

cctx

in

A compression context that can be employed multiple times for consecutive streaming operations.

dstBuffer

out

Destination buffer, compressed data is kept here, memory should be allocated already.

dstCapacity

in

Size of pre-allocated ‘dst’ buffer.

prefsPtr

in

An optional pointer which makes it possible to supply advanced compression instructions to streaming interface. It can be replaced by NULL, in which case, the function will assume default preferences.

Note

dstCapacity must be >= LZ4F_HEADER_SIZE_MAX bytes.

Returns:

Result

Description

Success

Number of bytes written into dstBuffer.

Failure

An error code if it fails (can be tested using LZ4F_isError()).

size_t LZ4F_compressBegin_usingCDict(LZ4F_cctx *cctx, void *dstBuffer, size_t dstCapacity, const LZ4F_CDict *cdict, const LZ4F_preferences_t *prefsPtr)#

Inits streaming dictionary compression, and writes the frame header into dstBuffer. Stable since v1.10.

Parameters

Direction

Description

cctx

in

A compression context that can be employed multiple times for consecutive streaming operations. cctx must point to a context created by LZ4F_createCompressionContext().

dstBuffer

out

Destination buffer, compressed data is kept here, memory should be allocated already.

dstCapacity

in

Size of pre-allocated ‘dst’ buffer.

cdict

in

If cdict==NULL, compress without a dictionary.

prefsPtr

in

Can provide preferences in compression with this pointer. It is optional pointer : NULL can be provided, but it’s not recommended, as it’s the only way to provide dictID in the frame header.

Note

dstCapacity must be >= LZ4F_HEADER_SIZE_MAX bytes. cdict must outlive the compression session.

Returns:

Result

Description

Success

Returns number of bytes written into dstBuffer for the header.

Failure

An error code (which can be tested using LZ4F_isError()).

size_t LZ4F_compressBegin_usingDict(LZ4F_cctx *cctx, void *dstBuffer, size_t dstCapacity, const void *dictBuffer, size_t dictSize, const LZ4F_preferences_t *prefsPtr)#

Inits dictionary compression streaming, and writes the frame header into dstBuffer. Stable since v1.10.

Parameters

Direction

Description

cctx

in

A compression context that can be employed multiple times for consecutive streaming operations. cctx must point to a context created by LZ4F_createCompressionContext().

dstBuffer

out

Destination buffer, compressed data is kept here, memory should be allocated already.

dstCapacity

in

Size of pre-allocated ‘dst’ buffer.

dictBuffer

in

Dictionary buffer.

dictSize

in

Length of dictionary buffer.

prefsPtr

in

Can provide preferences in compression with this pointer. It is optional pointer : NULL can be provided, but it’s not recommended, as it’s the only way to provide dictID in the frame header.

Note

  1. dstCapacity must be >= LZ4F_HEADER_SIZE_MAX bytes.

  2. dictBuffer must outlive the compression session.

  3. The LZ4Frame spec allows each independent block to be compressed with the dictionary, but this entry supports a more limited scenario, where only the first block uses the dictionary. This is still useful for small data, which only need one block anyway.

  4. For larger inputs, one may be more interested in LZ4F_compressFrame_usingCDict() below.

Returns:

Result

Description

Success

Number of bytes written into dstBuffer for the header.

Failure

An error code is returned, which can be tested using LZ4F_isError().

size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t *prefsPtr)#

Provides minimum dstCapacity required to guarantee success of LZ4F_compressUpdate(), given a srcSize and preferences, for a worst case scenario.

When srcSize==0, LZ4F_compressBound() provides an upper bound for LZ4F_flush() and LZ4F_compressEnd() instead.

Parameters

Direction

Description

srcSize

in

Input buffer size.

preferencesPtr

in

An optional pointer which makes it possible to supply advanced compression instructions to streaming interface. It can be replaced by NULL, in which case, the function will assume default preferences.

Note

The result is only valid for a single invocation of LZ4F_compressUpdate(). When invoking LZ4F_compressUpdate() multiple times, if the output buffer is gradually filled up instead of emptied and re-used from its start, one must check if there is enough remaining capacity before each invocation, using LZ4F_compressBound().

Returns:

is always the same for a srcSize and prefsPtr. prefsPtr is optional : when NULL is provided, preferences will be set to cover worst case scenario. tech details :

Returns:

if automatic flushing is not enabled, includes the possibility that internal buffer might already be filled by up to (blockSize-1) bytes. It also includes frame footer (ending + checksum), since it might be generated by LZ4F_compressEnd().

Returns:

doesn’t include frame header, as it was already generated by LZ4F_compressBegin().

size_t LZ4F_compressEnd(LZ4F_cctx *cctx, void *dstBuffer, size_t dstCapacity, const LZ4F_compressOptions_t *cOptPtr)#

To properly finish an LZ4 frame, invoke LZ4F_compressEnd().

It will flush whatever data remained within cctx (like LZ4_flush()) and properly finalize the frame, with an endMark and a checksum.

Parameters

Direction

Description

cctx

in

A compression context that can be employed multiple times for consecutive streaming operations.

dstBuffer

out

Destination buffer, compressed data is kept here, memory should be allocated already.

dstCapacity

in

Size of pre-allocated ‘dst’ buffer. Must be large enough to work properly, value should be >= LZ4F_compressBound(0, prefsPtr)

cOptPtr

in

is optional : NULL can be provided, in which case all options are set to default.

Note

LZ4F_compressEnd() is guaranteed to be successful when dstCapacity >= LZ4F_compressBound(0, prefsPtr). A successful call to LZ4F_compressEnd() makes cctx available again for another compression task.

Returns:

Result

Description

Success

nb of bytes written into dstBuffer, necessarily >= 4 (endMark)

Failure

An error code if it fails (can be tested using LZ4F_isError()).

size_t LZ4F_compressFrame(void *dstBuffer, size_t dstCapacity, const void *srcBuffer, size_t srcSize, const LZ4F_preferences_t *preferencesPtr)#

Compress an entire srcBuffer into a valid LZ4 frame.

The LZ4F_preferences_t structure is optional : you can provide NULL as argument. All preferences will be set to default.

Parameters

Direction

Description

dstBuffer

out

Destination buffer, compressed data is kept here, memory should be allocated already.

dstCapacity

in

Size of pre-allocated ‘dst’ buffer.

srcBuffer

in

Source buffer, the data you want to compress is copied/or pointed here.

srcSize

in

Size of srcBuffer.

preferencesPtr

in

An optional pointer which makes it possible to supply advanced compression instructions to streaming interface. It can be replaced by NULL, in which case, the function will assume default preferences.

Note

  1. dstCapacity MUST be >= LZ4F_compressFrameBound(srcSize, preferencesPtr).

  2. It’s a stateless operation (no LZ4F_cctx state needed).

  3. In order to reduce load on the allocator, LZ4F_compressFrame(), by default, uses the stack to allocate space for the compression state and some table. If this usage of the stack is too much for your application, consider compiling lz4frame.c with compile-time macro LZ4F_HEAPMODE set to 1 instead. All state allocations will use the Heap. It also means each invocation of LZ4F_compressFrame() will trigger several internal alloc/free invocations.

Returns:

Result

Description

Success

Number of bytes written into dstBuffer.

Failure

An error code if it fails (can be tested using LZ4F_isError()).

size_t LZ4F_compressFrame_usingCDict(LZ4F_cctx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const LZ4F_CDict *cdict, const LZ4F_preferences_t *preferencesPtr)#

Compress an entire srcBuffer into a valid LZ4 frame using a digested Dictionary. Stable since v1.10.

Parameters

Direction

Description

cctx

in

A compression context that can be employed multiple times for consecutive streaming operations. cctx must point to a context created by LZ4F_createCompressionContext().

dst

out

Destination buffer, compressed data is kept here, memory should be allocated already.

dstCapacity

in

Size of pre-allocated ‘dst’ buffer.

src

in

Source buffer, the data you want to compress is copied/or pointed here.

srcSize

in

Size of srcBuffer.

cdict

in

If cdict==NULL, compress without a dictionary.

preferencesPtr

in

Can provide preferences in compression with this pointer. It is optional pointer : NULL can be provided, but it’s not recommended, as it’s the only way to provide dictID in the frame header.

Note

  1. dstBuffer MUST be >= LZ4F_compressFrameBound(srcSize, preferencesPtr). If this condition is not respected, function will fail (

Returns:

an errorCode).

  1. cctx must point to a context created by LZ4F_createCompressionContext().

  2. If cdict==NULL, compress without a dictionary.

  3. For larger inputs generating multiple independent blocks, this entry point uses the dictionary for each block.

Returns:

Result

Description

Success

Returns number of bytes written into dstBuffer.

Failure

An error code if it fails (can be tested using LZ4F_isError()).

size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t *preferencesPtr)#

This function outputs the maximum possible compressed size with LZ4F_compressFrame() given srcSize and preferences.

Parameters

Direction

Description

srcSize

in

Input buffer size.

preferencesPtr

in

An optional pointer which makes it possible to supply advanced compression instructions to streaming interface. It can be replaced by NULL, in which case, the function will assume default preferences.

Note

this result is only usable with LZ4F_compressFrame(). It may also be relevant to LZ4F_compressUpdate() only if no flush() operation is ever performed.

Returns:

Returns the maximum possible compressed size with LZ4F_compressFrame() given srcSize and preferences.

int LZ4F_compressionLevel_max(void)#

Returns maximum compression level, the higher the compression level, the better the compression ratio.

Returns:

Maximum allowed compression level is returned (currently: 12).

size_t LZ4F_compressUpdate(LZ4F_cctx *cctx, void *dstBuffer, size_t dstCapacity, const void *srcBuffer, size_t srcSize, const LZ4F_compressOptions_t *cOptPtr)#

LZ4F_compressUpdate() can be called repetitively to compress as much data as necessary.

@important dstCapacity MUST be large enough to ensure operation success even in worst case situations. This value is provided by LZ4F_compressBound(). If this condition is not respected, LZ4F_compress() will fail (result is an errorCode). After an error, the state is left in a UB state, and must be re-initialized or freed. If previously an uncompressed block was written, buffered data is flushed before appending compressed data is continued.

Parameters

Direction

Description

cctx

in

A compression context that can be employed multiple times for consecutive streaming operations.

dstBuffer

out

Destination buffer, compressed data is kept here, memory should be allocated already.

dstCapacity

in

Size of pre-allocated ‘dst’ buffer. Must be large enough to work properly, value should be >= LZ4F_compressBound()

srcBuffer

in

Source buffer, the data you want to compress is copied/or pointed here.

srcSize

in

Size of srcBuffer.

cOptPtr

in

is optional : NULL can be provided, in which case all options are set to default.

Returns:

Result

Description

Success

number of bytes written into dstBuffer (it can be zero, meaning input data was just buffered).

Failure

An error code if it fails (can be tested using LZ4F_isError()).

LZ4F_CDict *LZ4F_createCDict(const void *dictBuffer, size_t dictSize)#

When compressing multiple messages / blocks using the same dictionary, it’s recommended to load it just once. Stable since v1.10.

LZ4_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay. LZ4_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only. dictBuffer can be released after LZ4_CDict creation, since its content is copied within CDict

Parameters

Direction

Description

dictBuffer

in

A dictionary used to compress multiple blocks.

dictSize

in

Length of dictBuffer.

Returns:

Result

Description

Success

Returns a dictionary unlike that pointed by dictBuffer where all the necessary varaibles are initialized.

Failure

If LZ4’s default memory allocation fails NULL is returned.

LZ4F_errorCode_t LZ4F_createCompressionContext(LZ4F_cctx **cctxPtr, unsigned version)#

Used to create compression context that can be employed multiple times for consecutive streaming operations.

The first thing to do before compression is to create a compressionContext object, which will keep track of operation state during streaming compression, this task is achieved by this function. This is achieved using LZ4F_createCompressionContext(), which takes as argument a version, and a pointer to LZ4F_cctx*, to write the resulting pointer into.

Parameters

Direction

Description

cctxPtr

in,out

a pointer of pointer to fully allocated LZ4F_cctx object, to write the resulting pointer into.

version

in

provided MUST be LZ4F_VERSION. It is intended to track potential version mismatch, notably when using DLL.

Version

provided MUST be LZ4F_VERSION. It is intended to track potential version mismatch, notably when using DLL.

Note

  1. cctxPtr MUST be != NULL.

  2. A created compression context can be employed multiple times for consecutive streaming operations.

  3. Once all streaming compression jobs are completed, the state object can be released using LZ4F_freeCompressionContext().

Returns:

Result

Description

Success

Returns LZ4F_OK_NoError on success.

Failure

Returns LZ4F_ERROR_parameter_null if cctxPtr is NULL.

Returns LZ4F_ERROR_allocation_failed if there is problem with allocation of memory.

LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_dctx **dctxPtr, unsigned version)#

Create an LZ4F_dctx object, to track all decompression operations.

The function fills @dctxPtr with the value of a pointer to an allocated and initialized LZ4F_dctx object. dctx memory can be released using LZ4F_freeDecompressionContext();

Parameters

Direction

Description

dctxPtr

in

Pointer to pointer of a LZ4F_dctx object, to track all decompression operations.

version

in

provided MUST be LZ4F_VERSION. It is intended to track potential version mismatch, notably when using DLL.

Returns:

Result

Description

Success

0 is returned if decompression has been completed fully and correctly.

Failure

An errorCode is returned on failure, which can be tested using LZ4F_isError().

size_t LZ4F_decompress(LZ4F_dctx *dctx, void *dstBuffer, size_t *dstSizePtr, const void *srcBuffer, size_t *srcSizePtr, const LZ4F_decompressOptions_t *dOptPtr)#

Call this function repetitively to regenerate data compressed in srcBuffer.

The function requires a valid dctx state. It will read up to *srcSizePtr bytes from srcBuffer, and decompress data into dstBuffer, of capacity *dstSizePtr.

The nb of bytes consumed from srcBuffer will be written into *srcSizePtr (necessarily <= original value). The nb of bytes decompressed into dstBuffer will be written into *dstSizePtr (necessarily <= original value).

The function does not necessarily read all input bytes, so always check value in *srcSizePtr. Unconsumed source data must be presented again in subsequent invocations.

dstBuffer can freely change between each consecutive function invocation. dstBuffer content will be overwritten.

After decompression a hint of how many srcSize bytes LZ4F_decompress() expects for next call. Schematically, it’s the size of the current (or remaining) compressed block + header of next block. Respecting the hint provides some small speed benefit, because it skips intermediate buffers. This is just a hint though, it’s always possible to provide any srcSize.

When provided with more bytes than necessary to decode a frame, LZ4F_decompress() will stop reading exactly at end of current frame, and return 0.

After a decompression error, the dctx context is not resumable. Use LZ4F_resetDecompressionContext() to return to clean state.

After a frame is fully decoded, dctx can be used again to decompress another frame.

Parameters

Direction

Description

dctx

in,out

LZ4F_dctx object, to track all decompression operations.

dstBuffer

out

Decompressed data is written in dstBuffer, dstBuffer can freely change between each consecutive function invocation & content inside it will be overwritten.

dstSizePtr

in,out

While calling this function “*dstSizePtr” provides the length of dstBuffer, after decompression is done nb of bytes decompressed into dstBuffer will be written into *dstSizePtr (necessarily <= original value).

srcBuffer

in

LZ4 Frame format compatible compressed input stream.

srcSizePtr

in,out

It will read up to *srcSizePtr bytes from srcBuffer and write the nb of bytes consumed from srcBuffer into *srcSizePtr (necessarily <= original value).

dOptPtr

in,out

Advanced decompression options, could be NULL in which case default options are assumed.

Note

If LZ4F_getFrameInfo() is called before LZ4F_decompress(), srcBuffer must be updated to reflect the number of bytes consumed after reading the frame header. Failure to update srcBuffer before calling LZ4F_decompress() will cause decompression failure or, even worse, successful but incorrect decompression. See the LZ4F_getFrameInfo() docs for details.

Returns:

Result

Description

Success

When a frame is fully decoded, 0 will be returned (no more data expected), if not a hint of how many srcSize bytes LZ4F_decompress() expects for next call.

Failure

If decompression failed, an error code is returned, which can be tested using LZ4F_isError().

size_t LZ4F_decompress_usingDict(LZ4F_dctx *dctxPtr, void *dstBuffer, size_t *dstSizePtr, const void *srcBuffer, size_t *srcSizePtr, const void *dict, size_t dictSize, const LZ4F_decompressOptions_t *decompressOptionsPtr)#

Same as LZ4F_decompress(), using a predefined dictionary. Stable since v1.10.

Dictionary is used “in place”, without any preprocessing. It must remain accessible throughout the entire frame decoding.

Parameters

Direction

Description

dctxPtr

in,out

LZ4F_dctx object, to track all decompression operations.

dstBuffer

out

Decompressed data is written in dstBuffer, dstBuffer can freely change between each consecutive function invocation & content inside it will be overwritten.

dstSizePtr

in,out

While calling this function “*dstSizePtr” provides the length of dstBuffer, after decompression is done nb of bytes decompressed into dstBuffer will be written into *dstSizePtr (necessarily <= original value).

srcBuffer

in

LZ4 Frame format compatible compressed input stream.

srcSizePtr

in,out

It will read up to *srcSizePtr bytes from srcBuffer and write the nb of bytes consumed from srcBuffer into *srcSizePtr (necessarily <= original value).

dict

in

A dictionary used to compress multiple blocks.

dictSize

in

Length of dict buffer.

decompressionOptionsPtr

in

Advanced decompression options, could be NULL in which case default options are assumed.

Returns:

Result

Description

Success

When a frame is fully decoded, 0 will be returned (no more data expected), if not a hint of how many srcSize bytes LZ4F_decompress_usingDict() expects for next call.

Failure

If decompression failed, an error code is returned, which can be tested using LZ4F_isError().

size_t LZ4F_flush(LZ4F_cctx *cctx, void *dstBuffer, size_t dstCapacity, const LZ4F_compressOptions_t *cOptPtr)#

When data must be generated and sent immediately, without waiting for a block to be completely filled, it’s possible to call LZ4_flush(). It will immediately compress any data buffered within cctx.

Parameters

Direction

Description

cctx

in

A compression context that can be employed multiple times for consecutive streaming operations.

dstBuffer

out

Destination buffer, compressed data is kept here, memory should be allocated already.

dstCapacity

in

Size of pre-allocated ‘dst’ buffer. Must be large enough to work properly, value should be >= LZ4F_compressBound()

cOptPtr

in

is optional : NULL can be provided, in which case all options are set to default.

Note

LZ4F_flush() is guaranteed to be successful when dstCapacity >= LZ4F_compressBound(0, prefsPtr).

Returns:

Result

Description

Success

nb of bytes written into dstBuffer (can be zero, when there is no data stored within cctx)

Failure

An error code if it fails (can be tested using LZ4F_isError()).

void LZ4F_freeCDict(LZ4F_CDict *CDict)#

Releases memory occupied by LZ4F_CDict element.

Parameters

Direction

Description

CDict

in

A dictionary, ready to start future compression operations without startup delay.

Returns:

void

LZ4F_errorCode_t LZ4F_freeCompressionContext(LZ4F_cctx *cctx)#

Once all streaming compression jobs are completed, the state object can be released using this function.

Parameters

Direction

Description

cctx

in

A compression context that can be employed multiple times for consecutive streaming operations.

Returns:

Is always successful even if input is NULL pointer (do nothing), so return value can be ignored.

LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_dctx *dctx)#

dctx memory can be released using LZ4F_freeDecompressionContext();

Result of LZ4F_freeDecompressionContext() indicates current state of decompressionContext when being released. That is, it should be == 0 if decompression has been completed fully and correctly.

Parameters

Direction

Description

dctx

in

LZ4F_dctx object, to track all decompression operations.

Returns:

Result

Description

Success

0 is returned on success.

Failure

Any value not equal to 0.

const char *LZ4F_getErrorName(LZ4F_errorCode_t code)#

return error code string; for debugging

Returns:

Result

Description

Success

Returns a proper error string.

Failure

Returns a string “Unspecified error code”.

size_t LZ4F_getFrameInfo(LZ4F_dctx *dctx, LZ4F_frameInfo_t *frameInfoPtr, const void *srcBuffer, size_t *srcSizePtr)#

This function extracts frame parameters (max blockSize, dictID, etc.). Its usage is optional: user can also invoke LZ4F_decompress() directly.

Extracted information will fill an existing LZ4F_frameInfo_t structure. This can be useful for allocation and dictionary identification purposes.

LZ4F_getFrameInfo() can work in the following situations :

1) At the beginning of a new frame, before any invocation of LZ4F_decompress(). It will decode header from srcBuffer, consuming the header and starting the decoding process.

Input size must be large enough to contain the full frame header. Frame header size can be known beforehand by LZ4F_headerSize(). Frame header size is variable, but is guaranteed to be >= LZ4F_HEADER_SIZE_MIN bytes, and not more than <= LZ4F_HEADER_SIZE_MAX bytes. Hence, blindly providing LZ4F_HEADER_SIZE_MAX bytes or more will always work. It’s allowed to provide more input data than the header size, LZ4F_getFrameInfo() will only consume the header.

If input size is not large enough, aka if it’s smaller than header size, function will fail and return an error code.

2) After decoding has been started, it’s possible to invoke LZ4F_getFrameInfo() anytime to extract already decoded frame parameters stored within dctx.

Note that, if decoding has barely started, and not yet read enough information to decode the header, LZ4F_getFrameInfo() will fail.

The number of bytes consumed from srcBuffer will be updated in *srcSizePtr (necessarily <= original value). LZ4F_getFrameInfo() only consumes bytes when decoding has not yet started, and when decoding the header has been successful. Decompression must then resume from (srcBuffer + *srcSizePtr).

Parameters

Direction

Description

dctx

in,out

LZ4F_dctx object, to track all decompression operations.

frameInfoPtr

out

This is a pointer to an already allocated LZ4F_frameInfo_t structure where frame parameters are copied into.

srcBuffer

in

LZ4 Frame format compatible compressed input stream.

srcSizePtr

in,out

Pointer to size of src buffer.

Note

in case of error, dctx is not modified. Decoding operation can resume from beginning safely.

Note

frame parameters are copied into an already allocated LZ4F_frameInfo_t structure.

Returns:

Result

Description

Success

A hint about how many srcSize bytes LZ4F_decompress() expects for next call

Failure

An error code, which can be tested using LZ4F_isError().

unsigned LZ4F_getVersion(void)#
size_t LZ4F_headerSize(const void *src, size_t srcSize)#

v1.9.0+ Provide the header size of a frame starting at src.

srcSize must be >= LZ4F_MIN_SIZE_TO_KNOW_HEADER_LENGTH, which is enough to decode the header length.

Parameters

Direction

Description

src

in

LZ4 Frame format compatible compressed stream .

srcSize

in

Size of src buffer.

Note

Frame header size is variable, but is guaranteed to be >= LZ4F_HEADER_SIZE_MIN bytes, and <= LZ4F_HEADER_SIZE_MAX bytes.

Returns:

Result

Description

Success

Size of frame header.

Failure

or an error code, which can be tested using LZ4F_isError().

unsigned LZ4F_isError(LZ4F_errorCode_t code)#

tells when a function result is an error code

Returns:

Result

Description

Success

Return 1 if the code represents error code.

Failure

Return 0 if non-error code is passed.

void LZ4F_resetDecompressionContext(LZ4F_dctx *dctx)#

added in v1.8.0 In case of an error, the context is left in “undefined” state. In which case, it’s necessary to reset it, before re-using it.

This method can also be used to abruptly stop any unfinished decompression, and start a new one using same context resources.

Parameters

Direction

Description

dctx

out

LZ4F_dctx object, to track all decompression operations.

Warning

NULL pointer cannot be passed.

Returns:

void

struct LZ4F_compressOptions_t#

Public Members

unsigned reserved[3]#
unsigned stableSrc#
struct LZ4F_decompressOptions_t#
#include <lz4frame.h>

Advanced decompression options.

Public Members

unsigned reserved0#

idem.

unsigned reserved1#

must be set to zero for forward compatibility.

unsigned skipChecksums#

disable checksum calculation and verification, even when one is present in frame, to save CPU time. Setting this option to 1 once disables all checksums for the rest of the frame.

unsigned stableDst#

pledges that last 64KB decompressed data is present right before @dstBuffer pointer. This optimization skips internal storage operations. Once set, this pledge must remain valid up to the end of current frame.

struct LZ4F_frameInfo_t#
#include <lz4frame.h>

makes it possible to set or read frame parameters.

Structure must be first init to 0, using memset() or LZ4F_INIT_FRAMEINFO, setting all parameters to default. It’s then possible to update selectively some parameters

Public Members

LZ4F_blockChecksum_t blockChecksumFlag#
LZ4F_blockMode_t blockMode#
LZ4F_blockSizeID_t blockSizeID#
LZ4F_contentChecksum_t contentChecksumFlag#
unsigned long long contentSize#
unsigned dictID#
LZ4F_frameType_t frameType#
struct LZ4F_preferences_t#
#include <lz4frame.h>

makes it possible to supply advanced compression instructions to streaming interface.

Structure must be first init to 0, using memset() or LZ4F_INIT_PREFERENCES, setting all parameters to default. All reserved fields must be set to zero.

Public Members

unsigned autoFlush#
int compressionLevel#
unsigned favorDecSpeed#
LZ4F_frameInfo_t frameInfo#
unsigned reserved[3]#