10c16b537SWarner Losh /* 2*5ff13fbcSAllan Jude * Copyright (c) Yann Collet, Facebook, Inc. 30c16b537SWarner Losh * All rights reserved. 40c16b537SWarner Losh * 50c16b537SWarner Losh * This source code is licensed under both the BSD-style license (found in the 60c16b537SWarner Losh * LICENSE file in the root directory of this source tree) and the GPLv2 (found 70c16b537SWarner Losh * in the COPYING file in the root directory of this source tree). 80c16b537SWarner Losh * You may select, at your option, one of the above-listed licenses. 90c16b537SWarner Losh */ 100c16b537SWarner Losh 110c16b537SWarner Losh #ifndef ZSTD_V02_H_4174539423 120c16b537SWarner Losh #define ZSTD_V02_H_4174539423 130c16b537SWarner Losh 140c16b537SWarner Losh #if defined (__cplusplus) 150c16b537SWarner Losh extern "C" { 160c16b537SWarner Losh #endif 170c16b537SWarner Losh 180c16b537SWarner Losh /* ************************************* 190c16b537SWarner Losh * Includes 200c16b537SWarner Losh ***************************************/ 210c16b537SWarner Losh #include <stddef.h> /* size_t */ 220c16b537SWarner Losh 230c16b537SWarner Losh 240c16b537SWarner Losh /* ************************************* 250c16b537SWarner Losh * Simple one-step function 260c16b537SWarner Losh ***************************************/ 270c16b537SWarner Losh /** 280c16b537SWarner Losh ZSTDv02_decompress() : decompress ZSTD frames compliant with v0.2.x format 290c16b537SWarner Losh compressedSize : is the exact source size 300c16b537SWarner Losh maxOriginalSize : is the size of the 'dst' buffer, which must be already allocated. 310c16b537SWarner Losh It must be equal or larger than originalSize, otherwise decompression will fail. 320c16b537SWarner Losh return : the number of bytes decompressed into destination buffer (originalSize) 330c16b537SWarner Losh or an errorCode if it fails (which can be tested using ZSTDv01_isError()) 340c16b537SWarner Losh */ 350c16b537SWarner Losh size_t ZSTDv02_decompress( void* dst, size_t maxOriginalSize, 360c16b537SWarner Losh const void* src, size_t compressedSize); 370c16b537SWarner Losh 380c16b537SWarner Losh /** 392b9c00cbSConrad Meyer ZSTDv02_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.2.x format 402b9c00cbSConrad Meyer srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src' 412b9c00cbSConrad Meyer cSize (output parameter) : the number of bytes that would be read to decompress this frame 422b9c00cbSConrad Meyer or an error code if it fails (which can be tested using ZSTDv01_isError()) 432b9c00cbSConrad Meyer dBound (output parameter) : an upper-bound for the decompressed size of the data in the frame 442b9c00cbSConrad Meyer or ZSTD_CONTENTSIZE_ERROR if an error occurs 452b9c00cbSConrad Meyer 462b9c00cbSConrad Meyer note : assumes `cSize` and `dBound` are _not_ NULL. 470c16b537SWarner Losh */ 482b9c00cbSConrad Meyer void ZSTDv02_findFrameSizeInfoLegacy(const void *src, size_t srcSize, 492b9c00cbSConrad Meyer size_t* cSize, unsigned long long* dBound); 500c16b537SWarner Losh 510c16b537SWarner Losh /** 520c16b537SWarner Losh ZSTDv02_isError() : tells if the result of ZSTDv02_decompress() is an error 530c16b537SWarner Losh */ 540c16b537SWarner Losh unsigned ZSTDv02_isError(size_t code); 550c16b537SWarner Losh 560c16b537SWarner Losh 570c16b537SWarner Losh /* ************************************* 580c16b537SWarner Losh * Advanced functions 590c16b537SWarner Losh ***************************************/ 600c16b537SWarner Losh typedef struct ZSTDv02_Dctx_s ZSTDv02_Dctx; 610c16b537SWarner Losh ZSTDv02_Dctx* ZSTDv02_createDCtx(void); 620c16b537SWarner Losh size_t ZSTDv02_freeDCtx(ZSTDv02_Dctx* dctx); 630c16b537SWarner Losh 640c16b537SWarner Losh size_t ZSTDv02_decompressDCtx(void* ctx, 650c16b537SWarner Losh void* dst, size_t maxOriginalSize, 660c16b537SWarner Losh const void* src, size_t compressedSize); 670c16b537SWarner Losh 680c16b537SWarner Losh /* ************************************* 690c16b537SWarner Losh * Streaming functions 700c16b537SWarner Losh ***************************************/ 710c16b537SWarner Losh size_t ZSTDv02_resetDCtx(ZSTDv02_Dctx* dctx); 720c16b537SWarner Losh 730c16b537SWarner Losh size_t ZSTDv02_nextSrcSizeToDecompress(ZSTDv02_Dctx* dctx); 740c16b537SWarner Losh size_t ZSTDv02_decompressContinue(ZSTDv02_Dctx* dctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize); 750c16b537SWarner Losh /** 760c16b537SWarner Losh Use above functions alternatively. 770c16b537SWarner Losh ZSTD_nextSrcSizeToDecompress() tells how much bytes to provide as 'srcSize' to ZSTD_decompressContinue(). 780c16b537SWarner Losh ZSTD_decompressContinue() will use previous data blocks to improve compression if they are located prior to current block. 790c16b537SWarner Losh Result is the number of bytes regenerated within 'dst'. 800c16b537SWarner Losh It can be zero, which is not an error; it just means ZSTD_decompressContinue() has decoded some header. 810c16b537SWarner Losh */ 820c16b537SWarner Losh 830c16b537SWarner Losh /* ************************************* 840c16b537SWarner Losh * Prefix - version detection 850c16b537SWarner Losh ***************************************/ 860c16b537SWarner Losh #define ZSTDv02_magicNumber 0xFD2FB522 /* v0.2 */ 870c16b537SWarner Losh 880c16b537SWarner Losh 890c16b537SWarner Losh #if defined (__cplusplus) 900c16b537SWarner Losh } 910c16b537SWarner Losh #endif 920c16b537SWarner Losh 930c16b537SWarner Losh #endif /* ZSTD_V02_H_4174539423 */ 94