]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/zstd/lib/legacy/zstd_v06.h
Import zstandard 1.3.1
[FreeBSD/FreeBSD.git] / contrib / zstd / lib / legacy / zstd_v06.h
1 /*
2  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under both the BSD-style license (found in the
6  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7  * in the COPYING file in the root directory of this source tree).
8  */
9
10 #ifndef ZSTDv06_H
11 #define ZSTDv06_H
12
13 #if defined (__cplusplus)
14 extern "C" {
15 #endif
16
17 /*======  Dependency  ======*/
18 #include <stddef.h>   /* size_t */
19
20
21 /*======  Export for Windows  ======*/
22 /*!
23 *  ZSTDv06_DLL_EXPORT :
24 *  Enable exporting of functions when building a Windows DLL
25 */
26 #if defined(_WIN32) && defined(ZSTDv06_DLL_EXPORT) && (ZSTDv06_DLL_EXPORT==1)
27 #  define ZSTDLIBv06_API __declspec(dllexport)
28 #else
29 #  define ZSTDLIBv06_API
30 #endif
31
32
33 /* *************************************
34 *  Simple functions
35 ***************************************/
36 /*! ZSTDv06_decompress() :
37     `compressedSize` : is the _exact_ size of the compressed blob, otherwise decompression will fail.
38     `dstCapacity` must be large enough, equal or larger than originalSize.
39     @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
40               or an errorCode if it fails (which can be tested using ZSTDv06_isError()) */
41 ZSTDLIBv06_API size_t ZSTDv06_decompress( void* dst, size_t dstCapacity,
42                                     const void* src, size_t compressedSize);
43
44 /**
45 ZSTDv06_getFrameSrcSize() : get the source length of a ZSTD frame
46     compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
47     return : the number of bytes that would be read to decompress this frame
48              or an errorCode if it fails (which can be tested using ZSTDv06_isError())
49 */
50 size_t ZSTDv06_findFrameCompressedSize(const void* src, size_t compressedSize);
51
52 /* *************************************
53 *  Helper functions
54 ***************************************/
55 ZSTDLIBv06_API size_t      ZSTDv06_compressBound(size_t srcSize); /*!< maximum compressed size (worst case scenario) */
56
57 /* Error Management */
58 ZSTDLIBv06_API unsigned    ZSTDv06_isError(size_t code);          /*!< tells if a `size_t` function result is an error code */
59 ZSTDLIBv06_API const char* ZSTDv06_getErrorName(size_t code);     /*!< provides readable string for an error code */
60
61
62 /* *************************************
63 *  Explicit memory management
64 ***************************************/
65 /** Decompression context */
66 typedef struct ZSTDv06_DCtx_s ZSTDv06_DCtx;
67 ZSTDLIBv06_API ZSTDv06_DCtx* ZSTDv06_createDCtx(void);
68 ZSTDLIBv06_API size_t     ZSTDv06_freeDCtx(ZSTDv06_DCtx* dctx);      /*!< @return : errorCode */
69
70 /** ZSTDv06_decompressDCtx() :
71 *   Same as ZSTDv06_decompress(), but requires an already allocated ZSTDv06_DCtx (see ZSTDv06_createDCtx()) */
72 ZSTDLIBv06_API size_t ZSTDv06_decompressDCtx(ZSTDv06_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
73
74
75 /*-***********************
76 *  Dictionary API
77 *************************/
78 /*! ZSTDv06_decompress_usingDict() :
79 *   Decompression using a pre-defined Dictionary content (see dictBuilder).
80 *   Dictionary must be identical to the one used during compression, otherwise regenerated data will be corrupted.
81 *   Note : dict can be NULL, in which case, it's equivalent to ZSTDv06_decompressDCtx() */
82 ZSTDLIBv06_API size_t ZSTDv06_decompress_usingDict(ZSTDv06_DCtx* dctx,
83                                                    void* dst, size_t dstCapacity,
84                                              const void* src, size_t srcSize,
85                                              const void* dict,size_t dictSize);
86
87
88 /*-************************
89 *  Advanced Streaming API
90 ***************************/
91 struct ZSTDv06_frameParams_s { unsigned long long frameContentSize; unsigned windowLog; };
92 typedef struct ZSTDv06_frameParams_s ZSTDv06_frameParams;
93
94 ZSTDLIBv06_API size_t ZSTDv06_getFrameParams(ZSTDv06_frameParams* fparamsPtr, const void* src, size_t srcSize);   /**< doesn't consume input */
95 ZSTDLIBv06_API size_t ZSTDv06_decompressBegin_usingDict(ZSTDv06_DCtx* dctx, const void* dict, size_t dictSize);
96 ZSTDLIBv06_API void   ZSTDv06_copyDCtx(ZSTDv06_DCtx* dctx, const ZSTDv06_DCtx* preparedDCtx);
97
98 ZSTDLIBv06_API size_t ZSTDv06_nextSrcSizeToDecompress(ZSTDv06_DCtx* dctx);
99 ZSTDLIBv06_API size_t ZSTDv06_decompressContinue(ZSTDv06_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
100
101
102
103 /* *************************************
104 *  ZBUFF API
105 ***************************************/
106
107 typedef struct ZBUFFv06_DCtx_s ZBUFFv06_DCtx;
108 ZSTDLIBv06_API ZBUFFv06_DCtx* ZBUFFv06_createDCtx(void);
109 ZSTDLIBv06_API size_t         ZBUFFv06_freeDCtx(ZBUFFv06_DCtx* dctx);
110
111 ZSTDLIBv06_API size_t ZBUFFv06_decompressInit(ZBUFFv06_DCtx* dctx);
112 ZSTDLIBv06_API size_t ZBUFFv06_decompressInitDictionary(ZBUFFv06_DCtx* dctx, const void* dict, size_t dictSize);
113
114 ZSTDLIBv06_API size_t ZBUFFv06_decompressContinue(ZBUFFv06_DCtx* dctx,
115                                                   void* dst, size_t* dstCapacityPtr,
116                                             const void* src, size_t* srcSizePtr);
117
118 /*-***************************************************************************
119 *  Streaming decompression howto
120 *
121 *  A ZBUFFv06_DCtx object is required to track streaming operations.
122 *  Use ZBUFFv06_createDCtx() and ZBUFFv06_freeDCtx() to create/release resources.
123 *  Use ZBUFFv06_decompressInit() to start a new decompression operation,
124 *   or ZBUFFv06_decompressInitDictionary() if decompression requires a dictionary.
125 *  Note that ZBUFFv06_DCtx objects can be re-init multiple times.
126 *
127 *  Use ZBUFFv06_decompressContinue() repetitively to consume your input.
128 *  *srcSizePtr and *dstCapacityPtr can be any size.
129 *  The function will report how many bytes were read or written by modifying *srcSizePtr and *dstCapacityPtr.
130 *  Note that it may not consume the entire input, in which case it's up to the caller to present remaining input again.
131 *  The content of `dst` will be overwritten (up to *dstCapacityPtr) at each function call, so save its content if it matters, or change `dst`.
132 *  @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to help latency),
133 *            or 0 when a frame is completely decoded,
134 *            or an error code, which can be tested using ZBUFFv06_isError().
135 *
136 *  Hint : recommended buffer sizes (not compulsory) : ZBUFFv06_recommendedDInSize() and ZBUFFv06_recommendedDOutSize()
137 *  output : ZBUFFv06_recommendedDOutSize== 128 KB block size is the internal unit, it ensures it's always possible to write a full block when decoded.
138 *  input  : ZBUFFv06_recommendedDInSize == 128KB + 3;
139 *           just follow indications from ZBUFFv06_decompressContinue() to minimize latency. It should always be <= 128 KB + 3 .
140 * *******************************************************************************/
141
142
143 /* *************************************
144 *  Tool functions
145 ***************************************/
146 ZSTDLIBv06_API unsigned ZBUFFv06_isError(size_t errorCode);
147 ZSTDLIBv06_API const char* ZBUFFv06_getErrorName(size_t errorCode);
148
149 /** Functions below provide recommended buffer sizes for Compression or Decompression operations.
150 *   These sizes are just hints, they tend to offer better latency */
151 ZSTDLIBv06_API size_t ZBUFFv06_recommendedDInSize(void);
152 ZSTDLIBv06_API size_t ZBUFFv06_recommendedDOutSize(void);
153
154
155 /*-*************************************
156 *  Constants
157 ***************************************/
158 #define ZSTDv06_MAGICNUMBER 0xFD2FB526   /* v0.6 */
159
160
161
162 #if defined (__cplusplus)
163 }
164 #endif
165
166 #endif  /* ZSTDv06_BUFFERED_H */