]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/zstd/zlibWrapper/zstd_zlibwrapper.h
Pull down pjdfstest 0.1
[FreeBSD/FreeBSD.git] / contrib / zstd / zlibWrapper / zstd_zlibwrapper.h
1 /**
2  * Copyright (c) 2016-present, Przemyslaw Skibinski, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  */
9
10 #ifndef ZSTD_ZLIBWRAPPER_H
11 #define ZSTD_ZLIBWRAPPER_H
12
13 #if defined (__cplusplus)
14 extern "C" {
15 #endif
16
17
18 #define ZLIB_CONST
19 #define Z_PREFIX
20 #define ZLIB_INTERNAL   /* disables gz*64 functions but fixes zlib 1.2.4 with Z_PREFIX */
21 #include <zlib.h>
22
23 #if !defined(z_const)
24     #define z_const
25 #endif
26
27
28 /* returns a string with version of zstd library */
29 const char * zstdVersion(void);
30
31
32 /*** COMPRESSION ***/
33 /* ZWRAP_useZSTDcompression() enables/disables zstd compression during runtime.
34    By default zstd compression is disabled. To enable zstd compression please use one of the methods:
35    - compilation with the additional option -DZWRAP_USE_ZSTD=1 
36    - using '#define ZWRAP_USE_ZSTD 1' in source code before '#include "zstd_zlibwrapper.h"'
37    - calling ZWRAP_useZSTDcompression(1)
38    All above-mentioned methods will enable zstd compression for all threads.
39    Be aware that ZWRAP_useZSTDcompression() is not thread-safe and may lead to a race condition. */
40 void ZWRAP_useZSTDcompression(int turn_on);
41
42 /* checks if zstd compression is turned on */
43 int ZWRAP_isUsingZSTDcompression(void);
44
45 /* Changes a pledged source size for a given compression stream.
46    It will change ZSTD compression parameters what may improve compression speed and/or ratio.
47    The function should be called just after deflateInit() or deflateReset() and before deflate() or deflateSetDictionary().
48    It's only helpful when data is compressed in blocks. 
49    There will be no change in case of deflateInit() or deflateReset() immediately followed by deflate(strm, Z_FINISH) 
50    as this case is automatically detected.  */
51 int ZWRAP_setPledgedSrcSize(z_streamp strm, unsigned long long pledgedSrcSize);
52
53 /* Similar to deflateReset but preserves dictionary set using deflateSetDictionary.
54    It should improve compression speed because there will be less calls to deflateSetDictionary 
55    When using zlib compression this method redirects to deflateReset. */
56 int ZWRAP_deflateReset_keepDict(z_streamp strm);
57
58
59
60 /*** DECOMPRESSION ***/
61 typedef enum { ZWRAP_FORCE_ZLIB, ZWRAP_AUTO } ZWRAP_decompress_type;
62
63 /* ZWRAP_setDecompressionType() enables/disables automatic recognition of zstd/zlib compressed data during runtime.
64    By default auto-detection of zstd and zlib streams in enabled (ZWRAP_AUTO).
65    Forcing zlib decompression with ZWRAP_setDecompressionType(ZWRAP_FORCE_ZLIB) slightly improves
66    decompression speed of zlib-encoded streams.
67    Be aware that ZWRAP_setDecompressionType() is not thread-safe and may lead to a race condition. */
68 void ZWRAP_setDecompressionType(ZWRAP_decompress_type type);
69
70 /* checks zstd decompression type */
71 ZWRAP_decompress_type ZWRAP_getDecompressionType(void);
72
73 /* Checks if zstd decompression is used for a given stream.
74    If will return 1 only when inflate() was called and zstd header was detected. */
75 int ZWRAP_isUsingZSTDdecompression(z_streamp strm);
76
77 /* Similar to inflateReset but preserves dictionary set using inflateSetDictionary.
78    inflate() will return Z_NEED_DICT only for the first time what will improve decompression speed.
79    For zlib streams this method redirects to inflateReset. */
80 int ZWRAP_inflateReset_keepDict(z_streamp strm);
81
82
83 #if defined (__cplusplus)
84 }
85 #endif
86
87 #endif /* ZSTD_ZLIBWRAPPER_H */