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