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