xref: /freebsd/sys/contrib/zstd/lib/legacy/zstd_v01.h (revision 5ff13fbc199bdf5f0572845351c68ee5ca828e71)
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_V01_H_28739879432
120c16b537SWarner Losh #define ZSTD_V01_H_28739879432
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 ZSTDv01_decompress() : decompress ZSTD frames compliant with v0.1.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 ZSTDv01_decompress( void* dst, size_t maxOriginalSize,
360c16b537SWarner Losh                      const void* src, size_t compressedSize);
370c16b537SWarner Losh 
380c16b537SWarner Losh  /**
392b9c00cbSConrad Meyer  ZSTDv01_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.1.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 ZSTDv01_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
492b9c00cbSConrad Meyer                                      size_t* cSize, unsigned long long* dBound);
500c16b537SWarner Losh 
510c16b537SWarner Losh /**
520c16b537SWarner Losh ZSTDv01_isError() : tells if the result of ZSTDv01_decompress() is an error
530c16b537SWarner Losh */
540c16b537SWarner Losh unsigned ZSTDv01_isError(size_t code);
550c16b537SWarner Losh 
560c16b537SWarner Losh 
570c16b537SWarner Losh /* *************************************
580c16b537SWarner Losh *  Advanced functions
590c16b537SWarner Losh ***************************************/
600c16b537SWarner Losh typedef struct ZSTDv01_Dctx_s ZSTDv01_Dctx;
610c16b537SWarner Losh ZSTDv01_Dctx* ZSTDv01_createDCtx(void);
620c16b537SWarner Losh size_t ZSTDv01_freeDCtx(ZSTDv01_Dctx* dctx);
630c16b537SWarner Losh 
640c16b537SWarner Losh size_t ZSTDv01_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 ZSTDv01_resetDCtx(ZSTDv01_Dctx* dctx);
720c16b537SWarner Losh 
730c16b537SWarner Losh size_t ZSTDv01_nextSrcSizeToDecompress(ZSTDv01_Dctx* dctx);
740c16b537SWarner Losh size_t ZSTDv01_decompressContinue(ZSTDv01_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 ZSTDv01_magicNumber   0xFD2FB51E   /* Big Endian version */
870c16b537SWarner Losh #define ZSTDv01_magicNumberLE 0x1EB52FFD   /* Little Endian version */
880c16b537SWarner Losh 
890c16b537SWarner Losh 
900c16b537SWarner Losh #if defined (__cplusplus)
910c16b537SWarner Losh }
920c16b537SWarner Losh #endif
930c16b537SWarner Losh 
940c16b537SWarner Losh #endif /* ZSTD_V01_H_28739879432 */
95