[8ebc79b] | 1 | /* |
---|
| 2 | zstd_v03 - decoder for 0.3 format |
---|
| 3 | Header File |
---|
| 4 | Copyright (C) 2015, 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 | ZSTDv03_decompress() : decompress ZSTD frames compliant with v0.3.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 ZSTDv03_decompress( void* dst, size_t maxOriginalSize, |
---|
| 57 | const void* src, size_t compressedSize); |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | ZSTDv03_isError() : tells if the result of ZSTDv03_decompress() is an error |
---|
| 61 | */ |
---|
| 62 | unsigned ZSTDv03_isError(size_t code); |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | /* ************************************* |
---|
| 66 | * Advanced functions |
---|
| 67 | ***************************************/ |
---|
| 68 | typedef struct ZSTDv03_Dctx_s ZSTDv03_Dctx; |
---|
| 69 | ZSTDv03_Dctx* ZSTDv03_createDCtx(void); |
---|
| 70 | size_t ZSTDv03_freeDCtx(ZSTDv03_Dctx* dctx); |
---|
| 71 | |
---|
| 72 | size_t ZSTDv03_decompressDCtx(void* ctx, |
---|
| 73 | void* dst, size_t maxOriginalSize, |
---|
| 74 | const void* src, size_t compressedSize); |
---|
| 75 | |
---|
| 76 | /* ************************************* |
---|
| 77 | * Streaming functions |
---|
| 78 | ***************************************/ |
---|
| 79 | size_t ZSTDv03_resetDCtx(ZSTDv03_Dctx* dctx); |
---|
| 80 | |
---|
| 81 | size_t ZSTDv03_nextSrcSizeToDecompress(ZSTDv03_Dctx* dctx); |
---|
| 82 | size_t ZSTDv03_decompressContinue(ZSTDv03_Dctx* dctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize); |
---|
| 83 | /** |
---|
| 84 | Use above functions alternatively. |
---|
| 85 | ZSTD_nextSrcSizeToDecompress() tells how much bytes to provide as 'srcSize' to ZSTD_decompressContinue(). |
---|
| 86 | ZSTD_decompressContinue() will use previous data blocks to improve compression if they are located prior to current block. |
---|
| 87 | Result is the number of bytes regenerated within 'dst'. |
---|
| 88 | It can be zero, which is not an error; it just means ZSTD_decompressContinue() has decoded some header. |
---|
| 89 | */ |
---|
| 90 | |
---|
| 91 | /* ************************************* |
---|
| 92 | * Prefix - version detection |
---|
| 93 | ***************************************/ |
---|
| 94 | #define ZSTDv03_magicNumber 0xFD2FB523 /* v0.3 */ |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | #if defined (__cplusplus) |
---|
| 98 | } |
---|
| 99 | #endif |
---|