1*0c16b537SWarner Losh /* 2*0c16b537SWarner Losh * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. 3*0c16b537SWarner Losh * All rights reserved. 4*0c16b537SWarner Losh * 5*0c16b537SWarner Losh * This source code is licensed under both the BSD-style license (found in the 6*0c16b537SWarner Losh * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7*0c16b537SWarner Losh * in the COPYING file in the root directory of this source tree). 8*0c16b537SWarner Losh * You may select, at your option, one of the above-listed licenses. 9*0c16b537SWarner Losh */ 10*0c16b537SWarner Losh 11*0c16b537SWarner Losh #ifndef ZSTD_V03_H_298734209782 12*0c16b537SWarner Losh #define ZSTD_V03_H_298734209782 13*0c16b537SWarner Losh 14*0c16b537SWarner Losh #if defined (__cplusplus) 15*0c16b537SWarner Losh extern "C" { 16*0c16b537SWarner Losh #endif 17*0c16b537SWarner Losh 18*0c16b537SWarner Losh /* ************************************* 19*0c16b537SWarner Losh * Includes 20*0c16b537SWarner Losh ***************************************/ 21*0c16b537SWarner Losh #include <stddef.h> /* size_t */ 22*0c16b537SWarner Losh 23*0c16b537SWarner Losh 24*0c16b537SWarner Losh /* ************************************* 25*0c16b537SWarner Losh * Simple one-step function 26*0c16b537SWarner Losh ***************************************/ 27*0c16b537SWarner Losh /** 28*0c16b537SWarner Losh ZSTDv03_decompress() : decompress ZSTD frames compliant with v0.3.x format 29*0c16b537SWarner Losh compressedSize : is the exact source size 30*0c16b537SWarner Losh maxOriginalSize : is the size of the 'dst' buffer, which must be already allocated. 31*0c16b537SWarner Losh It must be equal or larger than originalSize, otherwise decompression will fail. 32*0c16b537SWarner Losh return : the number of bytes decompressed into destination buffer (originalSize) 33*0c16b537SWarner Losh or an errorCode if it fails (which can be tested using ZSTDv01_isError()) 34*0c16b537SWarner Losh */ 35*0c16b537SWarner Losh size_t ZSTDv03_decompress( void* dst, size_t maxOriginalSize, 36*0c16b537SWarner Losh const void* src, size_t compressedSize); 37*0c16b537SWarner Losh 38*0c16b537SWarner Losh /** 39*0c16b537SWarner Losh ZSTDv03_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.3.x format 40*0c16b537SWarner Losh compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src' 41*0c16b537SWarner Losh return : the number of bytes that would be read to decompress this frame 42*0c16b537SWarner Losh or an errorCode if it fails (which can be tested using ZSTDv03_isError()) 43*0c16b537SWarner Losh */ 44*0c16b537SWarner Losh size_t ZSTDv03_findFrameCompressedSize(const void* src, size_t compressedSize); 45*0c16b537SWarner Losh 46*0c16b537SWarner Losh /** 47*0c16b537SWarner Losh ZSTDv03_isError() : tells if the result of ZSTDv03_decompress() is an error 48*0c16b537SWarner Losh */ 49*0c16b537SWarner Losh unsigned ZSTDv03_isError(size_t code); 50*0c16b537SWarner Losh 51*0c16b537SWarner Losh 52*0c16b537SWarner Losh /* ************************************* 53*0c16b537SWarner Losh * Advanced functions 54*0c16b537SWarner Losh ***************************************/ 55*0c16b537SWarner Losh typedef struct ZSTDv03_Dctx_s ZSTDv03_Dctx; 56*0c16b537SWarner Losh ZSTDv03_Dctx* ZSTDv03_createDCtx(void); 57*0c16b537SWarner Losh size_t ZSTDv03_freeDCtx(ZSTDv03_Dctx* dctx); 58*0c16b537SWarner Losh 59*0c16b537SWarner Losh size_t ZSTDv03_decompressDCtx(void* ctx, 60*0c16b537SWarner Losh void* dst, size_t maxOriginalSize, 61*0c16b537SWarner Losh const void* src, size_t compressedSize); 62*0c16b537SWarner Losh 63*0c16b537SWarner Losh /* ************************************* 64*0c16b537SWarner Losh * Streaming functions 65*0c16b537SWarner Losh ***************************************/ 66*0c16b537SWarner Losh size_t ZSTDv03_resetDCtx(ZSTDv03_Dctx* dctx); 67*0c16b537SWarner Losh 68*0c16b537SWarner Losh size_t ZSTDv03_nextSrcSizeToDecompress(ZSTDv03_Dctx* dctx); 69*0c16b537SWarner Losh size_t ZSTDv03_decompressContinue(ZSTDv03_Dctx* dctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize); 70*0c16b537SWarner Losh /** 71*0c16b537SWarner Losh Use above functions alternatively. 72*0c16b537SWarner Losh ZSTD_nextSrcSizeToDecompress() tells how much bytes to provide as 'srcSize' to ZSTD_decompressContinue(). 73*0c16b537SWarner Losh ZSTD_decompressContinue() will use previous data blocks to improve compression if they are located prior to current block. 74*0c16b537SWarner Losh Result is the number of bytes regenerated within 'dst'. 75*0c16b537SWarner Losh It can be zero, which is not an error; it just means ZSTD_decompressContinue() has decoded some header. 76*0c16b537SWarner Losh */ 77*0c16b537SWarner Losh 78*0c16b537SWarner Losh /* ************************************* 79*0c16b537SWarner Losh * Prefix - version detection 80*0c16b537SWarner Losh ***************************************/ 81*0c16b537SWarner Losh #define ZSTDv03_magicNumber 0xFD2FB523 /* v0.3 */ 82*0c16b537SWarner Losh 83*0c16b537SWarner Losh 84*0c16b537SWarner Losh #if defined (__cplusplus) 85*0c16b537SWarner Losh } 86*0c16b537SWarner Losh #endif 87*0c16b537SWarner Losh 88*0c16b537SWarner Losh #endif /* ZSTD_V03_H_298734209782 */ 89