ReactOS  0.4.14-dev-599-g2d4d3f5
zstd.h File Reference
#include <stddef.h>
Include dependency graph for zstd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ZSTD_inBuffer_s
 
struct  ZSTD_outBuffer_s
 

Macros

#define ZSTD_H_235446
 
#define ZSTDLIB_VISIBILITY
 
#define ZSTDLIB_API   ZSTDLIB_VISIBILITY
 
#define ZSTD_VERSION_MAJOR   1
 
#define ZSTD_VERSION_MINOR   3
 
#define ZSTD_VERSION_RELEASE   7
 
#define ZSTD_VERSION_NUMBER   (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
 
#define ZSTD_LIB_VERSION   ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE
 
#define ZSTD_QUOTE(str)   #str
 
#define ZSTD_EXPAND_AND_QUOTE(str)   ZSTD_QUOTE(str)
 
#define ZSTD_VERSION_STRING   ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION)
 
#define ZSTD_CLEVEL_DEFAULT   3
 
#define ZSTD_CONTENTSIZE_UNKNOWN   (0ULL - 1)
 
#define ZSTD_CONTENTSIZE_ERROR   (0ULL - 2)
 
#define ZSTD_COMPRESSBOUND(srcSize)   ((srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) /* margin, from 64 to 0 */ : 0)) /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */
 

Typedefs

typedef struct ZSTD_CCtx_s ZSTD_CCtx
 
typedef struct ZSTD_DCtx_s ZSTD_DCtx
 
typedef struct ZSTD_CDict_s ZSTD_CDict
 
typedef struct ZSTD_DDict_s ZSTD_DDict
 
typedef struct ZSTD_inBuffer_s ZSTD_inBuffer
 
typedef struct ZSTD_outBuffer_s ZSTD_outBuffer
 
typedef ZSTD_CCtx ZSTD_CStream
 
typedef ZSTD_DCtx ZSTD_DStream
 

Functions

ZSTDLIB_API unsigned ZSTD_versionNumber (void)
 
ZSTDLIB_API const charZSTD_versionString (void)
 
ZSTDLIB_API size_t ZSTD_compress (void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
 
ZSTDLIB_API size_t ZSTD_decompress (void *dst, size_t dstCapacity, const void *src, size_t compressedSize)
 
ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize (const void *src, size_t srcSize)
 
ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize (const void *src, size_t srcSize)
 
ZSTDLIB_API size_t ZSTD_compressBound (size_t srcSize)
 
ZSTDLIB_API unsigned ZSTD_isError (size_t code)
 
ZSTDLIB_API const charZSTD_getErrorName (size_t code)
 
ZSTDLIB_API int ZSTD_maxCLevel (void)
 
ZSTDLIB_API ZSTD_CCtxZSTD_createCCtx (void)
 
ZSTDLIB_API size_t ZSTD_freeCCtx (ZSTD_CCtx *cctx)
 
ZSTDLIB_API size_t ZSTD_compressCCtx (ZSTD_CCtx *ctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
 
ZSTDLIB_API ZSTD_DCtxZSTD_createDCtx (void)
 
ZSTDLIB_API size_t ZSTD_freeDCtx (ZSTD_DCtx *dctx)
 
ZSTDLIB_API size_t ZSTD_decompressDCtx (ZSTD_DCtx *ctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
 
ZSTDLIB_API size_t ZSTD_compress_usingDict (ZSTD_CCtx *ctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, int compressionLevel)
 
ZSTDLIB_API size_t ZSTD_decompress_usingDict (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize)
 
ZSTDLIB_API ZSTD_CDictZSTD_createCDict (const void *dictBuffer, size_t dictSize, int compressionLevel)
 
ZSTDLIB_API size_t ZSTD_freeCDict (ZSTD_CDict *CDict)
 
ZSTDLIB_API size_t ZSTD_compress_usingCDict (ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_CDict *cdict)
 
ZSTDLIB_API ZSTD_DDictZSTD_createDDict (const void *dictBuffer, size_t dictSize)
 
ZSTDLIB_API size_t ZSTD_freeDDict (ZSTD_DDict *ddict)
 
ZSTDLIB_API size_t ZSTD_decompress_usingDDict (ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_DDict *ddict)
 
ZSTDLIB_API ZSTD_CStreamZSTD_createCStream (void)
 
ZSTDLIB_API size_t ZSTD_freeCStream (ZSTD_CStream *zcs)
 
ZSTDLIB_API size_t ZSTD_initCStream (ZSTD_CStream *zcs, int compressionLevel)
 
ZSTDLIB_API size_t ZSTD_compressStream (ZSTD_CStream *zcs, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
 
ZSTDLIB_API size_t ZSTD_flushStream (ZSTD_CStream *zcs, ZSTD_outBuffer *output)
 
ZSTDLIB_API size_t ZSTD_endStream (ZSTD_CStream *zcs, ZSTD_outBuffer *output)
 
ZSTDLIB_API size_t ZSTD_CStreamInSize (void)
 
ZSTDLIB_API size_t ZSTD_CStreamOutSize (void)
 
ZSTDLIB_API ZSTD_DStreamZSTD_createDStream (void)
 
ZSTDLIB_API size_t ZSTD_freeDStream (ZSTD_DStream *zds)
 
ZSTDLIB_API size_t ZSTD_initDStream (ZSTD_DStream *zds)
 
ZSTDLIB_API size_t ZSTD_decompressStream (ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
 
ZSTDLIB_API size_t ZSTD_DStreamInSize (void)
 
ZSTDLIB_API size_t ZSTD_DStreamOutSize (void)
 

Macro Definition Documentation

◆ ZSTD_CLEVEL_DEFAULT

#define ZSTD_CLEVEL_DEFAULT   3

Definition at line 89 of file zstd.h.

◆ ZSTD_COMPRESSBOUND

#define ZSTD_COMPRESSBOUND (   srcSize)    ((srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) /* margin, from 64 to 0 */ : 0)) /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */

Definition at line 150 of file zstd.h.

◆ ZSTD_CONTENTSIZE_ERROR

#define ZSTD_CONTENTSIZE_ERROR   (0ULL - 2)

Definition at line 137 of file zstd.h.

◆ ZSTD_CONTENTSIZE_UNKNOWN

#define ZSTD_CONTENTSIZE_UNKNOWN   (0ULL - 1)

ZSTD_getFrameContentSize() : added in v1.3.0 src should point to the start of a ZSTD encoded frame. srcSize must be at least as large as the frame header. hint : any size >= ZSTD_frameHeaderSize_max is large enough.

Returns
: - decompressed size of src frame content, if known
  • ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined
  • ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small) note 1 : a 0 return value means the frame is valid but "empty". note 2 : decompressed size is an optional field, it may not be present, typically in streaming mode. When return==ZSTD_CONTENTSIZE_UNKNOWN, data to decompress could be any size. In which case, it's necessary to use streaming mode to decompress data. Optionally, application can rely on some implicit limit, as ZSTD_decompress() only needs an upper bound of decompressed size. (For example, data could be necessarily cut into blocks <= 16 KB). note 3 : decompressed size is always present when compression is completed using single-pass functions, such as ZSTD_compress(), ZSTD_compressCCtx() ZSTD_compress_usingDict() or ZSTD_compress_usingCDict(). note 4 : decompressed size can be very large (64-bits value), potentially larger than what local system can handle as a single memory segment. In which case, it's necessary to use streaming mode to decompress data. note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified. Always ensure return value fits within application's authorized limits. Each application can set its own limits. note 6 : This function replaces ZSTD_getDecompressedSize()

Definition at line 136 of file zstd.h.

◆ ZSTD_EXPAND_AND_QUOTE

#define ZSTD_EXPAND_AND_QUOTE (   str)    ZSTD_QUOTE(str)

Definition at line 81 of file zstd.h.

◆ ZSTD_H_235446

#define ZSTD_H_235446

Definition at line 15 of file zstd.h.

◆ ZSTD_LIB_VERSION

Definition at line 79 of file zstd.h.

◆ ZSTD_QUOTE

#define ZSTD_QUOTE (   str)    #str

Definition at line 80 of file zstd.h.

◆ ZSTD_VERSION_MAJOR

#define ZSTD_VERSION_MAJOR   1

Definition at line 72 of file zstd.h.

◆ ZSTD_VERSION_MINOR

#define ZSTD_VERSION_MINOR   3

Definition at line 73 of file zstd.h.

◆ ZSTD_VERSION_NUMBER

#define ZSTD_VERSION_NUMBER   (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)

Definition at line 76 of file zstd.h.

◆ ZSTD_VERSION_RELEASE

#define ZSTD_VERSION_RELEASE   7

Definition at line 74 of file zstd.h.

◆ ZSTD_VERSION_STRING

#define ZSTD_VERSION_STRING   ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION)

Definition at line 82 of file zstd.h.

◆ ZSTDLIB_API

#define ZSTDLIB_API   ZSTDLIB_VISIBILITY

Definition at line 34 of file zstd.h.

◆ ZSTDLIB_VISIBILITY

#define ZSTDLIB_VISIBILITY

Definition at line 26 of file zstd.h.

Typedef Documentation

◆ ZSTD_CCtx

Definition at line 165 of file zstd.h.

◆ ZSTD_CDict

Definition at line 220 of file zstd.h.

◆ ZSTD_CStream

CCtx and CStream are now effectively same object (>= v1.3.0)

Definition at line 332 of file zstd.h.

◆ ZSTD_DCtx

Definition at line 182 of file zstd.h.

◆ ZSTD_DDict

Definition at line 248 of file zstd.h.

◆ ZSTD_DStream

DCtx and DStream are now effectively same object (>= v1.3.0)

Definition at line 377 of file zstd.h.

◆ ZSTD_inBuffer

◆ ZSTD_outBuffer

Function Documentation

◆ ZSTD_compress()

ZSTDLIB_API size_t ZSTD_compress ( void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
int  compressionLevel 
)

ZSTD_compress() : Compresses src content as a single zstd compressed frame into already allocated dst. Hint : compression runs faster if dstCapacity >= ZSTD_compressBound(srcSize).

Returns
: compressed size written into dst (<= `dstCapacity), or an error code if it fails (which can be tested using ZSTD_isError()).

Definition at line 3171 of file zstd_compress.c.

3174 {
3175  size_t result;
3176  ZSTD_CCtx ctxBody;
3177  ZSTD_initCCtx(&ctxBody, ZSTD_defaultCMem);
3178  result = ZSTD_compressCCtx(&ctxBody, dst, dstCapacity, src, srcSize, compressionLevel);
3179  ZSTD_freeCCtxContent(&ctxBody); /* can't free ctxBody itself, as it's on stack; free only heap content */
3180  return result;
3181 }
size_t ZSTD_compressCCtx(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, int compressionLevel)
static void ZSTD_freeCCtxContent(ZSTD_CCtx *cctx)
GLenum src
Definition: glext.h:6340
static void ZSTD_initCCtx(ZSTD_CCtx *cctx, ZSTD_customMem memManager)
Definition: zstd_compress.c:58
GLenum GLenum dst
Definition: glext.h:6340
GLuint64EXT * result
Definition: glext.h:11304

◆ ZSTD_compress_usingCDict()

ZSTDLIB_API size_t ZSTD_compress_usingCDict ( ZSTD_CCtx cctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const ZSTD_CDict cdict 
)

ZSTD_compress_usingCDict() : Compression using a digested Dictionary. Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. Note that compression level is decided during dictionary creation. Frame parameters are hardcoded (dictID=yes, contentSize=yes, checksum=no) Note : ZSTD_compress_usingCDict() can be used with a ZSTD_CDict created from an empty dictionary. But it is inefficient for small data, and it is recommended to use ZSTD_compressCCtx().

ZSTD_compress_usingCDict() : Compression using a digested Dictionary. Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. Note that compression parameters are decided at CDict creation time while frame parameters are hardcoded

Definition at line 3428 of file zstd_compress.c.

3432 {
3433  ZSTD_frameParameters const fParams = { 1 /*content*/, 0 /*checksum*/, 0 /*noDictID*/ };
3434  return ZSTD_compress_usingCDict_advanced(cctx, dst, dstCapacity, src, srcSize, cdict, fParams);
3435 }
GLenum src
Definition: glext.h:6340
size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_CDict *cdict, ZSTD_frameParameters fParams)
GLenum GLenum dst
Definition: glext.h:6340

◆ ZSTD_compress_usingDict()

ZSTDLIB_API size_t ZSTD_compress_usingDict ( ZSTD_CCtx ctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const void dict,
size_t  dictSize,
int  compressionLevel 
)

ZSTD_compress_usingDict() : Compression using a predefined Dictionary (see dictBuilder/zdict.h). Note : This function loads the dictionary, resulting in significant startup delay. Note : When dict == NULL || dictSize < 8 no dictionary is used.

Definition at line 3149 of file zstd_compress.c.

3154 {
3155  ZSTD_parameters const params = ZSTD_getParams(compressionLevel, srcSize + (!srcSize), dict ? dictSize : 0);
3156  ZSTD_CCtx_params cctxParams = ZSTD_assignParamsToCCtxParams(cctx->requestedParams, params);
3157  assert(params.fParams.contentSizeFlag == 1);
3158  return ZSTD_compress_advanced_internal(cctx, dst, dstCapacity, src, srcSize, dict, dictSize, cctxParams);
3159 }
#define assert(x)
Definition: debug.h:53
GLenum const GLfloat * params
Definition: glext.h:5645
static ZSTD_CCtx_params ZSTD_assignParamsToCCtxParams(ZSTD_CCtx_params cctxParams, ZSTD_parameters params)
GLenum src
Definition: glext.h:6340
size_t ZSTD_compress_advanced_internal(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, ZSTD_CCtx_params params)
GLenum GLenum dst
Definition: glext.h:6340
ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)

Referenced by ZSTD_compressCCtx().

◆ ZSTD_compressBound()

ZSTDLIB_API size_t ZSTD_compressBound ( size_t  srcSize)

maximum compressed size in worst case single-pass scenario

Definition at line 33 of file zstd_compress.c.

33  {
34  return ZSTD_COMPRESSBOUND(srcSize);
35 }
#define ZSTD_COMPRESSBOUND(srcSize)
Definition: zstd.h:150

Referenced by ZSTD_compressStream_generic(), ZSTD_CStreamOutSize(), ZSTD_estimateCStreamSize_usingCCtxParams(), and ZSTD_resetCCtx_internal().

◆ ZSTD_compressCCtx()

ZSTDLIB_API size_t ZSTD_compressCCtx ( ZSTD_CCtx ctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
int  compressionLevel 
)

ZSTD_compressCCtx() : Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()).

Definition at line 3161 of file zstd_compress.c.

3165 {
3166  DEBUGLOG(4, "ZSTD_compressCCtx (srcSize=%u)", (U32)srcSize);
3167  assert(cctx != NULL);
3168  return ZSTD_compress_usingDict(cctx, dst, dstCapacity, src, srcSize, NULL, 0, compressionLevel);
3169 }
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
#define DEBUGLOG(l,...)
Definition: debug.h:115
smooth NULL
Definition: ftsmooth.c:416
GLenum src
Definition: glext.h:6340
size_t ZSTD_compress_usingDict(ZSTD_CCtx *cctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, int compressionLevel)
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_compress().

◆ ZSTD_compressStream()

ZSTDLIB_API size_t ZSTD_compressStream ( ZSTD_CStream zcs,
ZSTD_outBuffer output,
ZSTD_inBuffer input 
)

Definition at line 3770 of file zstd_compress.c.

3771 {
3772  /* check conditions */
3773  if (output->pos > output->size) return ERROR(GENERIC);
3774  if (input->pos > input->size) return ERROR(GENERIC);
3775 
3776  return ZSTD_compressStream_generic(zcs, output, input, ZSTD_e_continue);
3777 }
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
#define ERROR(name)
Definition: error_private.h:53
size_t ZSTD_compressStream_generic(ZSTD_CStream *zcs, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective const flushMode)
GLenum GLenum GLenum input
Definition: glext.h:9031

Referenced by zstd_write_compressed_bit().

◆ ZSTD_createCCtx()

ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx ( void  )

Definition at line 53 of file zstd_compress.c.

54 {
55  return ZSTD_createCCtx_advanced(ZSTD_defaultCMem);
56 }
ZSTD_CCtx * ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
Definition: zstd_compress.c:70

◆ ZSTD_createCDict()

ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict ( const void dictBuffer,
size_t  dictSize,
int  compressionLevel 
)

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

Definition at line 3294 of file zstd_compress.c.

3295 {
3296  ZSTD_compressionParameters cParams = ZSTD_getCParams(compressionLevel, 0, dictSize);
3297  return ZSTD_createCDict_advanced(dict, dictSize,
3298  ZSTD_dlm_byCopy, ZSTD_dct_auto,
3299  cParams, ZSTD_defaultCMem);
3300 }
ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize)
ZSTD_CDict * ZSTD_createCDict_advanced(const void *dictBuffer, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams, ZSTD_customMem customMem)

◆ ZSTD_createCStream()

ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream ( void  )

Definition at line 3443 of file zstd_compress.c.

3444 {
3445  DEBUGLOG(3, "ZSTD_createCStream");
3446  return ZSTD_createCStream_advanced(ZSTD_defaultCMem);
3447 }
#define DEBUGLOG(l,...)
Definition: debug.h:115
ZSTD_CStream * ZSTD_createCStream_advanced(ZSTD_customMem customMem)

◆ ZSTD_createDCtx()

ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx ( void  )

Definition at line 247 of file zstd_decompress.c.

248 {
249  DEBUGLOG(3, "ZSTD_createDCtx");
250  return ZSTD_createDCtx_advanced(ZSTD_defaultCMem);
251 }
#define DEBUGLOG(l,...)
Definition: debug.h:115
ZSTD_DCtx * ZSTD_createDCtx_advanced(ZSTD_customMem customMem)

Referenced by ZSTD_decompress().

◆ ZSTD_createDDict()

ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict ( const void dict,
size_t  dictSize 
)

ZSTD_createDDict() : Create a digested dictionary, ready to start decompression operation without startup delay. dictBuffer can be released after DDict creation, as its content is copied inside DDict

ZSTD_createDDict() : Create a digested dictionary, to start decompression without startup delay. dict content is copied inside DDict. Consequently, dict can be released after ZSTD_DDict creation

Definition at line 2504 of file zstd_decompress.c.

2505 {
2506  ZSTD_customMem const allocator = { NULL, NULL, NULL };
2507  return ZSTD_createDDict_advanced(dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto, allocator);
2508 }
smooth NULL
Definition: ftsmooth.c:416
ZSTD_DDict * ZSTD_createDDict_advanced(const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_customMem customMem)

◆ ZSTD_createDStream()

ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream ( void  )

Definition at line 2632 of file zstd_decompress.c.

2633 {
2634  DEBUGLOG(3, "ZSTD_createDStream");
2635  return ZSTD_createDStream_advanced(ZSTD_defaultCMem);
2636 }
#define DEBUGLOG(l,...)
Definition: debug.h:115
ZSTD_DStream * ZSTD_createDStream_advanced(ZSTD_customMem customMem)

◆ ZSTD_CStreamInSize()

ZSTDLIB_API size_t ZSTD_CStreamInSize ( void  )

recommended size for input buffer

Definition at line 3468 of file zstd_compress.c.

3468 { return ZSTD_BLOCKSIZE_MAX; }

◆ ZSTD_CStreamOutSize()

ZSTDLIB_API size_t ZSTD_CStreamOutSize ( void  )

recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block in all circumstances.

Definition at line 3470 of file zstd_compress.c.

3471 {
3472  return ZSTD_compressBound(ZSTD_BLOCKSIZE_MAX) + ZSTD_blockHeaderSize + 4 /* 32-bits hash */ ;
3473 }
static const size_t ZSTD_blockHeaderSize
Definition: zstd_internal.h:85
size_t ZSTD_compressBound(size_t srcSize)
Definition: zstd_compress.c:33

◆ ZSTD_decompress()

ZSTDLIB_API size_t ZSTD_decompress ( void dst,
size_t  dstCapacity,
const void src,
size_t  compressedSize 
)

ZSTD_decompress() : compressedSize : must be the exact size of some number of compressed and/or skippable frames. dstCapacity is an upper bound of originalSize to regenerate. If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data.

Returns
: the number of bytes decompressed into dst (<= dstCapacity), or an errorCode if it fails (which can be tested using ZSTD_isError()).

Definition at line 2040 of file zstd_decompress.c.

2041 {
2042 #if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE>=1)
2043  size_t regenSize;
2044  ZSTD_DCtx* const dctx = ZSTD_createDCtx();
2045  if (dctx==NULL) return ERROR(memory_allocation);
2046  regenSize = ZSTD_decompressDCtx(dctx, dst, dstCapacity, src, srcSize);
2047  ZSTD_freeDCtx(dctx);
2048  return regenSize;
2049 #else /* stack mode */
2050  ZSTD_DCtx dctx;
2051  ZSTD_initDCtx_internal(&dctx);
2052  return ZSTD_decompressDCtx(&dctx, dst, dstCapacity, src, srcSize);
2053 #endif
2054 }
ZSTD_DCtx * ZSTD_createDCtx(void)
#define ERROR(name)
Definition: error_private.h:53
size_t ZSTD_decompressDCtx(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
smooth NULL
Definition: ftsmooth.c:416
size_t ZSTD_freeDCtx(ZSTD_DCtx *dctx)
GLenum src
Definition: glext.h:6340
static void ZSTD_initDCtx_internal(ZSTD_DCtx *dctx)
GLenum GLenum dst
Definition: glext.h:6340

◆ ZSTD_decompress_usingDDict()

ZSTDLIB_API size_t ZSTD_decompress_usingDDict ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const ZSTD_DDict ddict 
)

ZSTD_decompress_usingDDict() : Decompression using a digested Dictionary. Faster startup than ZSTD_decompress_usingDict(), recommended when same dictionary is used multiple times.

ZSTD_decompress_usingDDict() : Decompression using a pre-digested Dictionary Use dictionary without significant overhead.

Definition at line 2616 of file zstd_decompress.c.

2620 {
2621  /* pass content and size in case legacy frames are encountered */
2622  return ZSTD_decompressMultiFrame(dctx, dst, dstCapacity, src, srcSize,
2623  NULL, 0,
2624  ddict);
2625 }
static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, const ZSTD_DDict *ddict)
smooth NULL
Definition: ftsmooth.c:416
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_decompressStream().

◆ ZSTD_decompress_usingDict()

ZSTDLIB_API size_t ZSTD_decompress_usingDict ( ZSTD_DCtx dctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize,
const void dict,
size_t  dictSize 
)

ZSTD_decompress_usingDict() : Decompression using a predefined Dictionary (see dictBuilder/zdict.h). Dictionary must be identical to the one used during compression. Note : This function loads the dictionary, resulting in significant startup delay. Note : When dict == NULL || dictSize < 8 no dictionary is used.

Definition at line 2025 of file zstd_decompress.c.

2029 {
2030  return ZSTD_decompressMultiFrame(dctx, dst, dstCapacity, src, srcSize, dict, dictSize, NULL);
2031 }
static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, const ZSTD_DDict *ddict)
smooth NULL
Definition: ftsmooth.c:416
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by ZSTD_decompressDCtx().

◆ ZSTD_decompressDCtx()

ZSTDLIB_API size_t ZSTD_decompressDCtx ( ZSTD_DCtx ctx,
void dst,
size_t  dstCapacity,
const void src,
size_t  srcSize 
)

ZSTD_decompressDCtx() : Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx())

Definition at line 2034 of file zstd_decompress.c.

2035 {
2036  return ZSTD_decompress_usingDict(dctx, dst, dstCapacity, src, srcSize, NULL, 0);
2037 }
smooth NULL
Definition: ftsmooth.c:416
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
size_t ZSTD_decompress_usingDict(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize)

Referenced by ZSTD_decompress().

◆ ZSTD_decompressStream()

ZSTDLIB_API size_t ZSTD_decompressStream ( ZSTD_DStream zds,
ZSTD_outBuffer output,
ZSTD_inBuffer input 
)

Definition at line 2823 of file zstd_decompress.c.

2824 {
2825  const char* const istart = (const char*)(input->src) + input->pos;
2826  const char* const iend = (const char*)(input->src) + input->size;
2827  const char* ip = istart;
2828  char* const ostart = (char*)(output->dst) + output->pos;
2829  char* const oend = (char*)(output->dst) + output->size;
2830  char* op = ostart;
2831  U32 someMoreWork = 1;
2832 
2833  DEBUGLOG(5, "ZSTD_decompressStream");
2834  if (input->pos > input->size) { /* forbidden */
2835  DEBUGLOG(5, "in: pos: %u vs size: %u",
2836  (U32)input->pos, (U32)input->size);
2837  return ERROR(srcSize_wrong);
2838  }
2839  if (output->pos > output->size) { /* forbidden */
2840  DEBUGLOG(5, "out: pos: %u vs size: %u",
2841  (U32)output->pos, (U32)output->size);
2842  return ERROR(dstSize_tooSmall);
2843  }
2844  DEBUGLOG(5, "input size : %u", (U32)(input->size - input->pos));
2845 
2846  while (someMoreWork) {
2847  switch(zds->streamStage)
2848  {
2849  case zdss_init :
2850  DEBUGLOG(5, "stage zdss_init => transparent reset ");
2851  ZSTD_resetDStream(zds); /* transparent reset on starting decoding a new frame */
2852  /* fall-through */
2853 
2854  case zdss_loadHeader :
2855  DEBUGLOG(5, "stage zdss_loadHeader (srcSize : %u)", (U32)(iend - ip));
2856 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
2857  if (zds->legacyVersion) {
2858  /* legacy support is incompatible with static dctx */
2859  if (zds->staticSize) return ERROR(memory_allocation);
2860  { size_t const hint = ZSTD_decompressLegacyStream(zds->legacyContext, zds->legacyVersion, output, input);
2861  if (hint==0) zds->streamStage = zdss_init;
2862  return hint;
2863  } }
2864 #endif
2865  { size_t const hSize = ZSTD_getFrameHeader_advanced(&zds->fParams, zds->headerBuffer, zds->lhSize, zds->format);
2866  DEBUGLOG(5, "header size : %u", (U32)hSize);
2867  if (ZSTD_isError(hSize)) {
2868 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
2869  U32 const legacyVersion = ZSTD_isLegacy(istart, iend-istart);
2870  if (legacyVersion) {
2871  const void* const dict = zds->ddict ? zds->ddict->dictContent : NULL;
2872  size_t const dictSize = zds->ddict ? zds->ddict->dictSize : 0;
2873  DEBUGLOG(5, "ZSTD_decompressStream: detected legacy version v0.%u", legacyVersion);
2874  /* legacy support is incompatible with static dctx */
2875  if (zds->staticSize) return ERROR(memory_allocation);
2876  CHECK_F(ZSTD_initLegacyStream(&zds->legacyContext,
2877  zds->previousLegacyVersion, legacyVersion,
2878  dict, dictSize));
2879  zds->legacyVersion = zds->previousLegacyVersion = legacyVersion;
2880  { size_t const hint = ZSTD_decompressLegacyStream(zds->legacyContext, legacyVersion, output, input);
2881  if (hint==0) zds->streamStage = zdss_init; /* or stay in stage zdss_loadHeader */
2882  return hint;
2883  } }
2884 #endif
2885  return hSize; /* error */
2886  }
2887  if (hSize != 0) { /* need more input */
2888  size_t const toLoad = hSize - zds->lhSize; /* if hSize!=0, hSize > zds->lhSize */
2889  size_t const remainingInput = (size_t)(iend-ip);
2890  assert(iend >= ip);
2891  if (toLoad > remainingInput) { /* not enough input to load full header */
2892  if (remainingInput > 0) {
2893  memcpy(zds->headerBuffer + zds->lhSize, ip, remainingInput);
2894  zds->lhSize += remainingInput;
2895  }
2896  input->pos = input->size;
2897  return (MAX(ZSTD_frameHeaderSize_min, hSize) - zds->lhSize) + ZSTD_blockHeaderSize; /* remaining header bytes + next block header */
2898  }
2899  assert(ip != NULL);
2900  memcpy(zds->headerBuffer + zds->lhSize, ip, toLoad); zds->lhSize = hSize; ip += toLoad;
2901  break;
2902  } }
2903 
2904  /* check for single-pass mode opportunity */
2905  if (zds->fParams.frameContentSize && zds->fParams.windowSize /* skippable frame if == 0 */
2906  && (U64)(size_t)(oend-op) >= zds->fParams.frameContentSize) {
2907  size_t const cSize = ZSTD_findFrameCompressedSize(istart, iend-istart);
2908  if (cSize <= (size_t)(iend-istart)) {
2909  /* shortcut : using single-pass mode */
2910  size_t const decompressedSize = ZSTD_decompress_usingDDict(zds, op, oend-op, istart, cSize, zds->ddict);
2911  if (ZSTD_isError(decompressedSize)) return decompressedSize;
2912  DEBUGLOG(4, "shortcut to single-pass ZSTD_decompress_usingDDict()")
2913  ip = istart + cSize;
2914  op += decompressedSize;
2915  zds->expected = 0;
2916  zds->streamStage = zdss_init;
2917  someMoreWork = 0;
2918  break;
2919  } }
2920 
2921  /* Consume header (see ZSTDds_decodeFrameHeader) */
2922  DEBUGLOG(4, "Consume header");
2923  CHECK_F(ZSTD_decompressBegin_usingDDict(zds, zds->ddict));
2924 
2925  if ((MEM_readLE32(zds->headerBuffer) & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) { /* skippable frame */
2926  zds->expected = MEM_readLE32(zds->headerBuffer + ZSTD_FRAMEIDSIZE);
2927  zds->stage = ZSTDds_skipFrame;
2928  } else {
2932  }
2933 
2934  /* control buffer memory usage */
2935  DEBUGLOG(4, "Control max memory usage (%u KB <= max %u KB)",
2936  (U32)(zds->fParams.windowSize >>10),
2937  (U32)(zds->maxWindowSize >> 10) );
2938  zds->fParams.windowSize = MAX(zds->fParams.windowSize, 1U << ZSTD_WINDOWLOG_ABSOLUTEMIN);
2939  if (zds->fParams.windowSize > zds->maxWindowSize) return ERROR(frameParameter_windowTooLarge);
2940 
2941  /* Adapt buffer sizes to frame header instructions */
2942  { size_t const neededInBuffSize = MAX(zds->fParams.blockSizeMax, 4 /* frame checksum */);
2943  size_t const neededOutBuffSize = ZSTD_decodingBufferSize_min(zds->fParams.windowSize, zds->fParams.frameContentSize);
2944  if ((zds->inBuffSize < neededInBuffSize) || (zds->outBuffSize < neededOutBuffSize)) {
2945  size_t const bufferSize = neededInBuffSize + neededOutBuffSize;
2946  DEBUGLOG(4, "inBuff : from %u to %u",
2947  (U32)zds->inBuffSize, (U32)neededInBuffSize);
2948  DEBUGLOG(4, "outBuff : from %u to %u",
2949  (U32)zds->outBuffSize, (U32)neededOutBuffSize);
2950  if (zds->staticSize) { /* static DCtx */
2951  DEBUGLOG(4, "staticSize : %u", (U32)zds->staticSize);
2952  assert(zds->staticSize >= sizeof(ZSTD_DCtx)); /* controlled at init */
2953  if (bufferSize > zds->staticSize - sizeof(ZSTD_DCtx))
2954  return ERROR(memory_allocation);
2955  } else {
2956  ZSTD_free(zds->inBuff, zds->customMem);
2957  zds->inBuffSize = 0;
2958  zds->outBuffSize = 0;
2959  zds->inBuff = (char*)ZSTD_malloc(bufferSize, zds->customMem);
2960  if (zds->inBuff == NULL) return ERROR(memory_allocation);
2961  }
2962  zds->inBuffSize = neededInBuffSize;
2963  zds->outBuff = zds->inBuff + zds->inBuffSize;
2964  zds->outBuffSize = neededOutBuffSize;
2965  } }
2966  zds->streamStage = zdss_read;
2967  /* fall-through */
2968 
2969  case zdss_read:
2970  DEBUGLOG(5, "stage zdss_read");
2971  { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds);
2972  DEBUGLOG(5, "neededInSize = %u", (U32)neededInSize);
2973  if (neededInSize==0) { /* end of frame */
2974  zds->streamStage = zdss_init;
2975  someMoreWork = 0;
2976  break;
2977  }
2978  if ((size_t)(iend-ip) >= neededInSize) { /* decode directly from src */
2979  int const isSkipFrame = ZSTD_isSkipFrame(zds);
2980  size_t const decodedSize = ZSTD_decompressContinue(zds,
2981  zds->outBuff + zds->outStart, (isSkipFrame ? 0 : zds->outBuffSize - zds->outStart),
2982  ip, neededInSize);
2983  if (ZSTD_isError(decodedSize)) return decodedSize;
2984  ip += neededInSize;
2985  if (!decodedSize && !isSkipFrame) break; /* this was just a header */
2986  zds->outEnd = zds->outStart + decodedSize;
2987  zds->streamStage = zdss_flush;
2988  break;
2989  } }
2990  if (ip==iend) { someMoreWork = 0; break; } /* no more input */
2991  zds->streamStage = zdss_load;
2992  /* fall-through */
2993 
2994  case zdss_load:
2995  { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds);
2996  size_t const toLoad = neededInSize - zds->inPos;
2997  int const isSkipFrame = ZSTD_isSkipFrame(zds);
2998  size_t loadedSize;
2999  if (isSkipFrame) {
3000  loadedSize = MIN(toLoad, (size_t)(iend-ip));
3001  } else {
3002  if (toLoad > zds->inBuffSize - zds->inPos) return ERROR(corruption_detected); /* should never happen */
3003  loadedSize = ZSTD_limitCopy(zds->inBuff + zds->inPos, toLoad, ip, iend-ip);
3004  }
3005  ip += loadedSize;
3006  zds->inPos += loadedSize;
3007  if (loadedSize < toLoad) { someMoreWork = 0; break; } /* not enough input, wait for more */
3008 
3009  /* decode loaded input */
3010  { size_t const decodedSize = ZSTD_decompressContinue(zds,
3011  zds->outBuff + zds->outStart, zds->outBuffSize - zds->outStart,
3012  zds->inBuff, neededInSize);
3013  if (ZSTD_isError(decodedSize)) return decodedSize;
3014  zds->inPos = 0; /* input is consumed */
3015  if (!decodedSize && !isSkipFrame) { zds->streamStage = zdss_read; break; } /* this was just a header */
3016  zds->outEnd = zds->outStart + decodedSize;
3017  } }
3018  zds->streamStage = zdss_flush;
3019  /* fall-through */
3020 
3021  case zdss_flush:
3022  { size_t const toFlushSize = zds->outEnd - zds->outStart;
3023  size_t const flushedSize = ZSTD_limitCopy(op, oend-op, zds->outBuff + zds->outStart, toFlushSize);
3024  op += flushedSize;
3025  zds->outStart += flushedSize;
3026  if (flushedSize == toFlushSize) { /* flush completed */
3027  zds->streamStage = zdss_read;
3028  if ( (zds->outBuffSize < zds->fParams.frameContentSize)
3029  && (zds->outStart + zds->fParams.blockSizeMax > zds->outBuffSize) ) {
3030  DEBUGLOG(5, "restart filling outBuff from beginning (left:%i, needed:%u)",
3031  (int)(zds->outBuffSize - zds->outStart),
3032  (U32)zds->fParams.blockSizeMax);
3033  zds->outStart = zds->outEnd = 0;
3034  }
3035  break;
3036  } }
3037  /* cannot complete flush */
3038  someMoreWork = 0;
3039  break;
3040 
3041  default: return ERROR(GENERIC); /* impossible */
3042  } }
3043 
3044  /* result */
3045  input->pos = (size_t)(ip - (const char*)(input->src));
3046  output->pos = (size_t)(op - (char*)(output->dst));
3047  if ((ip==istart) && (op==ostart)) { /* no forward progress */
3048  zds->noForwardProgress ++;
3050  if (op==oend) return ERROR(dstSize_tooSmall);
3051  if (ip==iend) return ERROR(srcSize_wrong);
3052  assert(0);
3053  }
3054  } else {
3055  zds->noForwardProgress = 0;
3056  }
3057  { size_t nextSrcSizeHint = ZSTD_nextSrcSizeToDecompress(zds);
3058  if (!nextSrcSizeHint) { /* frame fully decoded */
3059  if (zds->outEnd == zds->outStart) { /* output fully flushed */
3060  if (zds->hostageByte) {
3061  if (input->pos >= input->size) {
3062  /* can't release hostage (not present) */
3063  zds->streamStage = zdss_read;
3064  return 1;
3065  }
3066  input->pos++; /* release hostage */
3067  } /* zds->hostageByte */
3068  return 0;
3069  } /* zds->outEnd == zds->outStart */
3070  if (!zds->hostageByte) { /* output not fully flushed; keep last byte as hostage; will be released when all output is flushed */
3071  input->pos--; /* note : pos > 0, otherwise, impossible to finish reading last block */
3072  zds->hostageByte=1;
3073  }
3074  return 1;
3075  } /* nextSrcSizeHint==0 */
3076  nextSrcSizeHint += ZSTD_blockHeaderSize * (ZSTD_nextInputType(zds) == ZSTDnit_block); /* preload header of next block */
3077  assert(zds->inPos <= nextSrcSizeHint);
3078  nextSrcSizeHint -= zds->inPos; /* part already loaded*/
3079  return nextSrcSizeHint;
3080  }
3081 }
#define ZSTD_NO_FORWARD_PROGRESS_MAX
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
const void * dictContent
ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx *dctx)
ZSTD_frameHeader fParams
#define ERROR(name)
Definition: error_private.h:53
ZSTD_dStreamStage streamStage
void ZSTD_free(void *ptr, ZSTD_customMem customMem)
Definition: zstd_common.c:68
static int ZSTD_isSkipFrame(ZSTD_DCtx *dctx)
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
Definition: mem.h:273
#define U(x)
Definition: wordpad.c:44
#define ZSTD_WINDOWLOG_ABSOLUTEMIN
Definition: zstd_internal.h:77
unsigned int U32
Definition: mem.h:77
#define assert(x)
Definition: debug.h:53
ZSTD_format_e format
T MIN(T a, T b)
Definition: polytest.cpp:79
#define DEBUGLOG(l,...)
Definition: debug.h:115
size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx *dctx)
static const size_t ZSTD_blockHeaderSize
Definition: zstd_internal.h:85
void * legacyContext
size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader *zfhPtr, const void *src, size_t srcSize, ZSTD_format_e format)
size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
smooth NULL
Definition: ftsmooth.c:416
size_t ZSTD_resetDStream(ZSTD_DStream *dctx)
ZSTD_customMem customMem
#define CHECK_F(f)
Definition: fse_compress.c:661
BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX]
MEM_STATIC size_t ZSTD_limitCopy(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
const ZSTD_DDict * ddict
static size_t ZSTD_decodeFrameHeader(ZSTD_DCtx *dctx, const void *src, size_t headerSize)
__kernel_size_t size_t
Definition: linux.h:237
Definition: dhcpd.h:61
if(!(yy_init))
Definition: macro.lex.yy.c:714
size_t ZSTD_decompress_usingDDict(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_DDict *ddict)
ZSTD_dStage stage
size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
void * ZSTD_malloc(size_t size, ZSTD_customMem customMem)
Definition: zstd_common.c:54
T MAX(T a, T b)
Definition: polytest.cpp:85
U32 previousLegacyVersion
#define ZSTD_isError
size_t ZSTD_decompressContinue(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
DWORD hint
Definition: vfdcmd.c:88
GLenum GLenum GLenum input
Definition: glext.h:9031
unsigned long long U64
Definition: mem.h:81
size_t outBuffSize
#define ZSTD_FRAMEIDSIZE
Definition: zstd_internal.h:82
size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize)
UINT op
Definition: effect.c:223
size_t maxWindowSize
BOOL expected
Definition: store.c:2063

Referenced by zstd_decompress(), and ZSTD_decompress_generic().

◆ ZSTD_DStreamInSize()

ZSTDLIB_API size_t ZSTD_DStreamInSize ( void  )

recommended size for input buffer

Definition at line 2656 of file zstd_decompress.c.

2656 { return ZSTD_BLOCKSIZE_MAX + ZSTD_blockHeaderSize; }
static const size_t ZSTD_blockHeaderSize
Definition: zstd_internal.h:85

◆ ZSTD_DStreamOutSize()

ZSTDLIB_API size_t ZSTD_DStreamOutSize ( void  )

recommended size for output buffer. Guarantee to successfully flush at least one complete block in all circumstances.

Definition at line 2657 of file zstd_decompress.c.

2657 { return ZSTD_BLOCKSIZE_MAX; }

◆ ZSTD_endStream()

ZSTDLIB_API size_t ZSTD_endStream ( ZSTD_CStream zcs,
ZSTD_outBuffer output 
)

Definition at line 3883 of file zstd_compress.c.

3884 {
3885  ZSTD_inBuffer input = { NULL, 0, 0 };
3886  if (output->pos > output->size) return ERROR(GENERIC);
3887  CHECK_F( ZSTD_compressStream_generic(zcs, output, &input, ZSTD_e_end) );
3888  { size_t const lastBlockSize = zcs->frameEnded ? 0 : ZSTD_BLOCKHEADERSIZE;
3889  size_t const checksumSize = zcs->frameEnded ? 0 : zcs->appliedParams.fParams.checksumFlag * 4;
3890  size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize + lastBlockSize + checksumSize;
3891  DEBUGLOG(4, "ZSTD_endStream : remaining to flush : %u", (U32)toFlush);
3892  return toFlush;
3893  }
3894 }
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
#define ERROR(name)
Definition: error_private.h:53
unsigned int U32
Definition: mem.h:77
#define DEBUGLOG(l,...)
Definition: debug.h:115
smooth NULL
Definition: ftsmooth.c:416
ZSTD_CCtx_params appliedParams
#define CHECK_F(f)
Definition: fse_compress.c:661
#define ZSTD_BLOCKHEADERSIZE
Definition: zstd_internal.h:84
size_t ZSTD_compressStream_generic(ZSTD_CStream *zcs, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective const flushMode)
GLenum GLenum GLenum input
Definition: glext.h:9031

Referenced by zstd_write_compressed_bit().

◆ ZSTD_flushStream()

ZSTDLIB_API size_t ZSTD_flushStream ( ZSTD_CStream zcs,
ZSTD_outBuffer output 
)

ZSTD_flushStream() :

Returns
: amount of data remaining to flush

Definition at line 3874 of file zstd_compress.c.

3875 {
3876  ZSTD_inBuffer input = { NULL, 0, 0 };
3877  if (output->pos > output->size) return ERROR(GENERIC);
3878  CHECK_F( ZSTD_compressStream_generic(zcs, output, &input, ZSTD_e_flush) );
3879  return zcs->outBuffContentSize - zcs->outBuffFlushedSize; /* remaining to flush */
3880 }
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
#define ERROR(name)
Definition: error_private.h:53
smooth NULL
Definition: ftsmooth.c:416
#define CHECK_F(f)
Definition: fse_compress.c:661
size_t ZSTD_compressStream_generic(ZSTD_CStream *zcs, ZSTD_outBuffer *output, ZSTD_inBuffer *input, ZSTD_EndDirective const flushMode)
GLenum GLenum GLenum input
Definition: glext.h:9031

◆ ZSTD_freeCCtx()

ZSTDLIB_API size_t ZSTD_freeCCtx ( ZSTD_CCtx cctx)

Definition at line 116 of file zstd_compress.c.

117 {
118  if (cctx==NULL) return 0; /* support free on NULL */
119  if (cctx->staticSize) return ERROR(memory_allocation); /* not compatible with static CCtx */
120  ZSTD_freeCCtxContent(cctx);
121  ZSTD_free(cctx, cctx->customMem);
122  return 0;
123 }
#define ERROR(name)
Definition: error_private.h:53
void ZSTD_free(void *ptr, ZSTD_customMem customMem)
Definition: zstd_common.c:68
smooth NULL
Definition: ftsmooth.c:416
static void ZSTD_freeCCtxContent(ZSTD_CCtx *cctx)
ZSTD_customMem customMem

Referenced by ZSTD_freeCStream().

◆ ZSTD_freeCDict()

ZSTDLIB_API size_t ZSTD_freeCDict ( ZSTD_CDict CDict)

ZSTD_freeCDict() : Function frees memory allocated by ZSTD_createCDict().

Definition at line 3310 of file zstd_compress.c.

3311 {
3312  if (cdict==NULL) return 0; /* support free on NULL */
3313  { ZSTD_customMem const cMem = cdict->customMem;
3314  ZSTD_free(cdict->workspace, cMem);
3315  ZSTD_free(cdict->dictBuffer, cMem);
3316  ZSTD_free(cdict, cMem);
3317  return 0;
3318  }
3319 }
void ZSTD_free(void *ptr, ZSTD_customMem customMem)
Definition: zstd_common.c:68
smooth NULL
Definition: ftsmooth.c:416

Referenced by ZSTD_CCtx_loadDictionary_advanced(), ZSTD_createCDict_advanced(), ZSTD_freeCCtxContent(), and ZSTD_initCStream_internal().

◆ ZSTD_freeCStream()

ZSTDLIB_API size_t ZSTD_freeCStream ( ZSTD_CStream zcs)

Definition at line 3459 of file zstd_compress.c.

3460 {
3461  return ZSTD_freeCCtx(zcs); /* same object */
3462 }
size_t ZSTD_freeCCtx(ZSTD_CCtx *cctx)

Referenced by zstd_write_compressed_bit().

◆ ZSTD_freeDCtx()

ZSTDLIB_API size_t ZSTD_freeDCtx ( ZSTD_DCtx dctx)

Definition at line 253 of file zstd_decompress.c.

254 {
255  if (dctx==NULL) return 0; /* support free on NULL */
256  if (dctx->staticSize) return ERROR(memory_allocation); /* not compatible with static DCtx */
257  { ZSTD_customMem const cMem = dctx->customMem;
258  ZSTD_freeDDict(dctx->ddictLocal);
259  dctx->ddictLocal = NULL;
260  ZSTD_free(dctx->inBuff, cMem);
261  dctx->inBuff = NULL;
262 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
263  if (dctx->legacyContext)
264  ZSTD_freeLegacyStreamContext(dctx->legacyContext, dctx->previousLegacyVersion);
265 #endif
266  ZSTD_free(dctx, cMem);
267  return 0;
268  }
269 }
#define ERROR(name)
Definition: error_private.h:53
void ZSTD_free(void *ptr, ZSTD_customMem customMem)
Definition: zstd_common.c:68
void * legacyContext
smooth NULL
Definition: ftsmooth.c:416
ZSTD_customMem customMem
ZSTD_DDict * ddictLocal
U32 previousLegacyVersion
size_t ZSTD_freeDDict(ZSTD_DDict *ddict)

Referenced by ZSTD_decompress(), and ZSTD_freeDStream().

◆ ZSTD_freeDDict()

ZSTDLIB_API size_t ZSTD_freeDDict ( ZSTD_DDict ddict)

ZSTD_freeDDict() : Function frees memory allocated with ZSTD_createDDict()

Definition at line 2546 of file zstd_decompress.c.

2547 {
2548  if (ddict==NULL) return 0; /* support free on NULL */
2549  { ZSTD_customMem const cMem = ddict->cMem;
2550  ZSTD_free(ddict->dictBuffer, cMem);
2551  ZSTD_free(ddict, cMem);
2552  return 0;
2553  }
2554 }
void ZSTD_free(void *ptr, ZSTD_customMem customMem)
Definition: zstd_common.c:68
smooth NULL
Definition: ftsmooth.c:416
ZSTD_customMem cMem

Referenced by ZSTD_createDDict_advanced(), ZSTD_DCtx_loadDictionary_advanced(), and ZSTD_freeDCtx().

◆ ZSTD_freeDStream()

ZSTDLIB_API size_t ZSTD_freeDStream ( ZSTD_DStream zds)

Definition at line 2648 of file zstd_decompress.c.

2649 {
2650  return ZSTD_freeDCtx(zds);
2651 }
size_t ZSTD_freeDCtx(ZSTD_DCtx *dctx)

Referenced by zstd_decompress().

◆ ZSTD_getDecompressedSize()

ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize ( const void src,
size_t  srcSize 
)

ZSTD_getDecompressedSize() : NOTE: This function is now obsolete, in favor of ZSTD_getFrameContentSize(). Both functions work the same way, but ZSTD_getDecompressedSize() blends "empty", "unknown" and "error" results to the same return value (0), while ZSTD_getFrameContentSize() gives them separate return values.

Returns
: decompressed size of src frame content if known and not empty, 0 otherwise.

ZSTD_getDecompressedSize() : compatible with legacy mode

Returns
: decompressed size if known, 0 otherwise note : 0 can mean any of the following :
  • frame content is empty
  • decompressed size field is not present in frame header
  • frame header unknown / not supported
  • frame header not complete (srcSize too small)

Definition at line 506 of file zstd_decompress.c.

507 {
508  unsigned long long const ret = ZSTD_getFrameContentSize(src, srcSize);
510  return (ret >= ZSTD_CONTENTSIZE_ERROR) ? 0 : ret;
511 }
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
#define ZSTD_STATIC_ASSERT(c)
Definition: zstd_internal.h:43
int ret
GLenum src
Definition: glext.h:6340
unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize)
#define ZSTD_CONTENTSIZE_ERROR
Definition: zstd.h:137

◆ ZSTD_getErrorName()

ZSTDLIB_API const char* ZSTD_getErrorName ( size_t  code)

provides readable string from an error code

ZSTD_getErrorName() : provides error code string from function result (useful for debugging)

Definition at line 39 of file zstd_common.c.

39 { return ERR_getErrorName(code); }
ERR_STATIC const char * ERR_getErrorName(size_t code)
Definition: error_private.h:67

Referenced by zstd_decompress(), and zstd_write_compressed_bit().

◆ ZSTD_getFrameContentSize()

ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize ( const void src,
size_t  srcSize 
)

ZSTD_getFrameContentSize() : compatible with legacy mode

Returns
: decompressed size of the single frame pointed to be src if known, otherwise
  • ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined
  • ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small)

Definition at line 431 of file zstd_decompress.c.

432 {
433 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
434  if (ZSTD_isLegacy(src, srcSize)) {
435  unsigned long long const ret = ZSTD_getDecompressedSize_legacy(src, srcSize);
436  return ret == 0 ? ZSTD_CONTENTSIZE_UNKNOWN : ret;
437  }
438 #endif
439  { ZSTD_frameHeader zfh;
440  if (ZSTD_getFrameHeader(&zfh, src, srcSize) != 0)
441  return ZSTD_CONTENTSIZE_ERROR;
442  if (zfh.frameType == ZSTD_skippableFrame) {
443  return 0;
444  } else {
445  return zfh.frameContentSize;
446  } }
447 }
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
int ret
size_t ZSTD_getFrameHeader(ZSTD_frameHeader *zfhPtr, const void *src, size_t srcSize)
GLenum src
Definition: glext.h:6340
#define ZSTD_CONTENTSIZE_ERROR
Definition: zstd.h:137

Referenced by ZSTD_findDecompressedSize(), and ZSTD_getDecompressedSize().

◆ ZSTD_initCStream()

ZSTDLIB_API size_t ZSTD_initCStream ( ZSTD_CStream zcs,
int  compressionLevel 
)

Definition at line 3607 of file zstd_compress.c.

3608 {
3609  DEBUGLOG(4, "ZSTD_initCStream");
3610  return ZSTD_initCStream_srcSize(zcs, compressionLevel, ZSTD_CONTENTSIZE_UNKNOWN);
3611 }
size_t ZSTD_initCStream_srcSize(ZSTD_CStream *zcs, int compressionLevel, unsigned long long pss)
#define ZSTD_CONTENTSIZE_UNKNOWN
Definition: zstd.h:136
#define DEBUGLOG(l,...)
Definition: debug.h:115

◆ ZSTD_initDStream()

ZSTDLIB_API size_t ZSTD_initDStream ( ZSTD_DStream zds)

Definition at line 2710 of file zstd_decompress.c.

2711 {
2712  DEBUGLOG(4, "ZSTD_initDStream");
2713  return ZSTD_initDStream_usingDict(zds, NULL, 0);
2714 }
size_t ZSTD_initDStream_usingDict(ZSTD_DStream *zds, const void *dict, size_t dictSize)
#define DEBUGLOG(l,...)
Definition: debug.h:115
smooth NULL
Definition: ftsmooth.c:416

Referenced by ZSTD_DCtx_reset(), zstd_decompress(), and ZSTD_initDStream_usingDDict().

◆ ZSTD_isError()

ZSTDLIB_API unsigned ZSTD_isError ( size_t  code)

tells if a size_t function result is an error code

ZSTD_isError() : tells if a return value is an error code

Definition at line 35 of file zstd_common.c.

35 { return ERR_isError(code); }
ERR_STATIC unsigned ERR_isError(size_t code)
Definition: error_private.h:56

◆ ZSTD_maxCLevel()

ZSTDLIB_API int ZSTD_maxCLevel ( void  )

maximum compression level available

Definition at line 3900 of file zstd_compress.c.

3900 { return ZSTD_MAX_CLEVEL; }
#define ZSTD_MAX_CLEVEL

Referenced by registry_load_volume_options(), and ZSTD_CCtxParam_setParameter().

◆ ZSTD_versionNumber()

ZSTDLIB_API unsigned ZSTD_versionNumber ( void  )

useful to check dll version

Definition at line 25 of file zstd_common.c.

25 { return ZSTD_VERSION_NUMBER; }
#define ZSTD_VERSION_NUMBER
Definition: zstd.h:76

◆ ZSTD_versionString()

ZSTDLIB_API const char* ZSTD_versionString ( void  )

Definition at line 27 of file zstd_common.c.

27 { return ZSTD_VERSION_STRING; }
#define ZSTD_VERSION_STRING
Definition: zstd.h:82