Path: blob/main/sys/contrib/zstd/lib/legacy/zstd_v06.h
48378 views
/*1* Copyright (c) Yann Collet, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under both the BSD-style license (found in the5* LICENSE file in the root directory of this source tree) and the GPLv2 (found6* in the COPYING file in the root directory of this source tree).7* You may select, at your option, one of the above-listed licenses.8*/910#ifndef ZSTDv06_H11#define ZSTDv06_H1213#if defined (__cplusplus)14extern "C" {15#endif1617/*====== Dependency ======*/18#include <stddef.h> /* size_t */192021/*====== Export for Windows ======*/22/*!23* ZSTDv06_DLL_EXPORT :24* Enable exporting of functions when building a Windows DLL25*/26#if defined(_WIN32) && defined(ZSTDv06_DLL_EXPORT) && (ZSTDv06_DLL_EXPORT==1)27# define ZSTDLIBv06_API __declspec(dllexport)28#else29# define ZSTDLIBv06_API30#endif313233/* *************************************34* Simple functions35***************************************/36/*! ZSTDv06_decompress() :37`compressedSize` : is the _exact_ size of the compressed blob, otherwise decompression will fail.38`dstCapacity` must be large enough, equal or larger than originalSize.39@return : the number of bytes decompressed into `dst` (<= `dstCapacity`),40or an errorCode if it fails (which can be tested using ZSTDv06_isError()) */41ZSTDLIBv06_API size_t ZSTDv06_decompress( void* dst, size_t dstCapacity,42const void* src, size_t compressedSize);4344/**45ZSTDv06_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.6.x format46srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'47cSize (output parameter) : the number of bytes that would be read to decompress this frame48or an error code if it fails (which can be tested using ZSTDv01_isError())49dBound (output parameter) : an upper-bound for the decompressed size of the data in the frame50or ZSTD_CONTENTSIZE_ERROR if an error occurs5152note : assumes `cSize` and `dBound` are _not_ NULL.53*/54void ZSTDv06_findFrameSizeInfoLegacy(const void *src, size_t srcSize,55size_t* cSize, unsigned long long* dBound);5657/* *************************************58* Helper functions59***************************************/60ZSTDLIBv06_API size_t ZSTDv06_compressBound(size_t srcSize); /*!< maximum compressed size (worst case scenario) */6162/* Error Management */63ZSTDLIBv06_API unsigned ZSTDv06_isError(size_t code); /*!< tells if a `size_t` function result is an error code */64ZSTDLIBv06_API const char* ZSTDv06_getErrorName(size_t code); /*!< provides readable string for an error code */656667/* *************************************68* Explicit memory management69***************************************/70/** Decompression context */71typedef struct ZSTDv06_DCtx_s ZSTDv06_DCtx;72ZSTDLIBv06_API ZSTDv06_DCtx* ZSTDv06_createDCtx(void);73ZSTDLIBv06_API size_t ZSTDv06_freeDCtx(ZSTDv06_DCtx* dctx); /*!< @return : errorCode */7475/** ZSTDv06_decompressDCtx() :76* Same as ZSTDv06_decompress(), but requires an already allocated ZSTDv06_DCtx (see ZSTDv06_createDCtx()) */77ZSTDLIBv06_API size_t ZSTDv06_decompressDCtx(ZSTDv06_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);787980/*-***********************81* Dictionary API82*************************/83/*! ZSTDv06_decompress_usingDict() :84* Decompression using a pre-defined Dictionary content (see dictBuilder).85* Dictionary must be identical to the one used during compression, otherwise regenerated data will be corrupted.86* Note : dict can be NULL, in which case, it's equivalent to ZSTDv06_decompressDCtx() */87ZSTDLIBv06_API size_t ZSTDv06_decompress_usingDict(ZSTDv06_DCtx* dctx,88void* dst, size_t dstCapacity,89const void* src, size_t srcSize,90const void* dict,size_t dictSize);919293/*-************************94* Advanced Streaming API95***************************/96struct ZSTDv06_frameParams_s { unsigned long long frameContentSize; unsigned windowLog; };97typedef struct ZSTDv06_frameParams_s ZSTDv06_frameParams;9899ZSTDLIBv06_API size_t ZSTDv06_getFrameParams(ZSTDv06_frameParams* fparamsPtr, const void* src, size_t srcSize); /**< doesn't consume input */100ZSTDLIBv06_API size_t ZSTDv06_decompressBegin_usingDict(ZSTDv06_DCtx* dctx, const void* dict, size_t dictSize);101ZSTDLIBv06_API void ZSTDv06_copyDCtx(ZSTDv06_DCtx* dctx, const ZSTDv06_DCtx* preparedDCtx);102103ZSTDLIBv06_API size_t ZSTDv06_nextSrcSizeToDecompress(ZSTDv06_DCtx* dctx);104ZSTDLIBv06_API size_t ZSTDv06_decompressContinue(ZSTDv06_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);105106107108/* *************************************109* ZBUFF API110***************************************/111112typedef struct ZBUFFv06_DCtx_s ZBUFFv06_DCtx;113ZSTDLIBv06_API ZBUFFv06_DCtx* ZBUFFv06_createDCtx(void);114ZSTDLIBv06_API size_t ZBUFFv06_freeDCtx(ZBUFFv06_DCtx* dctx);115116ZSTDLIBv06_API size_t ZBUFFv06_decompressInit(ZBUFFv06_DCtx* dctx);117ZSTDLIBv06_API size_t ZBUFFv06_decompressInitDictionary(ZBUFFv06_DCtx* dctx, const void* dict, size_t dictSize);118119ZSTDLIBv06_API size_t ZBUFFv06_decompressContinue(ZBUFFv06_DCtx* dctx,120void* dst, size_t* dstCapacityPtr,121const void* src, size_t* srcSizePtr);122123/*-***************************************************************************124* Streaming decompression howto125*126* A ZBUFFv06_DCtx object is required to track streaming operations.127* Use ZBUFFv06_createDCtx() and ZBUFFv06_freeDCtx() to create/release resources.128* Use ZBUFFv06_decompressInit() to start a new decompression operation,129* or ZBUFFv06_decompressInitDictionary() if decompression requires a dictionary.130* Note that ZBUFFv06_DCtx objects can be re-init multiple times.131*132* Use ZBUFFv06_decompressContinue() repetitively to consume your input.133* *srcSizePtr and *dstCapacityPtr can be any size.134* The function will report how many bytes were read or written by modifying *srcSizePtr and *dstCapacityPtr.135* Note that it may not consume the entire input, in which case it's up to the caller to present remaining input again.136* The content of `dst` will be overwritten (up to *dstCapacityPtr) at each function call, so save its content if it matters, or change `dst`.137* @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to help latency),138* or 0 when a frame is completely decoded,139* or an error code, which can be tested using ZBUFFv06_isError().140*141* Hint : recommended buffer sizes (not compulsory) : ZBUFFv06_recommendedDInSize() and ZBUFFv06_recommendedDOutSize()142* output : ZBUFFv06_recommendedDOutSize== 128 KB block size is the internal unit, it ensures it's always possible to write a full block when decoded.143* input : ZBUFFv06_recommendedDInSize == 128KB + 3;144* just follow indications from ZBUFFv06_decompressContinue() to minimize latency. It should always be <= 128 KB + 3 .145* *******************************************************************************/146147148/* *************************************149* Tool functions150***************************************/151ZSTDLIBv06_API unsigned ZBUFFv06_isError(size_t errorCode);152ZSTDLIBv06_API const char* ZBUFFv06_getErrorName(size_t errorCode);153154/** Functions below provide recommended buffer sizes for Compression or Decompression operations.155* These sizes are just hints, they tend to offer better latency */156ZSTDLIBv06_API size_t ZBUFFv06_recommendedDInSize(void);157ZSTDLIBv06_API size_t ZBUFFv06_recommendedDOutSize(void);158159160/*-*************************************161* Constants162***************************************/163#define ZSTDv06_MAGICNUMBER 0xFD2FB526 /* v0.6 */164165166167#if defined (__cplusplus)168}169#endif170171#endif /* ZSTDv06_BUFFERED_H */172173174