[8ebc79b] | 1 | /* |
---|
| 2 | zstd_v04 - decoder for 0.4 format |
---|
| 3 | Header File |
---|
| 4 | Copyright (C) 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 | - ztsd public forum : https://groups.google.com/forum/#!forum/lz4c |
---|
| 32 | */ |
---|
| 33 | #pragma once |
---|
| 34 | |
---|
| 35 | #if defined (__cplusplus) |
---|
| 36 | extern "C" { |
---|
| 37 | #endif |
---|
| 38 | |
---|
| 39 | /* ************************************* |
---|
| 40 | * Includes |
---|
| 41 | ***************************************/ |
---|
| 42 | #include <stddef.h> /* size_t */ |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | /* ************************************* |
---|
| 46 | * Simple one-step function |
---|
| 47 | ***************************************/ |
---|
| 48 | /** |
---|
| 49 | ZSTDv04_decompress() : decompress ZSTD frames compliant with v0.4.x format |
---|
| 50 | compressedSize : is the exact source size |
---|
| 51 | maxOriginalSize : is the size of the 'dst' buffer, which must be already allocated. |
---|
| 52 | It must be equal or larger than originalSize, otherwise decompression will fail. |
---|
| 53 | return : the number of bytes decompressed into destination buffer (originalSize) |
---|
| 54 | or an errorCode if it fails (which can be tested using ZSTDv01_isError()) |
---|
| 55 | */ |
---|
| 56 | size_t ZSTDv04_decompress( void* dst, size_t maxOriginalSize, |
---|
| 57 | const void* src, size_t compressedSize); |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | ZSTDv04_isError() : tells if the result of ZSTDv04_decompress() is an error |
---|
| 61 | */ |
---|
| 62 | unsigned ZSTDv04_isError(size_t code); |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | /* ************************************* |
---|
| 66 | * Advanced functions |
---|
| 67 | ***************************************/ |
---|
| 68 | typedef struct ZSTDv04_Dctx_s ZSTDv04_Dctx; |
---|
| 69 | ZSTDv04_Dctx* ZSTDv04_createDCtx(void); |
---|
| 70 | size_t ZSTDv04_freeDCtx(ZSTDv04_Dctx* dctx); |
---|
| 71 | |
---|
| 72 | size_t ZSTDv04_decompressDCtx(ZSTDv04_Dctx* dctx, |
---|
| 73 | void* dst, size_t maxOriginalSize, |
---|
| 74 | const void* src, size_t compressedSize); |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | /* ************************************* |
---|
| 78 | * Direct Streaming |
---|
| 79 | ***************************************/ |
---|
| 80 | size_t ZSTDv04_resetDCtx(ZSTDv04_Dctx* dctx); |
---|
| 81 | |
---|
| 82 | size_t ZSTDv04_nextSrcSizeToDecompress(ZSTDv04_Dctx* dctx); |
---|
| 83 | size_t ZSTDv04_decompressContinue(ZSTDv04_Dctx* dctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize); |
---|
| 84 | /** |
---|
| 85 | Use above functions alternatively. |
---|
| 86 | ZSTD_nextSrcSizeToDecompress() tells how much bytes to provide as 'srcSize' to ZSTD_decompressContinue(). |
---|
| 87 | ZSTD_decompressContinue() will use previous data blocks to improve compression if they are located prior to current block. |
---|
| 88 | Result is the number of bytes regenerated within 'dst'. |
---|
| 89 | It can be zero, which is not an error; it just means ZSTD_decompressContinue() has decoded some header. |
---|
| 90 | */ |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | /* ************************************* |
---|
| 94 | * Buffered Streaming |
---|
| 95 | ***************************************/ |
---|
| 96 | typedef struct ZBUFFv04_DCtx_s ZBUFFv04_DCtx; |
---|
| 97 | ZBUFFv04_DCtx* ZBUFFv04_createDCtx(void); |
---|
| 98 | size_t ZBUFFv04_freeDCtx(ZBUFFv04_DCtx* dctx); |
---|
| 99 | |
---|
| 100 | size_t ZBUFFv04_decompressInit(ZBUFFv04_DCtx* dctx); |
---|
| 101 | size_t ZBUFFv04_decompressWithDictionary(ZBUFFv04_DCtx* dctx, const void* dict, size_t dictSize); |
---|
| 102 | |
---|
| 103 | size_t ZBUFFv04_decompressContinue(ZBUFFv04_DCtx* dctx, void* dst, size_t* maxDstSizePtr, const void* src, size_t* srcSizePtr); |
---|
| 104 | |
---|
| 105 | /** ************************************************ |
---|
| 106 | * Streaming decompression |
---|
| 107 | * |
---|
| 108 | * A ZBUFF_DCtx object is required to track streaming operation. |
---|
| 109 | * Use ZBUFF_createDCtx() and ZBUFF_freeDCtx() to create/release resources. |
---|
| 110 | * Use ZBUFF_decompressInit() to start a new decompression operation. |
---|
| 111 | * ZBUFF_DCtx objects can be reused multiple times. |
---|
| 112 | * |
---|
| 113 | * Optionally, a reference to a static dictionary can be set, using ZBUFF_decompressWithDictionary() |
---|
| 114 | * It must be the same content as the one set during compression phase. |
---|
| 115 | * Dictionary content must remain accessible during the decompression process. |
---|
| 116 | * |
---|
| 117 | * Use ZBUFF_decompressContinue() repetitively to consume your input. |
---|
| 118 | * *srcSizePtr and *maxDstSizePtr can be any size. |
---|
| 119 | * The function will report how many bytes were read or written by modifying *srcSizePtr and *maxDstSizePtr. |
---|
| 120 | * Note that it may not consume the entire input, in which case it's up to the caller to present remaining input again. |
---|
| 121 | * The content of dst will be overwritten (up to *maxDstSizePtr) at each function call, so save its content if it matters or change dst. |
---|
| 122 | * @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to improve latency) |
---|
| 123 | * or 0 when a frame is completely decoded |
---|
| 124 | * or an error code, which can be tested using ZBUFF_isError(). |
---|
| 125 | * |
---|
| 126 | * Hint : recommended buffer sizes (not compulsory) : ZBUFF_recommendedDInSize / ZBUFF_recommendedDOutSize |
---|
| 127 | * 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. |
---|
| 128 | * input : ZBUFF_recommendedDInSize==128Kb+3; just follow indications from ZBUFF_decompressContinue() to minimize latency. It should always be <= 128 KB + 3 . |
---|
| 129 | * **************************************************/ |
---|
| 130 | unsigned ZBUFFv04_isError(size_t errorCode); |
---|
| 131 | const char* ZBUFFv04_getErrorName(size_t errorCode); |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | /** The below functions provide recommended buffer sizes for Compression or Decompression operations. |
---|
| 135 | * These sizes are not compulsory, they just tend to offer better latency */ |
---|
| 136 | size_t ZBUFFv04_recommendedDInSize(void); |
---|
| 137 | size_t ZBUFFv04_recommendedDOutSize(void); |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | /* ************************************* |
---|
| 141 | * Prefix - version detection |
---|
| 142 | ***************************************/ |
---|
| 143 | #define ZSTDv04_magicNumber 0xFD2FB524 /* v0.4 */ |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | #if defined (__cplusplus) |
---|
| 147 | } |
---|
| 148 | #endif |
---|