Path: blob/main/sys/contrib/zstd/lib/legacy/zstd_v05.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 ZSTDv05_H11#define ZSTDv05_H1213#if defined (__cplusplus)14extern "C" {15#endif1617/*-*************************************18* Dependencies19***************************************/20#include <stddef.h> /* size_t */21#include "../common/mem.h" /* U64, U32 */222324/* *************************************25* Simple functions26***************************************/27/*! ZSTDv05_decompress() :28`compressedSize` : is the _exact_ size of the compressed blob, otherwise decompression will fail.29`dstCapacity` must be large enough, equal or larger than originalSize.30@return : the number of bytes decompressed into `dst` (<= `dstCapacity`),31or an errorCode if it fails (which can be tested using ZSTDv05_isError()) */32size_t ZSTDv05_decompress( void* dst, size_t dstCapacity,33const void* src, size_t compressedSize);3435/**36ZSTDv05_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.5.x format37srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'38cSize (output parameter) : the number of bytes that would be read to decompress this frame39or an error code if it fails (which can be tested using ZSTDv01_isError())40dBound (output parameter) : an upper-bound for the decompressed size of the data in the frame41or ZSTD_CONTENTSIZE_ERROR if an error occurs4243note : assumes `cSize` and `dBound` are _not_ NULL.44*/45void ZSTDv05_findFrameSizeInfoLegacy(const void *src, size_t srcSize,46size_t* cSize, unsigned long long* dBound);4748/* *************************************49* Helper functions50***************************************/51/* Error Management */52unsigned ZSTDv05_isError(size_t code); /*!< tells if a `size_t` function result is an error code */53const char* ZSTDv05_getErrorName(size_t code); /*!< provides readable string for an error code */545556/* *************************************57* Explicit memory management58***************************************/59/** Decompression context */60typedef struct ZSTDv05_DCtx_s ZSTDv05_DCtx;61ZSTDv05_DCtx* ZSTDv05_createDCtx(void);62size_t ZSTDv05_freeDCtx(ZSTDv05_DCtx* dctx); /*!< @return : errorCode */6364/** ZSTDv05_decompressDCtx() :65* Same as ZSTDv05_decompress(), but requires an already allocated ZSTDv05_DCtx (see ZSTDv05_createDCtx()) */66size_t ZSTDv05_decompressDCtx(ZSTDv05_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);676869/*-***********************70* Simple Dictionary API71*************************/72/*! ZSTDv05_decompress_usingDict() :73* Decompression using a pre-defined Dictionary content (see dictBuilder).74* Dictionary must be identical to the one used during compression, otherwise regenerated data will be corrupted.75* Note : dict can be NULL, in which case, it's equivalent to ZSTDv05_decompressDCtx() */76size_t ZSTDv05_decompress_usingDict(ZSTDv05_DCtx* dctx,77void* dst, size_t dstCapacity,78const void* src, size_t srcSize,79const void* dict,size_t dictSize);8081/*-************************82* Advanced Streaming API83***************************/84typedef enum { ZSTDv05_fast, ZSTDv05_greedy, ZSTDv05_lazy, ZSTDv05_lazy2, ZSTDv05_btlazy2, ZSTDv05_opt, ZSTDv05_btopt } ZSTDv05_strategy;85typedef struct {86U64 srcSize;87U32 windowLog; /* the only useful information to retrieve */88U32 contentLog; U32 hashLog; U32 searchLog; U32 searchLength; U32 targetLength; ZSTDv05_strategy strategy;89} ZSTDv05_parameters;90size_t ZSTDv05_getFrameParams(ZSTDv05_parameters* params, const void* src, size_t srcSize);9192size_t ZSTDv05_decompressBegin_usingDict(ZSTDv05_DCtx* dctx, const void* dict, size_t dictSize);93void ZSTDv05_copyDCtx(ZSTDv05_DCtx* dstDCtx, const ZSTDv05_DCtx* srcDCtx);94size_t ZSTDv05_nextSrcSizeToDecompress(ZSTDv05_DCtx* dctx);95size_t ZSTDv05_decompressContinue(ZSTDv05_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);969798/*-***********************99* ZBUFF API100*************************/101typedef struct ZBUFFv05_DCtx_s ZBUFFv05_DCtx;102ZBUFFv05_DCtx* ZBUFFv05_createDCtx(void);103size_t ZBUFFv05_freeDCtx(ZBUFFv05_DCtx* dctx);104105size_t ZBUFFv05_decompressInit(ZBUFFv05_DCtx* dctx);106size_t ZBUFFv05_decompressInitDictionary(ZBUFFv05_DCtx* dctx, const void* dict, size_t dictSize);107108size_t ZBUFFv05_decompressContinue(ZBUFFv05_DCtx* dctx,109void* dst, size_t* dstCapacityPtr,110const void* src, size_t* srcSizePtr);111112/*-***************************************************************************113* Streaming decompression114*115* A ZBUFFv05_DCtx object is required to track streaming operations.116* Use ZBUFFv05_createDCtx() and ZBUFFv05_freeDCtx() to create/release resources.117* Use ZBUFFv05_decompressInit() to start a new decompression operation,118* or ZBUFFv05_decompressInitDictionary() if decompression requires a dictionary.119* Note that ZBUFFv05_DCtx objects can be reused multiple times.120*121* Use ZBUFFv05_decompressContinue() repetitively to consume your input.122* *srcSizePtr and *dstCapacityPtr can be any size.123* The function will report how many bytes were read or written by modifying *srcSizePtr and *dstCapacityPtr.124* Note that it may not consume the entire input, in which case it's up to the caller to present remaining input again.125* The content of @dst will be overwritten (up to *dstCapacityPtr) at each function call, so save its content if it matters or change @dst.126* @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to help latency)127* or 0 when a frame is completely decoded128* or an error code, which can be tested using ZBUFFv05_isError().129*130* Hint : recommended buffer sizes (not compulsory) : ZBUFFv05_recommendedDInSize() / ZBUFFv05_recommendedDOutSize()131* output : ZBUFFv05_recommendedDOutSize==128 KB block size is the internal unit, it ensures it's always possible to write a full block when decoded.132* input : ZBUFFv05_recommendedDInSize==128Kb+3; just follow indications from ZBUFFv05_decompressContinue() to minimize latency. It should always be <= 128 KB + 3 .133* *******************************************************************************/134135136/* *************************************137* Tool functions138***************************************/139unsigned ZBUFFv05_isError(size_t errorCode);140const char* ZBUFFv05_getErrorName(size_t errorCode);141142/** Functions below provide recommended buffer sizes for Compression or Decompression operations.143* These sizes are just hints, and tend to offer better latency */144size_t ZBUFFv05_recommendedDInSize(void);145size_t ZBUFFv05_recommendedDOutSize(void);146147148149/*-*************************************150* Constants151***************************************/152#define ZSTDv05_MAGICNUMBER 0xFD2FB525 /* v0.5 */153154155156157#if defined (__cplusplus)158}159#endif160161#endif /* ZSTDv0505_H */162163164