Path: blob/main/sys/contrib/zstd/lib/legacy/zstd_v04.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 ZSTD_V04_H_9186832476923811#define ZSTD_V04_H_918683247692381213#if defined (__cplusplus)14extern "C" {15#endif1617/* *************************************18* Includes19***************************************/20#include <stddef.h> /* size_t */212223/* *************************************24* Simple one-step function25***************************************/26/**27ZSTDv04_decompress() : decompress ZSTD frames compliant with v0.4.x format28compressedSize : is the exact source size29maxOriginalSize : is the size of the 'dst' buffer, which must be already allocated.30It must be equal or larger than originalSize, otherwise decompression will fail.31return : the number of bytes decompressed into destination buffer (originalSize)32or an errorCode if it fails (which can be tested using ZSTDv01_isError())33*/34size_t ZSTDv04_decompress( void* dst, size_t maxOriginalSize,35const void* src, size_t compressedSize);3637/**38ZSTDv04_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.4.x format39srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'40cSize (output parameter) : the number of bytes that would be read to decompress this frame41or an error code if it fails (which can be tested using ZSTDv01_isError())42dBound (output parameter) : an upper-bound for the decompressed size of the data in the frame43or ZSTD_CONTENTSIZE_ERROR if an error occurs4445note : assumes `cSize` and `dBound` are _not_ NULL.46*/47void ZSTDv04_findFrameSizeInfoLegacy(const void *src, size_t srcSize,48size_t* cSize, unsigned long long* dBound);4950/**51ZSTDv04_isError() : tells if the result of ZSTDv04_decompress() is an error52*/53unsigned ZSTDv04_isError(size_t code);545556/* *************************************57* Advanced functions58***************************************/59typedef struct ZSTDv04_Dctx_s ZSTDv04_Dctx;60ZSTDv04_Dctx* ZSTDv04_createDCtx(void);61size_t ZSTDv04_freeDCtx(ZSTDv04_Dctx* dctx);6263size_t ZSTDv04_decompressDCtx(ZSTDv04_Dctx* dctx,64void* dst, size_t maxOriginalSize,65const void* src, size_t compressedSize);666768/* *************************************69* Direct Streaming70***************************************/71size_t ZSTDv04_resetDCtx(ZSTDv04_Dctx* dctx);7273size_t ZSTDv04_nextSrcSizeToDecompress(ZSTDv04_Dctx* dctx);74size_t ZSTDv04_decompressContinue(ZSTDv04_Dctx* dctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize);75/**76Use above functions alternatively.77ZSTD_nextSrcSizeToDecompress() tells how much bytes to provide as 'srcSize' to ZSTD_decompressContinue().78ZSTD_decompressContinue() will use previous data blocks to improve compression if they are located prior to current block.79Result is the number of bytes regenerated within 'dst'.80It can be zero, which is not an error; it just means ZSTD_decompressContinue() has decoded some header.81*/828384/* *************************************85* Buffered Streaming86***************************************/87typedef struct ZBUFFv04_DCtx_s ZBUFFv04_DCtx;88ZBUFFv04_DCtx* ZBUFFv04_createDCtx(void);89size_t ZBUFFv04_freeDCtx(ZBUFFv04_DCtx* dctx);9091size_t ZBUFFv04_decompressInit(ZBUFFv04_DCtx* dctx);92size_t ZBUFFv04_decompressWithDictionary(ZBUFFv04_DCtx* dctx, const void* dict, size_t dictSize);9394size_t ZBUFFv04_decompressContinue(ZBUFFv04_DCtx* dctx, void* dst, size_t* maxDstSizePtr, const void* src, size_t* srcSizePtr);9596/** ************************************************97* Streaming decompression98*99* A ZBUFF_DCtx object is required to track streaming operation.100* Use ZBUFF_createDCtx() and ZBUFF_freeDCtx() to create/release resources.101* Use ZBUFF_decompressInit() to start a new decompression operation.102* ZBUFF_DCtx objects can be reused multiple times.103*104* Optionally, a reference to a static dictionary can be set, using ZBUFF_decompressWithDictionary()105* It must be the same content as the one set during compression phase.106* Dictionary content must remain accessible during the decompression process.107*108* Use ZBUFF_decompressContinue() repetitively to consume your input.109* *srcSizePtr and *maxDstSizePtr can be any size.110* The function will report how many bytes were read or written by modifying *srcSizePtr and *maxDstSizePtr.111* Note that it may not consume the entire input, in which case it's up to the caller to present remaining input again.112* The content of dst will be overwritten (up to *maxDstSizePtr) at each function call, so save its content if it matters or change dst.113* @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to improve latency)114* or 0 when a frame is completely decoded115* or an error code, which can be tested using ZBUFF_isError().116*117* Hint : recommended buffer sizes (not compulsory) : ZBUFF_recommendedDInSize / ZBUFF_recommendedDOutSize118* output : ZBUFF_recommendedDOutSize==128 KB block size is the internal unit, it ensures it's always possible to write a full block when it's decoded.119* input : ZBUFF_recommendedDInSize==128Kb+3; just follow indications from ZBUFF_decompressContinue() to minimize latency. It should always be <= 128 KB + 3 .120* **************************************************/121unsigned ZBUFFv04_isError(size_t errorCode);122const char* ZBUFFv04_getErrorName(size_t errorCode);123124125/** The below functions provide recommended buffer sizes for Compression or Decompression operations.126* These sizes are not compulsory, they just tend to offer better latency */127size_t ZBUFFv04_recommendedDInSize(void);128size_t ZBUFFv04_recommendedDOutSize(void);129130131/* *************************************132* Prefix - version detection133***************************************/134#define ZSTDv04_magicNumber 0xFD2FB524 /* v0.4 */135136137#if defined (__cplusplus)138}139#endif140141#endif /* ZSTD_V04_H_91868324769238 */142143144