Classes | Macros | Typedefs | Enumerations | Functions | Variables
lz4frame.c File Reference
#include "lz4frame.h"
#include "lz4.h"
#include "lz4hc.h"
#include "xxhash.h"
#include <string.h>
#include <stdlib.h>
Include dependency graph for lz4frame.c:

Go to the source code of this file.

Classes

struct  LZ4F_cctx_s
 
struct  LZ4F_CDict_s
 
struct  LZ4F_dctx_s
 

Macros

#define _1BIT   0x01
 
#define _2BITS   0x03
 
#define _3BITS   0x07
 
#define _4BITS   0x0F
 
#define _8BITS   0xFF
 
#define ALLOC(s)   malloc(s)
 
#define ALLOC_AND_ZERO(s)   calloc(1,(s))
 
#define assert(condition)   ((void)0)
 
#define DEBUGLOG(l, ...)   {} /* disabled */
 
#define FORWARD_IF_ERROR(r)   if (LZ4F_isError(r)) return (r)
 
#define FREEMEM(p)   free(p)
 
#define GB   *(1<<30)
 
#define KB   *(1<<10)
 
#define LZ4_HC_STATIC_LINKING_ONLY
 
#define LZ4_STATIC_LINKING_ONLY
 
#define LZ4F_BLOCKSIZEID_DEFAULT   LZ4F_max64KB
 
#define LZ4F_BLOCKUNCOMPRESSED_FLAG   0x80000000U
 
#define LZ4F_GENERATE_STRING(STRING)   #STRING,
 
#define LZ4F_HEAPMODE   0
 
#define LZ4F_STATIC_ASSERT(c)   { enum { LZ4F_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
 
#define LZ4F_STATIC_LINKING_ONLY
 
#define MB   *(1<<20)
 
#define MEM_INIT(p, v, s)   memset((p),(v),(s))
 
#define MIN(a, b)   ( (a) < (b) ? (a) : (b) )
 
#define RETURN_ERROR(e)   return LZ4F_returnErrorCode(LZ4F_ERROR_ ## e)
 
#define RETURN_ERROR_IF(c, e)   if (c) RETURN_ERROR(e)
 
#define XXH_STATIC_LINKING_ONLY
 

Typedefs

typedef unsigned char BYTE
 
typedef int(* compressFunc_t) (void *ctx, const char *src, char *dst, int srcSize, int dstSize, int level, const LZ4F_CDict *cdict)
 
typedef struct LZ4F_cctx_s LZ4F_cctx_t
 
typedef signed int S32
 
typedef unsigned short U16
 
typedef unsigned int U32
 
typedef unsigned long long U64
 

Enumerations

enum  dStage_t {
  dstage_getFrameHeader =0, dstage_storeFrameHeader, dstage_init, dstage_getBlockHeader,
  dstage_storeBlockHeader, dstage_copyDirect, dstage_getBlockChecksum, dstage_getCBlock,
  dstage_storeCBlock, dstage_flushOut, dstage_getSuffix, dstage_storeSuffix,
  dstage_getSFrameSize, dstage_storeSFrameSize, dstage_skipSkippable
}
 
enum  LZ4F_blockCompression_t { LZ4B_COMPRESSED, LZ4B_UNCOMPRESSED }
 
enum  LZ4F_lastBlockStatus { notDone, fromTmpBuffer, fromSrcBuffer }
 

Functions

static int ctxTypeID_to_size (int ctxTypeID)
 
static void * LZ4F_calloc (size_t s, LZ4F_CustomMem cmem)
 
size_t LZ4F_compressBegin (LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstCapacity, const LZ4F_preferences_t *preferencesPtr)
 
size_t LZ4F_compressBegin_usingCDict (LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstCapacity, const LZ4F_CDict *cdict, const LZ4F_preferences_t *preferencesPtr)
 
static int LZ4F_compressBlock (void *ctx, const char *src, char *dst, int srcSize, int dstCapacity, int level, const LZ4F_CDict *cdict)
 
static int LZ4F_compressBlock_continue (void *ctx, const char *src, char *dst, int srcSize, int dstCapacity, int level, const LZ4F_CDict *cdict)
 
static int LZ4F_compressBlockHC (void *ctx, const char *src, char *dst, int srcSize, int dstCapacity, int level, const LZ4F_CDict *cdict)
 
static int LZ4F_compressBlockHC_continue (void *ctx, const char *src, char *dst, int srcSize, int dstCapacity, int level, const LZ4F_CDict *cdict)
 
size_t LZ4F_compressBound (size_t srcSize, const LZ4F_preferences_t *preferencesPtr)
 
static size_t LZ4F_compressBound_internal (size_t srcSize, const LZ4F_preferences_t *preferencesPtr, size_t alreadyBuffered)
 
size_t LZ4F_compressEnd (LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstCapacity, const LZ4F_compressOptions_t *compressOptionsPtr)
 
size_t LZ4F_compressFrame (void *dstBuffer, size_t dstCapacity, const void *srcBuffer, size_t srcSize, const LZ4F_preferences_t *preferencesPtr)
 
size_t LZ4F_compressFrame_usingCDict (LZ4F_cctx *cctx, void *dstBuffer, size_t dstCapacity, const void *srcBuffer, size_t srcSize, const LZ4F_CDict *cdict, const LZ4F_preferences_t *preferencesPtr)
 
size_t LZ4F_compressFrameBound (size_t srcSize, const LZ4F_preferences_t *preferencesPtr)
 
int LZ4F_compressionLevel_max (void)
 
size_t LZ4F_compressUpdate (LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstCapacity, const void *srcBuffer, size_t srcSize, const LZ4F_compressOptions_t *compressOptionsPtr)
 
static size_t LZ4F_compressUpdateImpl (LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstCapacity, const void *srcBuffer, size_t srcSize, const LZ4F_compressOptions_t *compressOptionsPtr, LZ4F_blockCompression_t blockCompression)
 
LZ4F_CDict * LZ4F_createCDict (const void *dictBuffer, size_t dictSize)
 
LZ4F_CDict * LZ4F_createCDict_advanced (LZ4F_CustomMem cmem, const void *dictBuffer, size_t dictSize)
 
LZ4F_errorCode_t LZ4F_createCompressionContext (LZ4F_cctx **LZ4F_compressionContextPtr, unsigned version)
 
LZ4F_cctxLZ4F_createCompressionContext_advanced (LZ4F_CustomMem customMem, unsigned version)
 
LZ4F_errorCode_t LZ4F_createDecompressionContext (LZ4F_dctx **LZ4F_decompressionContextPtr, unsigned versionNumber)
 
LZ4F_dctxLZ4F_createDecompressionContext_advanced (LZ4F_CustomMem customMem, unsigned version)
 
static size_t LZ4F_decodeHeader (LZ4F_dctx *dctx, const void *src, size_t srcSize)
 
size_t LZ4F_decompress (LZ4F_dctx *dctx, void *dstBuffer, size_t *dstSizePtr, const void *srcBuffer, size_t *srcSizePtr, const LZ4F_decompressOptions_t *decompressOptionsPtr)
 
size_t LZ4F_decompress_usingDict (LZ4F_dctx *dctx, void *dstBuffer, size_t *dstSizePtr, const void *srcBuffer, size_t *srcSizePtr, const void *dict, size_t dictSize, const LZ4F_decompressOptions_t *decompressOptionsPtr)
 
static int LZ4F_doNotCompressBlock (void *ctx, const char *src, char *dst, int srcSize, int dstCapacity, int level, const LZ4F_CDict *cdict)
 
size_t LZ4F_flush (LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstCapacity, const LZ4F_compressOptions_t *compressOptionsPtr)
 
static void LZ4F_free (void *p, LZ4F_CustomMem cmem)
 
void LZ4F_freeCDict (LZ4F_CDict *cdict)
 
LZ4F_errorCode_t LZ4F_freeCompressionContext (LZ4F_cctx *cctxPtr)
 
LZ4F_errorCode_t LZ4F_freeDecompressionContext (LZ4F_dctx *dctx)
 
size_t LZ4F_getBlockSize (LZ4F_blockSizeID_t blockSizeID)
 
LZ4F_errorCodes LZ4F_getErrorCode (size_t functionResult)
 
const char * LZ4F_getErrorName (LZ4F_errorCode_t code)
 
LZ4F_errorCode_t LZ4F_getFrameInfo (LZ4F_dctx *dctx, LZ4F_frameInfo_t *frameInfoPtr, const void *srcBuffer, size_t *srcSizePtr)
 
unsigned LZ4F_getVersion (void)
 
static BYTE LZ4F_headerChecksum (const void *header, size_t length)
 
size_t LZ4F_headerSize (const void *src, size_t srcSize)
 
static void LZ4F_initStream (void *ctx, const LZ4F_CDict *cdict, int level, LZ4F_blockMode_t blockMode)
 
unsigned LZ4F_isError (LZ4F_errorCode_t code)
 
static int LZ4F_localSaveDict (LZ4F_cctx_t *cctxPtr)
 
static size_t LZ4F_makeBlock (void *dst, const void *src, size_t srcSize, compressFunc_t compress, void *lz4ctx, int level, const LZ4F_CDict *cdict, LZ4F_blockChecksum_t crcFlag)
 
static void * LZ4F_malloc (size_t s, LZ4F_CustomMem cmem)
 
static LZ4F_blockSizeID_t LZ4F_optimalBSID (const LZ4F_blockSizeID_t requestedBSID, const size_t srcSize)
 
static U32 LZ4F_readLE32 (const void *src)
 
static U64 LZ4F_readLE64 (const void *src)
 
void LZ4F_resetDecompressionContext (LZ4F_dctx *dctx)
 
static LZ4F_errorCode_t LZ4F_returnErrorCode (LZ4F_errorCodes code)
 
static compressFunc_t LZ4F_selectCompression (LZ4F_blockMode_t blockMode, int level, LZ4F_blockCompression_t compressMode)
 
size_t LZ4F_uncompressedUpdate (LZ4F_cctx *cctxPtr, void *dstBuffer, size_t dstCapacity, const void *srcBuffer, size_t srcSize, const LZ4F_compressOptions_t *compressOptionsPtr)
 
static void LZ4F_updateDict (LZ4F_dctx *dctx, const BYTE *dstPtr, size_t dstSize, const BYTE *dstBufferStart, unsigned withinTmp)
 
static void LZ4F_writeLE32 (void *dst, U32 value32)
 
static void LZ4F_writeLE64 (void *dst, U64 value64)
 

Variables

static const size_t BFSize = LZ4F_BLOCK_CHECKSUM_SIZE
 
static const size_t BHSize = LZ4F_BLOCK_HEADER_SIZE
 
static const LZ4F_compressOptions_t k_cOptionsNull = { 0, { 0, 0, 0 } }
 
static const char * LZ4F_errorStrings [] = { LZ4F_LIST_ERRORS(LZ4F_GENERATE_STRING) }
 
static const size_t maxFHSize = LZ4F_HEADER_SIZE_MAX
 
static const size_t minFHSize = LZ4F_HEADER_SIZE_MIN
 

Macro Definition Documentation

◆ _1BIT

#define _1BIT   0x01

Definition at line 241 of file lz4frame.c.

◆ _2BITS

#define _2BITS   0x03

Definition at line 242 of file lz4frame.c.

◆ _3BITS

#define _3BITS   0x07

Definition at line 243 of file lz4frame.c.

◆ _4BITS

#define _4BITS   0x0F

Definition at line 244 of file lz4frame.c.

◆ _8BITS

#define _8BITS   0xFF

Definition at line 245 of file lz4frame.c.

◆ ALLOC

#define ALLOC (   s)    malloc(s)

Definition at line 95 of file lz4frame.c.

◆ ALLOC_AND_ZERO

#define ALLOC_AND_ZERO (   s)    calloc(1,(s))

Definition at line 96 of file lz4frame.c.

◆ assert

#define assert (   condition)    ((void)0)

Definition at line 145 of file lz4frame.c.

◆ DEBUGLOG

#define DEBUGLOG (   l,
  ... 
)    {} /* disabled */

Definition at line 161 of file lz4frame.c.

◆ FORWARD_IF_ERROR

#define FORWARD_IF_ERROR (   r)    if (LZ4F_isError(r)) return (r)

Definition at line 319 of file lz4frame.c.

◆ FREEMEM

#define FREEMEM (   p)    free(p)

Definition at line 97 of file lz4frame.c.

◆ GB

#define GB   *(1<<30)

Definition at line 238 of file lz4frame.c.

◆ KB

#define KB   *(1<<10)

Definition at line 236 of file lz4frame.c.

◆ LZ4_HC_STATIC_LINKING_ONLY

#define LZ4_HC_STATIC_LINKING_ONLY

Definition at line 72 of file lz4frame.c.

◆ LZ4_STATIC_LINKING_ONLY

#define LZ4_STATIC_LINKING_ONLY

Definition at line 70 of file lz4frame.c.

◆ LZ4F_BLOCKSIZEID_DEFAULT

#define LZ4F_BLOCKSIZEID_DEFAULT   LZ4F_max64KB

Definition at line 248 of file lz4frame.c.

◆ LZ4F_BLOCKUNCOMPRESSED_FLAG

#define LZ4F_BLOCKUNCOMPRESSED_FLAG   0x80000000U

Definition at line 247 of file lz4frame.c.

◆ LZ4F_GENERATE_STRING

#define LZ4F_GENERATE_STRING (   STRING)    #STRING,

Definition at line 286 of file lz4frame.c.

◆ LZ4F_HEAPMODE

#define LZ4F_HEAPMODE   0

Definition at line 61 of file lz4frame.c.

◆ LZ4F_STATIC_ASSERT

#define LZ4F_STATIC_ASSERT (   c)    { enum { LZ4F_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */

Definition at line 149 of file lz4frame.c.

◆ LZ4F_STATIC_LINKING_ONLY

#define LZ4F_STATIC_LINKING_ONLY

Definition at line 68 of file lz4frame.c.

◆ MB

#define MB   *(1<<20)

Definition at line 237 of file lz4frame.c.

◆ MEM_INIT

#define MEM_INIT (   p,
  v,
  s 
)    memset((p),(v),(s))

Definition at line 90 of file lz4frame.c.

◆ MIN

#define MIN (   a,
 
)    ( (a) < (b) ? (a) : (b) )

Definition at line 339 of file lz4frame.c.

◆ RETURN_ERROR

#define RETURN_ERROR (   e)    return LZ4F_returnErrorCode(LZ4F_ERROR_ ## e)

Definition at line 315 of file lz4frame.c.

◆ RETURN_ERROR_IF

#define RETURN_ERROR_IF (   c,
 
)    if (c) RETURN_ERROR(e)

Definition at line 317 of file lz4frame.c.

◆ XXH_STATIC_LINKING_ONLY

#define XXH_STATIC_LINKING_ONLY

Definition at line 74 of file lz4frame.c.

Typedef Documentation

◆ BYTE

typedef unsigned char BYTE

Definition at line 176 of file lz4frame.c.

◆ compressFunc_t

typedef int(* compressFunc_t) (void *ctx, const char *src, char *dst, int srcSize, int dstSize, int level, const LZ4F_CDict *cdict)

Definition at line 818 of file lz4frame.c.

◆ LZ4F_cctx_t

typedef struct LZ4F_cctx_s LZ4F_cctx_t

◆ S32

typedef signed int S32

Definition at line 179 of file lz4frame.c.

◆ U16

typedef unsigned short U16

Definition at line 177 of file lz4frame.c.

◆ U32

typedef unsigned int U32

Definition at line 178 of file lz4frame.c.

◆ U64

typedef unsigned long long U64

Definition at line 180 of file lz4frame.c.

Enumeration Type Documentation

◆ dStage_t

enum dStage_t
Enumerator
dstage_getFrameHeader 
dstage_storeFrameHeader 
dstage_init 
dstage_getBlockHeader 
dstage_storeBlockHeader 
dstage_copyDirect 
dstage_getBlockChecksum 
dstage_getCBlock 
dstage_storeCBlock 
dstage_flushOut 
dstage_getSuffix 
dstage_storeSuffix 
dstage_getSFrameSize 
dstage_storeSFrameSize 
dstage_skipSkippable 

Definition at line 1194 of file lz4frame.c.

◆ LZ4F_blockCompression_t

Enumerator
LZ4B_COMPRESSED 
LZ4B_UNCOMPRESSED 

Definition at line 260 of file lz4frame.c.

◆ LZ4F_lastBlockStatus

Enumerator
notDone 
fromTmpBuffer 
fromSrcBuffer 

Definition at line 913 of file lz4frame.c.

Function Documentation

◆ ctxTypeID_to_size()

static int ctxTypeID_to_size ( int  ctxTypeID)
static

Definition at line 660 of file lz4frame.c.

◆ LZ4F_calloc()

static void* LZ4F_calloc ( size_t  s,
LZ4F_CustomMem  cmem 
)
static

Definition at line 100 of file lz4frame.c.

◆ LZ4F_compressBegin()

size_t LZ4F_compressBegin ( LZ4F_cctx cctxPtr,
void *  dstBuffer,
size_t  dstCapacity,
const LZ4F_preferences_t preferencesPtr 
)

LZ4F_compressBegin() : init streaming compression AND writes frame header into @dstBuffer. @dstCapacity must be >= LZ4F_HEADER_SIZE_MAX bytes. @preferencesPtr can be NULL, in which case default parameters are selected.

Returns
: number of bytes written into dstBuffer for the header or an error code (can be tested using LZ4F_isError())

Definition at line 795 of file lz4frame.c.

◆ LZ4F_compressBegin_usingCDict()

size_t LZ4F_compressBegin_usingCDict ( LZ4F_cctx cctxPtr,
void *  dstBuffer,
size_t  dstCapacity,
const LZ4F_CDict *  cdict,
const LZ4F_preferences_t preferencesPtr 
)

LZ4F_compressBegin_usingCDict() : init streaming compression AND writes frame header into @dstBuffer. @dstCapacity must be >= LZ4F_HEADER_SIZE_MAX bytes.

Returns
: number of bytes written into @dstBuffer for the header or an error code (can be tested using LZ4F_isError())

Definition at line 677 of file lz4frame.c.

◆ LZ4F_compressBlock()

static int LZ4F_compressBlock ( void *  ctx,
const char *  src,
char *  dst,
int  srcSize,
int  dstCapacity,
int  level,
const LZ4F_CDict *  cdict 
)
static

Definition at line 853 of file lz4frame.c.

◆ LZ4F_compressBlock_continue()

static int LZ4F_compressBlock_continue ( void *  ctx,
const char *  src,
char *  dst,
int  srcSize,
int  dstCapacity,
int  level,
const LZ4F_CDict *  cdict 
)
static

Definition at line 865 of file lz4frame.c.

◆ LZ4F_compressBlockHC()

static int LZ4F_compressBlockHC ( void *  ctx,
const char *  src,
char *  dst,
int  srcSize,
int  dstCapacity,
int  level,
const LZ4F_CDict *  cdict 
)
static

Definition at line 873 of file lz4frame.c.

◆ LZ4F_compressBlockHC_continue()

static int LZ4F_compressBlockHC_continue ( void *  ctx,
const char *  src,
char *  dst,
int  srcSize,
int  dstCapacity,
int  level,
const LZ4F_CDict *  cdict 
)
static

Definition at line 882 of file lz4frame.c.

◆ LZ4F_compressBound()

size_t LZ4F_compressBound ( size_t  srcSize,
const LZ4F_preferences_t prefsPtr 
)

LZ4F_compressBound() : 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. Note that 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 :
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().
doesn't include frame header, as it was already generated by LZ4F_compressBegin().

Definition at line 809 of file lz4frame.c.

◆ LZ4F_compressBound_internal()

static size_t LZ4F_compressBound_internal ( size_t  srcSize,
const LZ4F_preferences_t preferencesPtr,
size_t  alreadyBuffered 
)
static

LZ4F_compressBound_internal() : Provides dstCapacity given a srcSize to guarantee operation success in worst case situations. prefsPtr is optional : if NULL is provided, preferences will be set to cover worst case scenario.

Returns
is always the same for a srcSize and prefsPtr, so it can be relied upon to size reusable buffers. When srcSize==0, LZ4F_compressBound() provides an upper bound for LZ4F_flush() and LZ4F_compressEnd() operations.

Definition at line 371 of file lz4frame.c.

◆ LZ4F_compressEnd()

size_t LZ4F_compressEnd ( LZ4F_cctx cctxPtr,
void *  dstBuffer,
size_t  dstCapacity,
const LZ4F_compressOptions_t compressOptionsPtr 
)

LZ4F_compressEnd() : When you want to properly finish the compressed frame, just call LZ4F_compressEnd(). It will flush whatever data remained within compressionContext (like LZ4_flush()) but also properly finalize the frame, with an endMark and an (optional) checksum. LZ4F_compressOptions_t structure is optional : you can provide NULL as argument.

Returns
: the number of bytes written into dstBuffer (necessarily >= 4 (endMark size)) or an error code if it fails (can be tested using LZ4F_isError()) The context can then be used again to compress a new frame, starting with LZ4F_compressBegin().

Definition at line 1151 of file lz4frame.c.

◆ LZ4F_compressFrame()

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

LZ4F_compressFrame() : Compress an entire srcBuffer into a valid LZ4 frame, in a single step. dstBuffer MUST be >= LZ4F_compressFrameBound(srcSize, preferencesPtr). The LZ4F_preferences_t structure is optional : you can provide NULL as argument. All preferences will be set to default.

Returns
: number of bytes written into dstBuffer. or an error code if it fails (can be tested using LZ4F_isError())

Definition at line 475 of file lz4frame.c.

◆ LZ4F_compressFrame_usingCDict()

size_t LZ4F_compressFrame_usingCDict ( LZ4F_cctx cctx,
void *  dstBuffer,
size_t  dstCapacity,
const void *  srcBuffer,
size_t  srcSize,
const LZ4F_CDict *  cdict,
const LZ4F_preferences_t preferencesPtr 
)

LZ4F_compressFrame_usingCDict() : Compress srcBuffer using a dictionary, in a single step. cdict can be NULL, in which case, no dictionary is used. dstBuffer MUST be >= LZ4F_compressFrameBound(srcSize, preferencesPtr). The LZ4F_preferences_t structure is optional : you may provide NULL as argument, however, it's the only way to provide a dictID, so it's not recommended.

Returns
: number of bytes written into dstBuffer, or an error code if it fails (can be tested using LZ4F_isError())

Definition at line 420 of file lz4frame.c.

◆ LZ4F_compressFrameBound()

size_t LZ4F_compressFrameBound ( size_t  srcSize,
const LZ4F_preferences_t preferencesPtr 
)

LZ4F_compressFrameBound() : Returns the maximum possible compressed size with LZ4F_compressFrame() given srcSize and preferences. preferencesPtr is optional. 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.

Definition at line 398 of file lz4frame.c.

◆ LZ4F_compressionLevel_max()

int LZ4F_compressionLevel_max ( void  )

Definition at line 323 of file lz4frame.c.

◆ LZ4F_compressUpdate()

size_t LZ4F_compressUpdate ( LZ4F_cctx cctxPtr,
void *  dstBuffer,
size_t  dstCapacity,
const void *  srcBuffer,
size_t  srcSize,
const LZ4F_compressOptions_t compressOptionsPtr 
)

LZ4F_compressUpdate() : LZ4F_compressUpdate() can be called repetitively to compress as much data as necessary. When successful, the function always entirely consumes @srcBuffer. src data is either buffered or compressed into @dstBuffer. If previously an uncompressed block was written, buffered data is flushed before appending compressed data is continued. @dstCapacity MUST be >= LZ4F_compressBound(srcSize, preferencesPtr). @compressOptionsPtr is optional : provide NULL to mean "default".

Returns
: the number of bytes written into dstBuffer. It can be zero, meaning input data was just buffered. or an error code if it fails (which can be tested using LZ4F_isError()) After an error, the state is left in a UB state, and must be re-initialized.

Definition at line 1060 of file lz4frame.c.

◆ LZ4F_compressUpdateImpl()

static size_t LZ4F_compressUpdateImpl ( LZ4F_cctx cctxPtr,
void *  dstBuffer,
size_t  dstCapacity,
const void *  srcBuffer,
size_t  srcSize,
const LZ4F_compressOptions_t compressOptionsPtr,
LZ4F_blockCompression_t  blockCompression 
)
static

LZ4F_compressUpdateImpl() : LZ4F_compressUpdate() can be called repetitively to compress as much data as necessary. When successful, the function always entirely consumes @srcBuffer. src data is either buffered or compressed into @dstBuffer. If the block compression does not match the compression of the previous block, the old data is flushed and operations continue with the new compression mode. @dstCapacity MUST be >= LZ4F_compressBound(srcSize, preferencesPtr) when block compression is turned on. @compressOptionsPtr is optional : provide NULL to mean "default".

Returns
: the number of bytes written into dstBuffer. It can be zero, meaning input data was just buffered. or an error code if it fails (which can be tested using LZ4F_isError()) After an error, the state is left in a UB state, and must be re-initialized.

Definition at line 930 of file lz4frame.c.

◆ LZ4F_createCDict()

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

LZ4F_createCDict() : When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once. LZ4F_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay. LZ4F_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only. @dictBuffer can be released after LZ4F_CDict creation, since its content is copied within CDict

Returns
: digested dictionary for compression, or NULL if failed

Definition at line 565 of file lz4frame.c.

◆ LZ4F_createCDict_advanced()

LZ4F_CDict* LZ4F_createCDict_advanced ( LZ4F_CustomMem  cmem,
const void *  dictBuffer,
size_t  dictSize 
)

Definition at line 530 of file lz4frame.c.

◆ LZ4F_createCompressionContext()

LZ4F_errorCode_t LZ4F_createCompressionContext ( LZ4F_cctx **  LZ4F_compressionContextPtr,
unsigned  version 
)

LZ4F_createCompressionContext() : The first thing to do is to create a compressionContext object, which will be used in all compression operations. This is achieved using LZ4F_createCompressionContext(), which takes as argument a version and an LZ4F_preferences_t structure. The version provided MUST be LZ4F_VERSION. It is intended to track potential incompatible differences between different binaries. The function will provide a pointer to an allocated LZ4F_compressionContext_t object. If the result LZ4F_errorCode_t is not OK_NoError, there was an error during context creation. Object can release its memory using LZ4F_freeCompressionContext();

Definition at line 608 of file lz4frame.c.

◆ LZ4F_createCompressionContext_advanced()

LZ4F_cctx* LZ4F_createCompressionContext_advanced ( LZ4F_CustomMem  customMem,
unsigned  version 
)

Definition at line 586 of file lz4frame.c.

◆ LZ4F_createDecompressionContext()

LZ4F_errorCode_t LZ4F_createDecompressionContext ( LZ4F_dctx **  LZ4F_decompressionContextPtr,
unsigned  versionNumber 
)

LZ4F_createDecompressionContext() : Create a decompressionContext object, which will track all decompression operations. Provides a pointer to a fully allocated and initialized LZ4F_decompressionContext object. Object can later be released using LZ4F_freeDecompressionContext().

Returns
: if != 0, there was an error during context creation.

Definition at line 1247 of file lz4frame.c.

◆ LZ4F_createDecompressionContext_advanced()

LZ4F_dctx* LZ4F_createDecompressionContext_advanced ( LZ4F_CustomMem  customMem,
unsigned  version 
)

Definition at line 1230 of file lz4frame.c.

◆ LZ4F_decodeHeader()

static size_t LZ4F_decodeHeader ( LZ4F_dctx dctx,
const void *  src,
size_t  srcSize 
)
static

LZ4F_decodeHeader() : input : src points at the beginning of the frame output : set internal values of dctx, such as dctx->frameInfo and dctx->dStage. Also allocates internal buffers.

Returns
: nb Bytes read from src (necessarily <= srcSize) or an error code (testable with LZ4F_isError())

Definition at line 1291 of file lz4frame.c.

◆ LZ4F_decompress()

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

LZ4F_decompress() : Call this function repetitively to regenerate compressed data in srcBuffer. The function will attempt to decode up to *srcSizePtr bytes from srcBuffer into dstBuffer of capacity *dstSizePtr.

The number of bytes regenerated into dstBuffer will be provided within *dstSizePtr (necessarily <= original value).

The number of bytes effectively read from srcBuffer will be provided within *srcSizePtr (necessarily <= original value). If number of bytes read is < number of bytes provided, then decompression operation is not complete. Remaining data will have to be presented again in a subsequent invocation.

The function result is an hint of the better srcSize to use for next call to LZ4F_decompress. Schematically, it's the size of the current (or remaining) compressed block + header of next block. Respecting the hint provides a small boost to performance, since it allows less buffer shuffling. Note that this is just a hint, and it's always possible to any srcSize value. When a frame is fully decoded,

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

Definition at line 1556 of file lz4frame.c.

◆ LZ4F_decompress_usingDict()

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

LZ4F_decompress_usingDict() : Same as LZ4F_decompress(), using a predefined dictionary. Dictionary is used "in place", without any preprocessing. It must remain accessible throughout the entire frame decoding.

Definition at line 2065 of file lz4frame.c.

◆ LZ4F_doNotCompressBlock()

static int LZ4F_doNotCompressBlock ( void *  ctx,
const char *  src,
char *  dst,
int  srcSize,
int  dstCapacity,
int  level,
const LZ4F_CDict *  cdict 
)
static

Definition at line 888 of file lz4frame.c.

◆ LZ4F_flush()

size_t LZ4F_flush ( LZ4F_cctx cctxPtr,
void *  dstBuffer,
size_t  dstCapacity,
const LZ4F_compressOptions_t compressOptionsPtr 
)

LZ4F_flush() : When compressed data must be sent immediately, without waiting for a block to be filled, invoke LZ4_flush(), which will immediately compress any remaining data stored within LZ4F_cctx. The result of the function is the number of bytes written into dstBuffer. It can be zero, this means there was no data left within LZ4F_cctx. The function outputs an error code if it fails (can be tested using LZ4F_isError()) LZ4F_compressOptions_t* is optional. NULL is a valid argument.

Definition at line 1104 of file lz4frame.c.

◆ LZ4F_free()

static void LZ4F_free ( void *  p,
LZ4F_CustomMem  cmem 
)
static

Definition at line 126 of file lz4frame.c.

◆ LZ4F_freeCDict()

void LZ4F_freeCDict ( LZ4F_CDict *  cdict)

Definition at line 571 of file lz4frame.c.

◆ LZ4F_freeCompressionContext()

LZ4F_errorCode_t LZ4F_freeCompressionContext ( LZ4F_cctx cctxPtr)

Definition at line 620 of file lz4frame.c.

◆ LZ4F_freeDecompressionContext()

LZ4F_errorCode_t LZ4F_freeDecompressionContext ( LZ4F_dctx dctx)

Definition at line 1259 of file lz4frame.c.

◆ LZ4F_getBlockSize()

size_t LZ4F_getBlockSize ( LZ4F_blockSizeID_t  blockSizeID)

Definition at line 325 of file lz4frame.c.

◆ LZ4F_getErrorCode()

LZ4F_errorCodes LZ4F_getErrorCode ( size_t  functionResult)

Definition at line 302 of file lz4frame.c.

◆ LZ4F_getErrorName()

const char* LZ4F_getErrorName ( LZ4F_errorCode_t  code)

return error code string; for debugging

Definition at line 295 of file lz4frame.c.

◆ LZ4F_getFrameInfo()

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

LZ4F_getFrameInfo() : This function extracts frame parameters (max blockSize, frame checksum, etc.). Usage is optional. Objective is to provide relevant information for allocation purposes. This function works in 2 situations :

  • At the beginning of a new frame, in which case it will decode this information from srcBuffer, and start the decoding process. Amount of input data provided must be large enough to successfully decode the frame header. A header size is variable, but is guaranteed to be <= LZ4F_HEADER_SIZE_MAX bytes. It's possible to provide more input data than this minimum.
  • After decoding has been started. In which case, no input is read, frame parameters are extracted from dctx. The number of bytes consumed from srcBuffer will be updated within *srcSizePtr (necessarily <= original value). Decompression must resume from (srcBuffer + *srcSizePtr).
    Returns
    : an hint about how many srcSize bytes LZ4F_decompress() expects for next call, or an error code which can be tested using LZ4F_isError() note 1 : in case of error, dctx is not modified. Decoding operations can resume from where they stopped. note 2 : frame parameters are copied into an already allocated LZ4F_frameInfo_t structure.

Definition at line 1428 of file lz4frame.c.

◆ LZ4F_getVersion()

unsigned LZ4F_getVersion ( void  )

Definition at line 321 of file lz4frame.c.

◆ LZ4F_headerChecksum()

static BYTE LZ4F_headerChecksum ( const void *  header,
size_t  length 
)
static

Definition at line 341 of file lz4frame.c.

◆ LZ4F_headerSize()

size_t LZ4F_headerSize ( const void *  src,
size_t  srcSize 
)

LZ4F_headerSize() :

Returns
: size of frame header or an error code, which can be tested using LZ4F_isError()

Definition at line 1387 of file lz4frame.c.

◆ LZ4F_initStream()

static void LZ4F_initStream ( void *  ctx,
const LZ4F_CDict *  cdict,
int  level,
LZ4F_blockMode_t  blockMode 
)
static

This function prepares the internal LZ4(HC) stream for a new compression, resetting the context and attaching the dictionary, if there is one.

It needs to be called at the beginning of each independent compression stream (i.e., at the beginning of a frame in blockLinked mode, or at the beginning of each block in blockIndependent mode).

Definition at line 639 of file lz4frame.c.

◆ LZ4F_isError()

unsigned LZ4F_isError ( LZ4F_errorCode_t  code)

tells when a function result is an error code

Definition at line 290 of file lz4frame.c.

◆ LZ4F_localSaveDict()

static int LZ4F_localSaveDict ( LZ4F_cctx_t cctxPtr)
static

Definition at line 906 of file lz4frame.c.

◆ LZ4F_makeBlock()

static size_t LZ4F_makeBlock ( void *  dst,
const void *  src,
size_t  srcSize,
compressFunc_t  compress,
void *  lz4ctx,
int  level,
const LZ4F_CDict *  cdict,
LZ4F_blockChecksum_t  crcFlag 
)
static

LZ4F_makeBlock(): compress a single block, add header and optional checksum. assumption : dst buffer capacity is >= BHSize + srcSize + crcSize

Definition at line 825 of file lz4frame.c.

◆ LZ4F_malloc()

static void* LZ4F_malloc ( size_t  s,
LZ4F_CustomMem  cmem 
)
static

Definition at line 116 of file lz4frame.c.

◆ LZ4F_optimalBSID()

static LZ4F_blockSizeID_t LZ4F_optimalBSID ( const LZ4F_blockSizeID_t  requestedBSID,
const size_t  srcSize 
)
static

Definition at line 351 of file lz4frame.c.

◆ LZ4F_readLE32()

static U32 LZ4F_readLE32 ( const void *  src)
static

Definition at line 185 of file lz4frame.c.

◆ LZ4F_readLE64()

static U64 LZ4F_readLE64 ( const void *  src)
static

Definition at line 204 of file lz4frame.c.

◆ LZ4F_resetDecompressionContext()

void LZ4F_resetDecompressionContext ( LZ4F_dctx dctx)

LZ4F_resetDecompressionContext() : 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.

Definition at line 1274 of file lz4frame.c.

◆ LZ4F_returnErrorCode()

static LZ4F_errorCode_t LZ4F_returnErrorCode ( LZ4F_errorCodes  code)
static

Definition at line 308 of file lz4frame.c.

◆ LZ4F_selectCompression()

static compressFunc_t LZ4F_selectCompression ( LZ4F_blockMode_t  blockMode,
int  level,
LZ4F_blockCompression_t  compressMode 
)
static

Definition at line 894 of file lz4frame.c.

◆ LZ4F_uncompressedUpdate()

size_t LZ4F_uncompressedUpdate ( LZ4F_cctx cctxPtr,
void *  dstBuffer,
size_t  dstCapacity,
const void *  srcBuffer,
size_t  srcSize,
const LZ4F_compressOptions_t compressOptionsPtr 
)

LZ4F_compressUpdate() : LZ4F_compressUpdate() can be called repetitively to compress as much data as necessary. When successful, the function always entirely consumes @srcBuffer. src data is either buffered or compressed into @dstBuffer. If previously an uncompressed block was written, buffered data is flushed before appending compressed data is continued. This is only supported when LZ4F_blockIndependent is used @dstCapacity MUST be >= LZ4F_compressBound(srcSize, preferencesPtr). @compressOptionsPtr is optional : provide NULL to mean "default".

Returns
: the number of bytes written into dstBuffer. It can be zero, meaning input data was just buffered. or an error code if it fails (which can be tested using LZ4F_isError()) After an error, the state is left in a UB state, and must be re-initialized.

Definition at line 1084 of file lz4frame.c.

◆ LZ4F_updateDict()

static void LZ4F_updateDict ( LZ4F_dctx dctx,
const BYTE dstPtr,
size_t  dstSize,
const BYTE dstBufferStart,
unsigned  withinTmp 
)
static

Definition at line 1470 of file lz4frame.c.

◆ LZ4F_writeLE32()

static void LZ4F_writeLE32 ( void *  dst,
U32  value32 
)
static

Definition at line 195 of file lz4frame.c.

◆ LZ4F_writeLE64()

static void LZ4F_writeLE64 ( void *  dst,
U64  value64 
)
static

Definition at line 218 of file lz4frame.c.

Variable Documentation

◆ BFSize

const size_t BFSize = LZ4F_BLOCK_CHECKSUM_SIZE
static

Definition at line 253 of file lz4frame.c.

◆ BHSize

const size_t BHSize = LZ4F_BLOCK_HEADER_SIZE
static

Definition at line 252 of file lz4frame.c.

◆ k_cOptionsNull

const LZ4F_compressOptions_t k_cOptionsNull = { 0, { 0, 0, 0 } }
static

Definition at line 915 of file lz4frame.c.

◆ LZ4F_errorStrings

const char* LZ4F_errorStrings[] = { LZ4F_LIST_ERRORS(LZ4F_GENERATE_STRING) }
static

Definition at line 287 of file lz4frame.c.

◆ maxFHSize

const size_t maxFHSize = LZ4F_HEADER_SIZE_MAX
static

Definition at line 251 of file lz4frame.c.

◆ minFHSize

const size_t minFHSize = LZ4F_HEADER_SIZE_MIN
static

Definition at line 250 of file lz4frame.c.



plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:49