[8ebc79b] | 1 | /* |
---|
| 2 | zstd_v06 - decoder for 0.6 format |
---|
| 3 | Header File |
---|
| 4 | Copyright (C) 2014-2016, Yann Collet. |
---|
| 5 | |
---|
| 6 | BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) |
---|
| 7 | |
---|
| 8 | Redistribution and use in source and binary forms, with or without |
---|
| 9 | modification, are permitted provided that the following conditions are |
---|
| 10 | met: |
---|
| 11 | * Redistributions of source code must retain the above copyright |
---|
| 12 | notice, this list of conditions and the following disclaimer. |
---|
| 13 | * Redistributions in binary form must reproduce the above |
---|
| 14 | copyright notice, this list of conditions and the following disclaimer |
---|
| 15 | in the documentation and/or other materials provided with the |
---|
| 16 | distribution. |
---|
| 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
| 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
| 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
| 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
| 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
| 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
| 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
| 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
| 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 28 | |
---|
| 29 | You can contact the author at : |
---|
| 30 | - zstd source repository : https://github.com/Cyan4973/zstd |
---|
| 31 | */ |
---|
| 32 | #ifndef ZSTDv06_H |
---|
| 33 | #define ZSTDv06_H |
---|
| 34 | |
---|
| 35 | #if defined (__cplusplus) |
---|
| 36 | extern "C" { |
---|
| 37 | #endif |
---|
| 38 | |
---|
| 39 | /*-************************************* |
---|
| 40 | * Dependencies |
---|
| 41 | ***************************************/ |
---|
| 42 | #include <stddef.h> /* size_t */ |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | /*-*************************************************************** |
---|
| 46 | * Export parameters |
---|
| 47 | *****************************************************************/ |
---|
| 48 | /*! |
---|
| 49 | * ZSTDv06_DLL_EXPORT : |
---|
| 50 | * Enable exporting of functions when building a Windows DLL |
---|
| 51 | */ |
---|
| 52 | #if defined(_WIN32) && defined(ZSTDv06_DLL_EXPORT) && (ZSTDv06_DLL_EXPORT==1) |
---|
| 53 | # define ZSTDLIB_API __declspec(dllexport) |
---|
| 54 | #else |
---|
| 55 | # define ZSTDLIB_API |
---|
| 56 | #endif |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | /* ************************************* |
---|
| 60 | * Simple functions |
---|
| 61 | ***************************************/ |
---|
| 62 | /*! ZSTDv06_decompress() : |
---|
| 63 | `compressedSize` : is the _exact_ size of the compressed blob, otherwise decompression will fail. |
---|
| 64 | `dstCapacity` must be large enough, equal or larger than originalSize. |
---|
| 65 | @return : the number of bytes decompressed into `dst` (<= `dstCapacity`), |
---|
| 66 | or an errorCode if it fails (which can be tested using ZSTDv06_isError()) */ |
---|
| 67 | ZSTDLIB_API size_t ZSTDv06_decompress( void* dst, size_t dstCapacity, |
---|
| 68 | const void* src, size_t compressedSize); |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | /* ************************************* |
---|
| 72 | * Helper functions |
---|
| 73 | ***************************************/ |
---|
| 74 | ZSTDLIB_API size_t ZSTDv06_compressBound(size_t srcSize); /*!< maximum compressed size (worst case scenario) */ |
---|
| 75 | |
---|
| 76 | /* Error Management */ |
---|
| 77 | ZSTDLIB_API unsigned ZSTDv06_isError(size_t code); /*!< tells if a `size_t` function result is an error code */ |
---|
| 78 | ZSTDLIB_API const char* ZSTDv06_getErrorName(size_t code); /*!< provides readable string for an error code */ |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | /* ************************************* |
---|
| 82 | * Explicit memory management |
---|
| 83 | ***************************************/ |
---|
| 84 | /** Decompression context */ |
---|
| 85 | typedef struct ZSTDv06_DCtx_s ZSTDv06_DCtx; |
---|
| 86 | ZSTDLIB_API ZSTDv06_DCtx* ZSTDv06_createDCtx(void); |
---|
| 87 | ZSTDLIB_API size_t ZSTDv06_freeDCtx(ZSTDv06_DCtx* dctx); /*!< @return : errorCode */ |
---|
| 88 | |
---|
| 89 | /** ZSTDv06_decompressDCtx() : |
---|
| 90 | * Same as ZSTDv06_decompress(), but requires an already allocated ZSTDv06_DCtx (see ZSTDv06_createDCtx()) */ |
---|
| 91 | ZSTDLIB_API size_t ZSTDv06_decompressDCtx(ZSTDv06_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | /*-*********************** |
---|
| 95 | * Dictionary API |
---|
| 96 | *************************/ |
---|
| 97 | /*! ZSTDv06_decompress_usingDict() : |
---|
| 98 | * Decompression using a pre-defined Dictionary content (see dictBuilder). |
---|
| 99 | * Dictionary must be identical to the one used during compression, otherwise regenerated data will be corrupted. |
---|
| 100 | * Note : dict can be NULL, in which case, it's equivalent to ZSTDv06_decompressDCtx() */ |
---|
| 101 | ZSTDLIB_API size_t ZSTDv06_decompress_usingDict(ZSTDv06_DCtx* dctx, |
---|
| 102 | void* dst, size_t dstCapacity, |
---|
| 103 | const void* src, size_t srcSize, |
---|
| 104 | const void* dict,size_t dictSize); |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | /*-************************ |
---|
| 108 | * Advanced Streaming API |
---|
| 109 | ***************************/ |
---|
| 110 | struct ZSTDv06_frameParams_s { unsigned long long frameContentSize; unsigned windowLog; }; |
---|
| 111 | typedef struct ZSTDv06_frameParams_s ZSTDv06_frameParams; |
---|
| 112 | |
---|
| 113 | ZSTDLIB_API size_t ZSTDv06_getFrameParams(ZSTDv06_frameParams* fparamsPtr, const void* src, size_t srcSize); /**< doesn't consume input */ |
---|
| 114 | ZSTDLIB_API size_t ZSTDv06_decompressBegin_usingDict(ZSTDv06_DCtx* dctx, const void* dict, size_t dictSize); |
---|
| 115 | ZSTDLIB_API void ZSTDv06_copyDCtx(ZSTDv06_DCtx* dctx, const ZSTDv06_DCtx* preparedDCtx); |
---|
| 116 | |
---|
| 117 | ZSTDLIB_API size_t ZSTDv06_nextSrcSizeToDecompress(ZSTDv06_DCtx* dctx); |
---|
| 118 | ZSTDLIB_API size_t ZSTDv06_decompressContinue(ZSTDv06_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | /* ************************************* |
---|
| 123 | * ZBUFF API |
---|
| 124 | ***************************************/ |
---|
| 125 | |
---|
| 126 | typedef struct ZBUFFv06_DCtx_s ZBUFFv06_DCtx; |
---|
| 127 | ZSTDLIB_API ZBUFFv06_DCtx* ZBUFFv06_createDCtx(void); |
---|
| 128 | ZSTDLIB_API size_t ZBUFFv06_freeDCtx(ZBUFFv06_DCtx* dctx); |
---|
| 129 | |
---|
| 130 | ZSTDLIB_API size_t ZBUFFv06_decompressInit(ZBUFFv06_DCtx* dctx); |
---|
| 131 | ZSTDLIB_API size_t ZBUFFv06_decompressInitDictionary(ZBUFFv06_DCtx* dctx, const void* dict, size_t dictSize); |
---|
| 132 | |
---|
| 133 | ZSTDLIB_API size_t ZBUFFv06_decompressContinue(ZBUFFv06_DCtx* dctx, |
---|
| 134 | void* dst, size_t* dstCapacityPtr, |
---|
| 135 | const void* src, size_t* srcSizePtr); |
---|
| 136 | |
---|
| 137 | /*-*************************************************************************** |
---|
| 138 | * Streaming decompression howto |
---|
| 139 | * |
---|
| 140 | * A ZBUFFv06_DCtx object is required to track streaming operations. |
---|
| 141 | * Use ZBUFFv06_createDCtx() and ZBUFFv06_freeDCtx() to create/release resources. |
---|
| 142 | * Use ZBUFFv06_decompressInit() to start a new decompression operation, |
---|
| 143 | * or ZBUFFv06_decompressInitDictionary() if decompression requires a dictionary. |
---|
| 144 | * Note that ZBUFFv06_DCtx objects can be re-init multiple times. |
---|
| 145 | * |
---|
| 146 | * Use ZBUFFv06_decompressContinue() repetitively to consume your input. |
---|
| 147 | * *srcSizePtr and *dstCapacityPtr can be any size. |
---|
| 148 | * The function will report how many bytes were read or written by modifying *srcSizePtr and *dstCapacityPtr. |
---|
| 149 | * Note that it may not consume the entire input, in which case it's up to the caller to present remaining input again. |
---|
| 150 | * The content of `dst` will be overwritten (up to *dstCapacityPtr) at each function call, so save its content if it matters, or change `dst`. |
---|
| 151 | * @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to help latency), |
---|
| 152 | * or 0 when a frame is completely decoded, |
---|
| 153 | * or an error code, which can be tested using ZBUFFv06_isError(). |
---|
| 154 | * |
---|
| 155 | * Hint : recommended buffer sizes (not compulsory) : ZBUFFv06_recommendedDInSize() and ZBUFFv06_recommendedDOutSize() |
---|
| 156 | * output : ZBUFFv06_recommendedDOutSize== 128 KB block size is the internal unit, it ensures it's always possible to write a full block when decoded. |
---|
| 157 | * input : ZBUFFv06_recommendedDInSize == 128KB + 3; |
---|
| 158 | * just follow indications from ZBUFFv06_decompressContinue() to minimize latency. It should always be <= 128 KB + 3 . |
---|
| 159 | * *******************************************************************************/ |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | /* ************************************* |
---|
| 163 | * Tool functions |
---|
| 164 | ***************************************/ |
---|
| 165 | ZSTDLIB_API unsigned ZBUFFv06_isError(size_t errorCode); |
---|
| 166 | ZSTDLIB_API const char* ZBUFFv06_getErrorName(size_t errorCode); |
---|
| 167 | |
---|
| 168 | /** Functions below provide recommended buffer sizes for Compression or Decompression operations. |
---|
| 169 | * These sizes are just hints, they tend to offer better latency */ |
---|
| 170 | ZSTDLIB_API size_t ZBUFFv06_recommendedDInSize(void); |
---|
| 171 | ZSTDLIB_API size_t ZBUFFv06_recommendedDOutSize(void); |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | /*-************************************* |
---|
| 175 | * Constants |
---|
| 176 | ***************************************/ |
---|
| 177 | #define ZSTDv06_MAGICNUMBER 0xFD2FB526 /* v0.6 */ |
---|
| 178 | |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | #if defined (__cplusplus) |
---|
| 182 | } |
---|
| 183 | #endif |
---|
| 184 | |
---|
| 185 | #endif /* ZSTDv06_BUFFERED_H */ |
---|