blob: 230bf8411b0a0de036c29ecfe3816bf00a502346 [file] [log] [blame]
Yann Collet32fb4072017-08-18 16:52:05 -07001/*
Elliott Hughes44aba642023-09-12 20:18:59 +00002 * Copyright (c) Meta Platforms, Inc. and affiliates.
Yann Collet4ded9e52016-08-30 10:04:33 -07003 * All rights reserved.
4 *
Yann Collet32fb4072017-08-18 16:52:05 -07005 * 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).
Yann Collet3128e032017-09-08 00:09:23 -07008 * You may select, at your option, one of the above-listed licenses.
Yann Collet4ded9e52016-08-30 10:04:33 -07009 */
inikep3eabe9b2016-05-12 17:15:41 +020010
11#ifndef ZSTD_ZLIBWRAPPER_H
12#define ZSTD_ZLIBWRAPPER_H
13
14#if defined (__cplusplus)
15extern "C" {
16#endif
17
18
Przemyslaw Skibinski6cecb352016-11-04 17:49:17 +010019#define ZLIB_CONST
inikep3eabe9b2016-05-12 17:15:41 +020020#define Z_PREFIX
Przemyslaw Skibinskic77befe2016-11-28 14:09:26 +010021#define ZLIB_INTERNAL /* disables gz*64 functions but fixes zlib 1.2.4 with Z_PREFIX */
inikep3eabe9b2016-05-12 17:15:41 +020022#include <zlib.h>
23
inikepd0c38622016-05-27 12:33:19 +020024#if !defined(z_const)
inikepbf25d7a2016-06-02 10:19:35 +020025 #define z_const
26#endif
Przemyslaw Skibinski6cecb352016-11-04 17:49:17 +010027
Elliott Hughes44aba642023-09-12 20:18:59 +000028#if !defined(_Z_OF)
29 #define _Z_OF OF
30#endif
inikep3eabe9b2016-05-12 17:15:41 +020031
inikep230a61f2016-09-21 16:46:35 +020032/* returns a string with version of zstd library */
inikep614fdde2016-06-02 18:40:41 +020033const char * zstdVersion(void);
inikep3eabe9b2016-05-12 17:15:41 +020034
inikepd7557172016-09-22 11:52:00 +020035
inikep706876f2016-09-27 16:56:07 +020036/*** COMPRESSION ***/
Przemyslaw Skibinski5c42aad2017-02-23 18:28:48 +010037/* 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:
Yann Collet32fb4072017-08-18 16:52:05 -070039 - compilation with the additional option -DZWRAP_USE_ZSTD=1
Przemyslaw Skibinski5c42aad2017-02-23 18:28:48 +010040 - 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. */
inikep252c20d2016-09-23 09:08:40 +020044void ZWRAP_useZSTDcompression(int turn_on);
inikepd7557172016-09-22 11:52:00 +020045
inikep706876f2016-09-27 16:56:07 +020046/* checks if zstd compression is turned on */
inikep252c20d2016-09-23 09:08:40 +020047int ZWRAP_isUsingZSTDcompression(void);
inikepd7557172016-09-22 11:52:00 +020048
inikep7e792572016-09-21 17:17:29 +020049/* Changes a pledged source size for a given compression stream.
inikepdfef5dd2016-09-22 10:23:26 +020050 It will change ZSTD compression parameters what may improve compression speed and/or ratio.
inikep572d4282016-09-27 15:25:20 +020051 The function should be called just after deflateInit() or deflateReset() and before deflate() or deflateSetDictionary().
Yann Collet32fb4072017-08-18 16:52:05 -070052 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)
inikep67a1f4d2016-09-26 20:49:18 +020054 as this case is automatically detected. */
inikep252c20d2016-09-23 09:08:40 +020055int ZWRAP_setPledgedSrcSize(z_streamp strm, unsigned long long pledgedSrcSize);
inikep230a61f2016-09-21 16:46:35 +020056
inikep856f91e2016-09-27 17:14:04 +020057/* Similar to deflateReset but preserves dictionary set using deflateSetDictionary.
Yann Collet32fb4072017-08-18 16:52:05 -070058 It should improve compression speed because there will be less calls to deflateSetDictionary
inikep856f91e2016-09-27 17:14:04 +020059 When using zlib compression this method redirects to deflateReset. */
inikep20859af2016-09-27 17:27:43 +020060int ZWRAP_deflateReset_keepDict(z_streamp strm);
inikep3eabe9b2016-05-12 17:15:41 +020061
inikep706876f2016-09-27 16:56:07 +020062
inikep856f91e2016-09-27 17:14:04 +020063
inikep706876f2016-09-27 16:56:07 +020064/*** DECOMPRESSION ***/
inikep252c20d2016-09-23 09:08:40 +020065typedef enum { ZWRAP_FORCE_ZLIB, ZWRAP_AUTO } ZWRAP_decompress_type;
inikepd7557172016-09-22 11:52:00 +020066
Przemyslaw Skibinski5c42aad2017-02-23 18:28:48 +010067/* 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. */
inikep252c20d2016-09-23 09:08:40 +020072void ZWRAP_setDecompressionType(ZWRAP_decompress_type type);
inikepd7557172016-09-22 11:52:00 +020073
inikep706876f2016-09-27 16:56:07 +020074/* checks zstd decompression type */
inikep252c20d2016-09-23 09:08:40 +020075ZWRAP_decompress_type ZWRAP_getDecompressionType(void);
inikepd7557172016-09-22 11:52:00 +020076
inikep22e27302016-09-27 18:21:17 +020077/* 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. */
inikep706876f2016-09-27 16:56:07 +020079int ZWRAP_isUsingZSTDdecompression(z_streamp strm);
inikepd7557172016-09-22 11:52:00 +020080
inikep706876f2016-09-27 16:56:07 +020081/* Similar to inflateReset but preserves dictionary set using inflateSetDictionary.
inikep856f91e2016-09-27 17:14:04 +020082 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. */
inikep20859af2016-09-27 17:27:43 +020084int ZWRAP_inflateReset_keepDict(z_streamp strm);
inikepd7557172016-09-22 11:52:00 +020085
86
inikep3eabe9b2016-05-12 17:15:41 +020087#if defined (__cplusplus)
88}
89#endif
90
91#endif /* ZSTD_ZLIBWRAPPER_H */