Classes | Macros | Typedefs | Functions | Variables
lz4.h File Reference
#include <stddef.h>

Go to the source code of this file.

Classes

struct  LZ4_stream_t_internal
 
struct  LZ4_streamDecode_t_internal
 
union  LZ4_stream_u
 
union  LZ4_streamDecode_u
 

Macros

#define LZ4LIB_API
 
#define LZ4_VERSION_MAJOR   1 /* for breaking interface changes */
 
#define LZ4_VERSION_MINOR   7 /* for new (non-breaking) interface capabilities */
 
#define LZ4_VERSION_RELEASE   5 /* for tweaks, bug-fixes, or development */
 
#define LZ4_VERSION_NUMBER   (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
 
#define LZ4_LIB_VERSION   LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE
 
#define LZ4_QUOTE(str)   #str
 
#define LZ4_EXPAND_AND_QUOTE(str)   LZ4_QUOTE(str)
 
#define LZ4_VERSION_STRING   LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION)
 
#define LZ4_MEMORY_USAGE   14
 
#define LZ4_MAX_INPUT_SIZE   0x7E000000 /* 2 113 929 216 bytes */
 
#define LZ4_COMPRESSBOUND(isize)   ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
 
#define LZ4_HASHLOG   (LZ4_MEMORY_USAGE-2)
 
#define LZ4_HASHTABLESIZE   (1 << LZ4_MEMORY_USAGE)
 
#define LZ4_HASH_SIZE_U32   (1 << LZ4_HASHLOG) /* required as macro for static allocation */
 
#define LZ4_STREAMSIZE_U64   ((1 << (LZ4_MEMORY_USAGE-3)) + 4)
 
#define LZ4_STREAMSIZE   (LZ4_STREAMSIZE_U64 * sizeof(unsigned long long))
 
#define LZ4_STREAMDECODESIZE_U64   4
 
#define LZ4_STREAMDECODESIZE   (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long))
 
#define LZ4_GCC_VERSION   (__GNUC__ * 100 + __GNUC_MINOR__)
 
#define LZ4_DEPRECATED(message)
 

Typedefs

typedef union LZ4_stream_u LZ4_stream_t
 
typedef union LZ4_streamDecode_u LZ4_streamDecode_t
 

Functions

LZ4LIB_API int LZ4_versionNumber (void)
 
LZ4LIB_API const char * LZ4_versionString (void)
 
LZ4LIB_API int LZ4_compress_default (const char *source, char *dest, int sourceSize, int maxDestSize)
 
LZ4LIB_API int LZ4_decompress_safe (const char *source, char *dest, int compressedSize, int maxDecompressedSize)
 
LZ4LIB_API int LZ4_compressBound (int inputSize)
 
LZ4LIB_API int LZ4_compress_fast (const char *source, char *dest, int sourceSize, int maxDestSize, int acceleration)
 
LZ4LIB_API int LZ4_sizeofState (void)
 
LZ4LIB_API int LZ4_compress_fast_extState (void *state, const char *source, char *dest, int inputSize, int maxDestSize, int acceleration)
 
LZ4LIB_API int LZ4_compress_destSize (const char *source, char *dest, int *sourceSizePtr, int targetDestSize)
 
LZ4LIB_API int LZ4_decompress_fast (const char *source, char *dest, int originalSize)
 
LZ4LIB_API int LZ4_decompress_safe_partial (const char *source, char *dest, int compressedSize, int targetOutputSize, int maxDecompressedSize)
 
LZ4LIB_API LZ4_stream_tLZ4_createStream (void)
 
LZ4LIB_API int LZ4_freeStream (LZ4_stream_t *streamPtr)
 
LZ4LIB_API void LZ4_resetStream (LZ4_stream_t *streamPtr)
 
LZ4LIB_API int LZ4_loadDict (LZ4_stream_t *streamPtr, const char *dictionary, int dictSize)
 
LZ4LIB_API int LZ4_compress_fast_continue (LZ4_stream_t *streamPtr, const char *src, char *dst, int srcSize, int maxDstSize, int acceleration)
 
LZ4LIB_API int LZ4_saveDict (LZ4_stream_t *streamPtr, char *safeBuffer, int dictSize)
 
LZ4LIB_API LZ4_streamDecode_tLZ4_createStreamDecode (void)
 
LZ4LIB_API int LZ4_freeStreamDecode (LZ4_streamDecode_t *LZ4_stream)
 
LZ4LIB_API int LZ4_setStreamDecode (LZ4_streamDecode_t *LZ4_streamDecode, const char *dictionary, int dictSize)
 
LZ4LIB_API int LZ4_decompress_safe_continue (LZ4_streamDecode_t *LZ4_streamDecode, const char *source, char *dest, int compressedSize, int maxDecompressedSize)
 
LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t *LZ4_streamDecode, const char *source, char *dest, int originalSize)
 
LZ4LIB_API int LZ4_decompress_safe_usingDict (const char *source, char *dest, int compressedSize, int maxDecompressedSize, const char *dictStart, int dictSize)
 
LZ4LIB_API int LZ4_decompress_fast_usingDict (const char *source, char *dest, int originalSize, const char *dictStart, int dictSize)
 
 LZ4_DEPRECATED ("use LZ4_compress_default() instead") int LZ4_compress(const char *source
 
 LZ4_DEPRECATED ("use LZ4_compress_fast_extState() instead") int LZ4_compress_withState(void *state
 
 LZ4_DEPRECATED ("use LZ4_compress_fast_continue() instead") int LZ4_compress_continue(LZ4_stream_t *LZ4_streamPtr
 
 LZ4_DEPRECATED ("use LZ4_createStream() instead") void *LZ4_create(char *inputBuffer)
 
 LZ4_DEPRECATED ("use LZ4_resetStream() instead") int LZ4_resetStreamState(void *state
 
 LZ4_DEPRECATED ("use LZ4_saveDict() instead") char *LZ4_slideInputBuffer(void *state)
 
 LZ4_DEPRECATED ("use LZ4_decompress_safe_usingDict() instead") int LZ4_decompress_safe_withPrefix64k(const char *src
 
 LZ4_DEPRECATED ("use LZ4_decompress_fast_usingDict() instead") int LZ4_decompress_fast_withPrefix64k(const char *src
 

Variables

char * dest
 
char int sourceSize
 
char int int maxOutputSize
 
const char * source
 
const char char int inputSize
 
char * inputBuffer
 
char * dst
 
char int compressedSize
 
char int int maxDstSize
 
char int originalSize
 

Macro Definition Documentation

#define LZ4_COMPRESSBOUND (   isize)    ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)

Definition at line 149 of file lz4.h.

Referenced by LZ4_compressBound().

#define LZ4_DEPRECATED (   message)

Definition at line 429 of file lz4.h.

#define LZ4_EXPAND_AND_QUOTE (   str)    LZ4_QUOTE(str)

Definition at line 94 of file lz4.h.

#define LZ4_GCC_VERSION   (__GNUC__ * 100 + __GNUC_MINOR__)

Deprecation warnings Should deprecation warnings be a problem, it is generally possible to disable them, typically with -Wno-deprecated-declarations for gcc or _CRT_SECURE_NO_WARNINGS in Visual. Otherwise, it's also possible to define LZ4_DISABLE_DEPRECATE_WARNINGS

Definition at line 418 of file lz4.h.

#define LZ4_HASH_SIZE_U32   (1 << LZ4_HASHLOG) /* required as macro for static allocation */

Definition at line 332 of file lz4.h.

Referenced by LZ4_renormDictT().

#define LZ4_HASHLOG   (LZ4_MEMORY_USAGE-2)

Definition at line 330 of file lz4.h.

Referenced by LZ4_hash4(), and LZ4_hash5().

#define LZ4_HASHTABLESIZE   (1 << LZ4_MEMORY_USAGE)

Definition at line 331 of file lz4.h.

Definition at line 92 of file lz4.h.

#define LZ4_MAX_INPUT_SIZE   0x7E000000 /* 2 113 929 216 bytes */

Definition at line 148 of file lz4.h.

Referenced by LZ4_compress_destSize_generic(), and LZ4_compress_generic().

#define LZ4_MEMORY_USAGE   14

LZ4_MEMORY_USAGE : Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.) Increasing memory usage improves compression ratio Reduced memory usage can improve speed, due to cache effect Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache

Definition at line 112 of file lz4.h.

#define LZ4_QUOTE (   str)    #str

Definition at line 93 of file lz4.h.

#define LZ4_STREAMDECODESIZE   (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long))

Definition at line 398 of file lz4.h.

#define LZ4_STREAMDECODESIZE_U64   4

LZ4_streamDecode_t : information structure to track an LZ4 stream during decompression. init this structure using LZ4_setStreamDecode (or memset()) before first use note : only use in association with static linking ! this definition is not API/ABI safe, and may change in a future version !

Definition at line 397 of file lz4.h.

#define LZ4_STREAMSIZE   (LZ4_STREAMSIZE_U64 * sizeof(unsigned long long))

Definition at line 382 of file lz4.h.

Referenced by LZ4_createStream(), LZ4_sizeofState(), and LZ4_sizeofStreamState().

#define LZ4_STREAMSIZE_U64   ((1 << (LZ4_MEMORY_USAGE-3)) + 4)

LZ4_stream_t : information structure to track an LZ4 stream. init this structure before first use. note : only use in association with static linking ! this definition is not API/ABI safe, and may change in a future version !

Definition at line 381 of file lz4.h.

Referenced by LZ4_createStream().

#define LZ4_VERSION_MAJOR   1 /* for breaking interface changes */

Definition at line 86 of file lz4.h.

#define LZ4_VERSION_MINOR   7 /* for new (non-breaking) interface capabilities */

Definition at line 87 of file lz4.h.

#define LZ4_VERSION_NUMBER   (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)

Definition at line 90 of file lz4.h.

Referenced by LZ4_versionNumber().

#define LZ4_VERSION_RELEASE   5 /* for tweaks, bug-fixes, or development */

Definition at line 88 of file lz4.h.

#define LZ4_VERSION_STRING   LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION)

Definition at line 95 of file lz4.h.

Referenced by LZ4_versionString().

#define LZ4LIB_API

Introduction

LZ4 is lossless compression algorithm, providing compression speed at 400 MB/s per core, scalable with multi-cores CPU. It features an extremely fast decoder, with speed in multiple GB/s per core, typically reaching RAM speed limits on multi-core systems.

The LZ4 compression library provides in-memory compression and decompression functions. Compression can be done in:

  • a single step (described as Simple Functions)
  • a single step, reusing a context (described in Advanced Functions)
  • unbounded multiple steps (described as Streaming compression)

lz4.h provides block compression functions. It gives full buffer control to user. Decompressing an lz4-compressed block also requires metadata (such as compressed size). Each application is free to encode such metadata in whichever way it wants.

An additional format, called LZ4 frame specification (doc/lz4_Frame_format.md), take care of encoding standard metadata alongside LZ4-compressed blocks. If your application requires interoperability, it's recommended to use it. A library is provided to take care of it, see lz4frame.h.

Definition at line 81 of file lz4.h.

Typedef Documentation

typedef union LZ4_stream_u LZ4_stream_t

Definition at line 230 of file lz4.h.

Definition at line 276 of file lz4.h.

Function Documentation

LZ4LIB_API int LZ4_compress_default ( const char *  source,
char *  dest,
int  sourceSize,
int  maxDestSize 
)

LZ4_compress_default() : Compresses 'sourceSize' bytes from buffer 'source' into already allocated 'dest' buffer of size 'maxDestSize'. Compression is guaranteed to succeed if 'maxDestSize' >= LZ4_compressBound(sourceSize). It also runs faster, so it's a recommended setting. If the function cannot compress 'source' into a more limited 'dest' budget, compression stops immediately, and the function result is zero. As a consequence, 'dest' content is not valid. This function never writes outside 'dest' buffer, nor read outside 'source' buffer. sourceSize : Max supported value is LZ4_MAX_INPUT_VALUE maxDestSize : full or partial size of buffer 'dest' (which must be already allocated) return : the number of bytes written into buffer 'dest' (necessarily <= maxOutputSize) or 0 if compression fails

Definition at line 697 of file lz4.cxx.

References LZ4_compress_fast().

Referenced by LZ4_compress(), and LZ4_compress_limitedOutput().

698 {
700 }
char int int maxOutputSize
Definition: lz4.h:435
const char * source
Definition: lz4.h:436
int LZ4_compress_fast(const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
Definition: lz4.cxx:679
const char char int inputSize
Definition: lz4.h:436
LZ4LIB_API int LZ4_compress_destSize ( const char *  source,
char *  dest,
int sourceSizePtr,
int  targetDestSize 
)

LZ4_compress_destSize() : Reverse the logic, by compressing as much data as possible from 'source' buffer into already allocated buffer 'dest' of size 'targetDestSize'. This function either compresses the entire 'source' content into 'dest' if it's large enough, or fill 'dest' buffer completely with as much data as possible from 'source'. sourceSizePtr : will be modified to indicate how many bytes where read from 'source' to fill 'dest'. New value is necessarily <= old value. return : Nb bytes written into 'dest' (necessarily <= targetDestSize) or 0 if compression fails

Definition at line 892 of file lz4.cxx.

References ALLOCATOR, FREEMEM, LZ4_compress_destSize_extState(), and fillBadChanDBTables::result.

893 {
894 #if (HEAPMODE)
895  LZ4_stream_t* ctx = (LZ4_stream_t*)ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */
896 #else
897  LZ4_stream_t ctxBody;
898  LZ4_stream_t* ctx = &ctxBody;
899 #endif
900 
901  int result = LZ4_compress_destSize_extState(ctx, src, dst, srcSizePtr, targetDstSize);
902 
903 #if (HEAPMODE)
904  FREEMEM(ctx);
905 #endif
906  return result;
907 }
#define FREEMEM
Definition: lz4.cxx:129
#define ALLOCATOR(n, s)
Definition: lz4.cxx:128
char * dst
Definition: lz4.h:458
static int LZ4_compress_destSize_extState(LZ4_stream_t *state, const char *src, char *dst, int *srcSizePtr, int targetDstSize)
Definition: lz4.cxx:877
LZ4LIB_API int LZ4_compress_fast ( const char *  source,
char *  dest,
int  sourceSize,
int  maxDestSize,
int  acceleration 
)

LZ4_compress_fast() : Same as LZ4_compress_default(), but allows to select an "acceleration" factor. The larger the acceleration value, the faster the algorithm, but also the lesser the compression. It's a trade-off. It can be fine tuned, with each successive value providing roughly +~3% to speed. An acceleration value of "1" is the same as regular LZ4_compress_default() Values <= 0 will be replaced by ACCELERATION_DEFAULT (see lz4.c), which is 1.

Definition at line 679 of file lz4.cxx.

References ALLOCATOR, FREEMEM, LZ4_compress_fast_extState(), and fillBadChanDBTables::result.

Referenced by LZ4_compress_default().

680 {
681 #if (HEAPMODE)
682  void* ctxPtr = ALLOCATOR(1, sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */
683 #else
684  LZ4_stream_t ctx;
685  void* const ctxPtr = &ctx;
686 #endif
687 
688  int const result = LZ4_compress_fast_extState(ctxPtr, source, dest, inputSize, maxOutputSize, acceleration);
689 
690 #if (HEAPMODE)
691  FREEMEM(ctxPtr);
692 #endif
693  return result;
694 }
char int int maxOutputSize
Definition: lz4.h:435
#define FREEMEM
Definition: lz4.cxx:129
#define ALLOCATOR(n, s)
Definition: lz4.cxx:128
int LZ4_compress_fast_extState(void *state, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
Definition: lz4.cxx:659
const char * source
Definition: lz4.h:436
const char char int inputSize
Definition: lz4.h:436
LZ4LIB_API int LZ4_compress_fast_continue ( LZ4_stream_t streamPtr,
const char *  src,
char *  dst,
int  srcSize,
int  maxDstSize,
int  acceleration 
)

LZ4_compress_fast_continue() : Compress buffer content 'src', using data from previously compressed blocks as dictionary to improve compression ratio. Important : Previous data blocks are assumed to still be present and unmodified ! 'dst' buffer must be already allocated. If maxDstSize >= LZ4_compressBound(srcSize), compression is guaranteed to succeed, and runs faster. If not, and if compressed data cannot fit into 'dst' buffer size, compression stops, and function returns a zero.

Definition at line 987 of file lz4.cxx.

References ACCELERATION_DEFAULT, byU32, LZ4_stream_t_internal::currentOffset, LZ4_stream_t_internal::dictionary, LZ4_stream_t_internal::dictSize, dictSmall, LZ4_stream_t_internal::initCheck, LZ4_stream_u::internal_donotuse, KB, limitedOutput, LZ4_compress_generic(), LZ4_renormDictT(), noDictIssue, fillBadChanDBTables::result, source, usingExtDict, and withPrefix64k.

Referenced by LZ4_compress_continue(), and LZ4_compress_limitedOutput_continue().

988 {
989  LZ4_stream_t_internal* streamPtr = &LZ4_stream->internal_donotuse;
990  const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize;
991 
992  const BYTE* smallest = (const BYTE*) source;
993  if (streamPtr->initCheck) return 0; /* Uninitialized structure detected */
994  if ((streamPtr->dictSize>0) && (smallest>dictEnd)) smallest = dictEnd;
995  LZ4_renormDictT(streamPtr, smallest);
996  if (acceleration < 1) acceleration = ACCELERATION_DEFAULT;
997 
998  /* Check overlapping input/dictionary space */
999  { const BYTE* sourceEnd = (const BYTE*) source + inputSize;
1000  if ((sourceEnd > streamPtr->dictionary) && (sourceEnd < dictEnd)) {
1001  streamPtr->dictSize = (U32)(dictEnd - sourceEnd);
1002  if (streamPtr->dictSize > 64 KB) streamPtr->dictSize = 64 KB;
1003  if (streamPtr->dictSize < 4) streamPtr->dictSize = 0;
1004  streamPtr->dictionary = dictEnd - streamPtr->dictSize;
1005  }
1006  }
1007 
1008  /* prefix mode : source data follows dictionary */
1009  if (dictEnd == (const BYTE*)source) {
1010  int result;
1011  if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset))
1013  else
1015  streamPtr->dictSize += (U32)inputSize;
1016  streamPtr->currentOffset += (U32)inputSize;
1017  return result;
1018  }
1019 
1020  /* external dictionary mode */
1021  { int result;
1022  if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset))
1024  else
1026  streamPtr->dictionary = (const BYTE*)source;
1027  streamPtr->dictSize = (U32)inputSize;
1028  streamPtr->currentOffset += (U32)inputSize;
1029  return result;
1030  }
1031 }
char int int maxOutputSize
Definition: lz4.h:435
unsigned int initCheck
Definition: lz4.h:358
unsigned int currentOffset
Definition: lz4.h:357
unsigned int U32
Definition: lz4.cxx:148
static void LZ4_renormDictT(LZ4_stream_t_internal *LZ4_dict, const BYTE *src)
Definition: lz4.cxx:968
FORCE_INLINE int LZ4_compress_generic(LZ4_stream_t_internal *const cctx, const char *const source, char *const dest, const int inputSize, const int maxOutputSize, const limitedOutput_directive outputLimited, const tableType_t tableType, const dict_directive dict, const dictIssue_directive dictIssue, const U32 acceleration)
Definition: lz4.cxx:459
#define ACCELERATION_DEFAULT
Definition: lz4.cxx:52
unsigned char BYTE
Definition: lz4.cxx:146
unsigned int dictSize
Definition: lz4.h:361
LZ4_stream_t_internal internal_donotuse
Definition: lz4.h:385
const char * source
Definition: lz4.h:436
Definition: lz4.cxx:381
const char char int inputSize
Definition: lz4.h:436
const unsigned char * dictionary
Definition: lz4.h:359
#define KB
Definition: lz4.cxx:270
LZ4LIB_API int LZ4_compress_fast_extState ( void state,
const char *  source,
char *  dest,
int  inputSize,
int  maxDestSize,
int  acceleration 
)

Definition at line 659 of file lz4.cxx.

References ACCELERATION_DEFAULT, byPtr, byU16, byU32, limitedOutput, LZ4_64Klimit, LZ4_compress_generic(), LZ4_compressBound(), LZ4_resetStream(), noDict, noDictIssue, and notLimited.

Referenced by LZ4_compress_destSize_extState(), LZ4_compress_fast(), LZ4_compress_limitedOutput_withState(), and LZ4_compress_withState().

660 {
661  LZ4_stream_t_internal* ctx = &((LZ4_stream_t*)state)->internal_donotuse;
663  if (acceleration < 1) acceleration = ACCELERATION_DEFAULT;
664 
666  if (inputSize < LZ4_64Klimit)
667  return LZ4_compress_generic(ctx, source, dest, inputSize, 0, notLimited, byU16, noDict, noDictIssue, acceleration);
668  else
669  return LZ4_compress_generic(ctx, source, dest, inputSize, 0, notLimited, (sizeof(void*)==8) ? byU32 : byPtr, noDict, noDictIssue, acceleration);
670  } else {
671  if (inputSize < LZ4_64Klimit)
673  else
674  return LZ4_compress_generic(ctx, source, dest, inputSize, maxOutputSize, limitedOutput, (sizeof(void*)==8) ? byU32 : byPtr, noDict, noDictIssue, acceleration);
675  }
676 }
char int int maxOutputSize
Definition: lz4.h:435
static const int LZ4_64Klimit
Definition: lz4.cxx:373
Definition: lz4.cxx:381
FORCE_INLINE int LZ4_compress_generic(LZ4_stream_t_internal *const cctx, const char *const source, char *const dest, const int inputSize, const int maxOutputSize, const limitedOutput_directive outputLimited, const tableType_t tableType, const dict_directive dict, const dictIssue_directive dictIssue, const U32 acceleration)
Definition: lz4.cxx:459
#define ACCELERATION_DEFAULT
Definition: lz4.cxx:52
Definition: lz4.cxx:381
const char * source
Definition: lz4.h:436
Definition: lz4.cxx:381
void LZ4_resetStream(LZ4_stream_t *LZ4_stream)
Definition: lz4.cxx:923
const char char int inputSize
Definition: lz4.h:436
Definition: lz4.cxx:383
int LZ4_compressBound(int isize)
Definition: lz4.cxx:395
LZ4LIB_API int LZ4_compressBound ( int  inputSize)

LZ4_compressBound() : Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible) This function is primarily useful for memory allocation purposes (destination buffer size). Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example). Note that LZ4_compress_default() compress faster when dest buffer size is >= LZ4_compressBound(srcSize) inputSize : max supported value is LZ4_MAX_INPUT_SIZE return : maximum output size in a "worst case" scenario or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE)

Definition at line 395 of file lz4.cxx.

References LZ4_COMPRESSBOUND.

Referenced by calib::ADCShapeFitTable::ADCShapeFitTable(), LZ4_compress(), LZ4_compress_continue(), LZ4_compress_destSize_extState(), LZ4_compress_fast_extState(), LZ4_compress_HC_continue(), LZ4_compress_HC_extStateHC(), LZ4_compress_withState(), LZ4_compressHC(), LZ4_compressHC2(), LZ4_compressHC2_withStateHC(), LZ4_compressHC_continue(), and LZ4_compressHC_withStateHC().

395 { return LZ4_COMPRESSBOUND(isize); }
#define LZ4_COMPRESSBOUND(isize)
Definition: lz4.h:149
LZ4LIB_API LZ4_stream_t* LZ4_createStream ( void  )

LZ4_createStream() and LZ4_freeStream() : LZ4_createStream() will allocate and initialize an LZ4_stream_t structure. LZ4_freeStream() releases its memory.

Definition at line 915 of file lz4.cxx.

References ALLOCATOR, LZ4_resetStream(), LZ4_STATIC_ASSERT, LZ4_STREAMSIZE, and LZ4_STREAMSIZE_U64.

916 {
918  LZ4_STATIC_ASSERT(LZ4_STREAMSIZE >= sizeof(LZ4_stream_t_internal)); /* A compilation error here means LZ4_STREAMSIZE is not large enough */
919  LZ4_resetStream(lz4s);
920  return lz4s;
921 }
#define LZ4_STREAMSIZE_U64
Definition: lz4.h:381
#define ALLOCATOR(n, s)
Definition: lz4.cxx:128
#define LZ4_STREAMSIZE
Definition: lz4.h:382
void LZ4_resetStream(LZ4_stream_t *LZ4_stream)
Definition: lz4.cxx:923
#define LZ4_STATIC_ASSERT(c)
Definition: lz4.cxx:286
LZ4LIB_API LZ4_streamDecode_t* LZ4_createStreamDecode ( void  )

LZ4_createStreamDecode() and LZ4_freeStreamDecode() : creation / destruction of streaming decompression tracking structure

Definition at line 1274 of file lz4.cxx.

References ALLOCATOR.

1275 {
1277  return lz4s;
1278 }
#define ALLOCATOR(n, s)
Definition: lz4.cxx:128
LZ4LIB_API int LZ4_decompress_fast ( const char *  source,
char *  dest,
int  originalSize 
)

LZ4_decompress_fast() : originalSize : is the original and therefore uncompressed size return : the number of bytes read from the source buffer (in other words, the compressed size) If the source stream is detected malformed, the function will stop decoding and return a negative result. Destination buffer must be already allocated. Its size must be a minimum of 'originalSize' bytes. note : This function fully respect memory boundaries for properly formed compressed data. It is a bit faster than LZ4_decompress_safe(). However, it does not provide any protection against intentionally modified data stream (malicious input). Use this function in trusted environment only (data to decode comes from a trusted source).

Definition at line 1261 of file lz4.cxx.

References endOnOutputSize, full, KB, LZ4_decompress_generic(), and withPrefix64k.

Referenced by LZ4_uncompress(), and calib::ADCShapeFitTable::Table().

1262 {
1264 }
FORCE_INLINE int LZ4_decompress_generic(const char *const source, char *const dest, int inputSize, int outputSize, int endOnInput, int partialDecoding, int targetOutputSize, int dict, const BYTE *const lowPrefix, const BYTE *const dictStart, const size_t dictSize)
Definition: lz4.cxx:1089
char int originalSize
Definition: lz4.h:459
Definition: lz4.cxx:387
unsigned char BYTE
Definition: lz4.cxx:146
const char * source
Definition: lz4.h:436
#define KB
Definition: lz4.cxx:270
LZ4LIB_API int LZ4_decompress_fast_continue ( LZ4_streamDecode_t LZ4_streamDecode,
const char *  source,
char *  dest,
int  originalSize 
)

Definition at line 1336 of file lz4.cxx.

References endOnOutputSize, LZ4_streamDecode_t_internal::extDictSize, LZ4_streamDecode_t_internal::externalDict, full, LZ4_streamDecode_u::internal_donotuse, LZ4_decompress_generic(), originalSize, LZ4_streamDecode_t_internal::prefixEnd, LZ4_streamDecode_t_internal::prefixSize, fillBadChanDBTables::result, and usingExtDict.

1337 {
1338  LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse;
1339  int result;
1340 
1341  if (lz4sd->prefixEnd == (BYTE*)dest) {
1343  endOnOutputSize, full, 0,
1344  usingExtDict, lz4sd->prefixEnd - lz4sd->prefixSize, lz4sd->externalDict, lz4sd->extDictSize);
1345  if (result <= 0) return result;
1346  lz4sd->prefixSize += originalSize;
1347  lz4sd->prefixEnd += originalSize;
1348  } else {
1349  lz4sd->extDictSize = lz4sd->prefixSize;
1350  lz4sd->externalDict = lz4sd->prefixEnd - lz4sd->extDictSize;
1352  endOnOutputSize, full, 0,
1353  usingExtDict, (BYTE*)dest, lz4sd->externalDict, lz4sd->extDictSize);
1354  if (result <= 0) return result;
1355  lz4sd->prefixSize = originalSize;
1356  lz4sd->prefixEnd = (BYTE*)dest + originalSize;
1357  }
1358 
1359  return result;
1360 }
LZ4_streamDecode_t_internal internal_donotuse
Definition: lz4.h:401
const unsigned char * prefixEnd
Definition: lz4.h:367
FORCE_INLINE int LZ4_decompress_generic(const char *const source, char *const dest, int inputSize, int outputSize, int endOnInput, int partialDecoding, int targetOutputSize, int dict, const BYTE *const lowPrefix, const BYTE *const dictStart, const size_t dictSize)
Definition: lz4.cxx:1089
const unsigned char * externalDict
Definition: lz4.h:365
char int originalSize
Definition: lz4.h:459
Definition: lz4.cxx:387
unsigned char BYTE
Definition: lz4.cxx:146
const char * source
Definition: lz4.h:436
LZ4LIB_API int LZ4_decompress_fast_usingDict ( const char *  source,
char *  dest,
int  originalSize,
const char *  dictStart,
int  dictSize 
)

Definition at line 1387 of file lz4.cxx.

References LZ4_decompress_usingDict_generic().

1388 {
1389  return LZ4_decompress_usingDict_generic(source, dest, 0, originalSize, 0, dictStart, dictSize);
1390 }
char int originalSize
Definition: lz4.h:459
const char * source
Definition: lz4.h:436
FORCE_INLINE int LZ4_decompress_usingDict_generic(const char *source, char *dest, int compressedSize, int maxOutputSize, int safe, const char *dictStart, int dictSize)
Definition: lz4.cxx:1370
LZ4LIB_API int LZ4_decompress_safe ( const char *  source,
char *  dest,
int  compressedSize,
int  maxDecompressedSize 
)

LZ4_decompress_safe() : compressedSize : is the precise full size of the compressed block. maxDecompressedSize : is the size of destination buffer, which must be already allocated. return : the number of bytes decompressed into destination buffer (necessarily <= maxDecompressedSize) If destination buffer is not large enough, decoding will stop and output an error code (<0). If the source stream is detected malformed, the function will stop decoding and return a negative result. This function is protected against buffer overflow exploits, including malicious data packets. It never writes outside output buffer, nor reads outside input buffer.

Definition at line 1251 of file lz4.cxx.

References endOnInputSize, full, LZ4_decompress_generic(), and noDict.

Referenced by LZ4_uncompress_unknownOutputSize().

1252 {
1253  return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize, endOnInputSize, full, 0, noDict, (BYTE*)dest, NULL, 0);
1254 }
FORCE_INLINE int LZ4_decompress_generic(const char *const source, char *const dest, int inputSize, int outputSize, int endOnInput, int partialDecoding, int targetOutputSize, int dict, const BYTE *const lowPrefix, const BYTE *const dictStart, const size_t dictSize)
Definition: lz4.cxx:1089
char int compressedSize
Definition: lz4.h:458
Definition: lz4.cxx:387
unsigned char BYTE
Definition: lz4.cxx:146
const char * source
Definition: lz4.h:436
Definition: lz4.cxx:383
LZ4LIB_API int LZ4_decompress_safe_continue ( LZ4_streamDecode_t LZ4_streamDecode,
const char *  source,
char *  dest,
int  compressedSize,
int  maxDecompressedSize 
)

LZ4_decompress_*_continue() : These decoding functions allow decompression of multiple blocks in "streaming" mode. Previously decoded blocks must remain available at the memory position where they were decoded (up to 64 KB) In the case of a ring buffers, decoding buffer must be either :

  • Exactly same size as encoding buffer, with same update rule (block boundaries at same positions) In which case, the decoding & encoding ring buffer can have any size, including very small ones ( < 64 KB).
  • Larger than encoding buffer, by a minimum of maxBlockSize more bytes. maxBlockSize is implementation dependent. It's the maximum size you intend to compress into a single block. In which case, encoding and decoding buffers do not need to be synchronized, and encoding ring buffer can have any size, including small ones ( < 64 KB).
  • At least 64 KB + 8 bytes + maxBlockSize. In which case, encoding and decoding buffers do not need to be synchronized, and encoding ring buffer can have any size, including larger than decoding buffer. Whenever these conditions are not possible, save the last 64KB of decoded data into a safe buffer, and indicate where it is saved using LZ4_setStreamDecode()

Definition at line 1310 of file lz4.cxx.

References endOnInputSize, LZ4_streamDecode_t_internal::extDictSize, LZ4_streamDecode_t_internal::externalDict, full, LZ4_streamDecode_u::internal_donotuse, LZ4_decompress_generic(), LZ4_streamDecode_t_internal::prefixEnd, LZ4_streamDecode_t_internal::prefixSize, fillBadChanDBTables::result, and usingExtDict.

1311 {
1312  LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse;
1313  int result;
1314 
1315  if (lz4sd->prefixEnd == (BYTE*)dest) {
1317  endOnInputSize, full, 0,
1318  usingExtDict, lz4sd->prefixEnd - lz4sd->prefixSize, lz4sd->externalDict, lz4sd->extDictSize);
1319  if (result <= 0) return result;
1320  lz4sd->prefixSize += result;
1321  lz4sd->prefixEnd += result;
1322  } else {
1323  lz4sd->extDictSize = lz4sd->prefixSize;
1324  lz4sd->externalDict = lz4sd->prefixEnd - lz4sd->extDictSize;
1326  endOnInputSize, full, 0,
1327  usingExtDict, (BYTE*)dest, lz4sd->externalDict, lz4sd->extDictSize);
1328  if (result <= 0) return result;
1329  lz4sd->prefixSize = result;
1330  lz4sd->prefixEnd = (BYTE*)dest + result;
1331  }
1332 
1333  return result;
1334 }
char int int maxOutputSize
Definition: lz4.h:435
LZ4_streamDecode_t_internal internal_donotuse
Definition: lz4.h:401
const unsigned char * prefixEnd
Definition: lz4.h:367
FORCE_INLINE int LZ4_decompress_generic(const char *const source, char *const dest, int inputSize, int outputSize, int endOnInput, int partialDecoding, int targetOutputSize, int dict, const BYTE *const lowPrefix, const BYTE *const dictStart, const size_t dictSize)
Definition: lz4.cxx:1089
const unsigned char * externalDict
Definition: lz4.h:365
char int compressedSize
Definition: lz4.h:458
Definition: lz4.cxx:387
unsigned char BYTE
Definition: lz4.cxx:146
const char * source
Definition: lz4.h:436
LZ4LIB_API int LZ4_decompress_safe_partial ( const char *  source,
char *  dest,
int  compressedSize,
int  targetOutputSize,
int  maxDecompressedSize 
)

LZ4_decompress_safe_partial() : This function decompress a compressed block of size 'compressedSize' at position 'source' into destination buffer 'dest' of size 'maxDecompressedSize'. The function tries to stop decompressing operation as soon as 'targetOutputSize' has been reached, reducing decompression time. return : the number of bytes decoded in the destination buffer (necessarily <= maxDecompressedSize) Note : this number can be < 'targetOutputSize' should the compressed block to decode be smaller. Always control how many bytes were decoded. If the source stream is detected malformed, the function will stop decoding and return a negative result. This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets

Definition at line 1256 of file lz4.cxx.

References endOnInputSize, LZ4_decompress_generic(), noDict, and partial.

1257 {
1258  return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize, endOnInputSize, partial, targetOutputSize, noDict, (BYTE*)dest, NULL, 0);
1259 }
Definition: lz4.cxx:387
FORCE_INLINE int LZ4_decompress_generic(const char *const source, char *const dest, int inputSize, int outputSize, int endOnInput, int partialDecoding, int targetOutputSize, int dict, const BYTE *const lowPrefix, const BYTE *const dictStart, const size_t dictSize)
Definition: lz4.cxx:1089
char int compressedSize
Definition: lz4.h:458
unsigned char BYTE
Definition: lz4.cxx:146
const char * source
Definition: lz4.h:436
Definition: lz4.cxx:383
LZ4LIB_API int LZ4_decompress_safe_usingDict ( const char *  source,
char *  dest,
int  compressedSize,
int  maxDecompressedSize,
const char *  dictStart,
int  dictSize 
)

LZ4_decompress_*_usingDict() : These decoding functions work the same as a combination of LZ4_setStreamDecode() followed by LZ4_decompress_*_continue() They are stand-alone, and don't need an LZ4_streamDecode_t structure.

Definition at line 1382 of file lz4.cxx.

References LZ4_decompress_usingDict_generic().

1383 {
1384  return LZ4_decompress_usingDict_generic(source, dest, compressedSize, maxOutputSize, 1, dictStart, dictSize);
1385 }
char int int maxOutputSize
Definition: lz4.h:435
char int compressedSize
Definition: lz4.h:458
const char * source
Definition: lz4.h:436
FORCE_INLINE int LZ4_decompress_usingDict_generic(const char *source, char *dest, int compressedSize, int maxOutputSize, int safe, const char *dictStart, int dictSize)
Definition: lz4.cxx:1370
LZ4_DEPRECATED ( "use LZ4_compress_default() instead"  ) const
LZ4_DEPRECATED ( "use LZ4_compress_fast_extState() instead"  )
LZ4_DEPRECATED ( "use LZ4_compress_fast_continue() instead"  )
LZ4_DEPRECATED ( "use LZ4_createStream() instead"  )
LZ4_DEPRECATED ( "use LZ4_resetStream() instead"  )
LZ4_DEPRECATED ( "use LZ4_saveDict() instead"  )
LZ4_DEPRECATED ( "use LZ4_decompress_safe_usingDict() instead"  ) const
LZ4_DEPRECATED ( "use LZ4_decompress_fast_usingDict() instead"  ) const
LZ4LIB_API int LZ4_freeStream ( LZ4_stream_t streamPtr)

Definition at line 928 of file lz4.cxx.

References FREEMEM.

929 {
930  FREEMEM(LZ4_stream);
931  return (0);
932 }
#define FREEMEM
Definition: lz4.cxx:129
LZ4LIB_API int LZ4_freeStreamDecode ( LZ4_streamDecode_t LZ4_stream)

Definition at line 1280 of file lz4.cxx.

References FREEMEM.

1281 {
1282  FREEMEM(LZ4_stream);
1283  return 0;
1284 }
#define FREEMEM
Definition: lz4.cxx:129
LZ4LIB_API int LZ4_loadDict ( LZ4_stream_t streamPtr,
const char *  dictionary,
int  dictSize 
)

LZ4_loadDict() : Use this function to load a static dictionary into LZ4_stream. Any previous data will be forgotten, only 'dictionary' will remain in memory. Loading a size of 0 is allowed. Return : dictionary size, in bytes (necessarily <= 64 KB)

Definition at line 936 of file lz4.cxx.

References byU32, LZ4_stream_t_internal::currentOffset, LZ4_stream_t_internal::dictionary, LZ4_stream_t_internal::dictSize, GB, HASH_UNIT, LZ4_stream_t_internal::hashTable, LZ4_stream_t_internal::initCheck, LZ4_stream_u::internal_donotuse, KB, LZ4_putPosition(), and LZ4_resetStream().

937 {
938  LZ4_stream_t_internal* dict = &LZ4_dict->internal_donotuse;
939  const BYTE* p = (const BYTE*)dictionary;
940  const BYTE* const dictEnd = p + dictSize;
941  const BYTE* base;
942 
943  if ((dict->initCheck) || (dict->currentOffset > 1 GB)) /* Uninitialized structure, or reuse overflow */
944  LZ4_resetStream(LZ4_dict);
945 
946  if (dictSize < (int)HASH_UNIT) {
947  dict->dictionary = NULL;
948  dict->dictSize = 0;
949  return 0;
950  }
951 
952  if ((dictEnd - p) > 64 KB) p = dictEnd - 64 KB;
953  dict->currentOffset += 64 KB;
954  base = p - dict->currentOffset;
955  dict->dictionary = p;
956  dict->dictSize = (U32)(dictEnd - p);
957  dict->currentOffset += dict->dictSize;
958 
959  while (p <= dictEnd-HASH_UNIT) {
960  LZ4_putPosition(p, dict->hashTable, byU32, base);
961  p+=3;
962  }
963 
964  return dict->dictSize;
965 }
unsigned int initCheck
Definition: lz4.h:358
unsigned int currentOffset
Definition: lz4.h:357
unsigned int U32
Definition: lz4.cxx:148
const char * p
Definition: xmltok.h:285
const XML_Char int const XML_Char int const XML_Char * base
Definition: expat.h:331
unsigned int hashTable[LZ4_HASH_SIZE_U32]
Definition: lz4.h:356
unsigned char BYTE
Definition: lz4.cxx:146
unsigned int dictSize
Definition: lz4.h:361
FORCE_INLINE void LZ4_putPosition(const BYTE *p, void *tableBase, tableType_t tableType, const BYTE *srcBase)
Definition: lz4.cxx:437
#define HASH_UNIT
Definition: lz4.cxx:935
Definition: lz4.cxx:381
void LZ4_resetStream(LZ4_stream_t *LZ4_stream)
Definition: lz4.cxx:923
#define GB
Definition: lz4.cxx:272
const unsigned char * dictionary
Definition: lz4.h:359
#define KB
Definition: lz4.cxx:270
LZ4LIB_API void LZ4_resetStream ( LZ4_stream_t streamPtr)

LZ4_resetStream() : An LZ4_stream_t structure can be allocated once and re-used multiple times. Use this function to init an allocated LZ4_stream_t structure and start a new compression.

Definition at line 923 of file lz4.cxx.

References MEM_INIT.

Referenced by LZ4_compress_destSize_extState(), LZ4_compress_fast_extState(), LZ4_compress_fast_force(), LZ4_createStream(), and LZ4_loadDict().

924 {
925  MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t));
926 }
#define MEM_INIT
Definition: lz4.cxx:131
LZ4LIB_API int LZ4_saveDict ( LZ4_stream_t LZ4_dict,
char *  safeBuffer,
int  dictSize 
)

LZ4_saveDict() : If previously compressed data block is not guaranteed to remain available at its memory location, save it into a safer place (char* safeBuffer). Note : you don't need to call LZ4_loadDict() afterwards, dictionary is immediately usable, you can therefore call LZ4_compress_fast_continue(). Return : saved dictionary size in bytes (necessarily <= dictSize), or 0 if error.

Definition at line 1062 of file lz4.cxx.

References LZ4_stream_t_internal::dictionary, LZ4_stream_t_internal::dictSize, LZ4_stream_u::internal_donotuse, and KB.

Referenced by LZ4_slideInputBuffer().

1063 {
1064  LZ4_stream_t_internal* const dict = &LZ4_dict->internal_donotuse;
1065  const BYTE* const previousDictEnd = dict->dictionary + dict->dictSize;
1066 
1067  if ((U32)dictSize > 64 KB) dictSize = 64 KB; /* useless to define a dictionary > 64 KB */
1068  if ((U32)dictSize > dict->dictSize) dictSize = dict->dictSize;
1069 
1070  memmove(safeBuffer, previousDictEnd - dictSize, dictSize);
1071 
1072  dict->dictionary = (const BYTE*)safeBuffer;
1073  dict->dictSize = (U32)dictSize;
1074 
1075  return dictSize;
1076 }
unsigned int U32
Definition: lz4.cxx:148
unsigned char BYTE
Definition: lz4.cxx:146
unsigned int dictSize
Definition: lz4.h:361
LZ4_stream_t_internal internal_donotuse
Definition: lz4.h:385
const unsigned char * dictionary
Definition: lz4.h:359
#define KB
Definition: lz4.cxx:270
LZ4LIB_API int LZ4_setStreamDecode ( LZ4_streamDecode_t LZ4_streamDecode,
const char *  dictionary,
int  dictSize 
)

LZ4_setStreamDecode() : Use this function to instruct where to find the dictionary. Setting a size of 0 is allowed (same effect as reset).

Returns
: 1 if OK, 0 if error

LZ4_setStreamDecode() : Use this function to instruct where to find the dictionary. This function is not necessary if previous data is still available where it was decoded. Loading a size of 0 is allowed (same effect as no dictionary). Return : 1 if OK, 0 if error

Definition at line 1293 of file lz4.cxx.

References LZ4_streamDecode_t_internal::extDictSize, LZ4_streamDecode_t_internal::externalDict, LZ4_streamDecode_u::internal_donotuse, LZ4_streamDecode_t_internal::prefixEnd, and LZ4_streamDecode_t_internal::prefixSize.

1294 {
1295  LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse;
1296  lz4sd->prefixSize = (size_t) dictSize;
1297  lz4sd->prefixEnd = (const BYTE*) dictionary + dictSize;
1298  lz4sd->externalDict = NULL;
1299  lz4sd->extDictSize = 0;
1300  return 1;
1301 }
LZ4_streamDecode_t_internal internal_donotuse
Definition: lz4.h:401
const unsigned char * prefixEnd
Definition: lz4.h:367
const unsigned char * externalDict
Definition: lz4.h:365
unsigned char BYTE
Definition: lz4.cxx:146
LZ4LIB_API int LZ4_sizeofState ( void  )

LZ4_compress_fast_extState() : Same compression function, just using an externally allocated memory space to store compression state. Use LZ4_sizeofState() to know how much memory must be allocated, and allocate it on 8-bytes boundaries (using malloc() typically). Then, provide it as 'void* state' to compression function.

Definition at line 396 of file lz4.cxx.

References LZ4_STREAMSIZE.

396 { return LZ4_STREAMSIZE; }
#define LZ4_STREAMSIZE
Definition: lz4.h:382
LZ4LIB_API int LZ4_versionNumber ( void  )

library version number; to be used when checking dll version

Definition at line 393 of file lz4.cxx.

References LZ4_VERSION_NUMBER.

393 { return LZ4_VERSION_NUMBER; }
#define LZ4_VERSION_NUMBER
Definition: lz4.h:90
LZ4LIB_API const char* LZ4_versionString ( void  )

library version string; to be used when checking dll version

Definition at line 394 of file lz4.cxx.

References LZ4_VERSION_STRING.

394 { return LZ4_VERSION_STRING; }
#define LZ4_VERSION_STRING
Definition: lz4.h:95

Variable Documentation

char int compressedSize

Definition at line 458 of file lz4.h.

Referenced by calib::ADCShapeFitTable::ADCShapeFitTable().

const char char * dest

Definition at line 434 of file lz4.h.

char * dst
char* inputBuffer

Definition at line 454 of file lz4.h.

const char char int inputSize
char int int maxDstSize

Definition at line 458 of file lz4.h.

const char char int int maxOutputSize

Definition at line 435 of file lz4.h.

Referenced by LZ4_compress_generic(), LZ4HC_compress_hashChain(), and LZ4HC_compress_optimal().

char int originalSize

Definition at line 459 of file lz4.h.

Referenced by LZ4_decompress_fast_continue().

const char * source
char int sourceSize

Definition at line 434 of file lz4.h.