2017-08-18 23:52:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
2016-08-30 17:04:33 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2017-08-18 23:52:05 +00:00
|
|
|
* This source code is licensed under both the BSD-style license (found in the
|
|
|
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
|
|
* in the COPYING file in the root directory of this source tree).
|
2016-08-30 17:04:33 +00:00
|
|
|
*/
|
2016-05-12 15:15:41 +00:00
|
|
|
|
|
|
|
#ifndef ZSTD_ZLIBWRAPPER_H
|
|
|
|
#define ZSTD_ZLIBWRAPPER_H
|
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-11-04 16:49:17 +00:00
|
|
|
#define ZLIB_CONST
|
2016-05-12 15:15:41 +00:00
|
|
|
#define Z_PREFIX
|
2016-11-28 13:09:26 +00:00
|
|
|
#define ZLIB_INTERNAL /* disables gz*64 functions but fixes zlib 1.2.4 with Z_PREFIX */
|
2016-05-12 15:15:41 +00:00
|
|
|
#include <zlib.h>
|
|
|
|
|
2016-05-27 10:33:19 +00:00
|
|
|
#if !defined(z_const)
|
2016-06-02 08:19:35 +00:00
|
|
|
#define z_const
|
|
|
|
#endif
|
2016-11-04 16:49:17 +00:00
|
|
|
|
2016-05-12 15:15:41 +00:00
|
|
|
|
2016-09-22 09:52:00 +00:00
|
|
|
/* returns a string with version of zstd library */
|
|
|
|
const char * zstdVersion(void);
|
|
|
|
|
|
|
|
|
2016-09-27 14:56:07 +00:00
|
|
|
/*** COMPRESSION ***/
|
2017-02-23 17:28:48 +00:00
|
|
|
/* ZWRAP_useZSTDcompression() enables/disables zstd compression during runtime.
|
|
|
|
By default zstd compression is disabled. To enable zstd compression please use one of the methods:
|
2017-08-18 23:52:05 +00:00
|
|
|
- compilation with the additional option -DZWRAP_USE_ZSTD=1
|
2017-02-23 17:28:48 +00:00
|
|
|
- using '#define ZWRAP_USE_ZSTD 1' in source code before '#include "zstd_zlibwrapper.h"'
|
|
|
|
- calling ZWRAP_useZSTDcompression(1)
|
|
|
|
All above-mentioned methods will enable zstd compression for all threads.
|
|
|
|
Be aware that ZWRAP_useZSTDcompression() is not thread-safe and may lead to a race condition. */
|
2016-09-23 07:08:40 +00:00
|
|
|
void ZWRAP_useZSTDcompression(int turn_on);
|
2016-09-21 14:46:35 +00:00
|
|
|
|
2016-09-27 14:56:07 +00:00
|
|
|
/* checks if zstd compression is turned on */
|
2016-09-23 07:08:40 +00:00
|
|
|
int ZWRAP_isUsingZSTDcompression(void);
|
2016-05-12 15:15:41 +00:00
|
|
|
|
2016-09-21 15:17:29 +00:00
|
|
|
/* Changes a pledged source size for a given compression stream.
|
2016-09-22 08:23:26 +00:00
|
|
|
It will change ZSTD compression parameters what may improve compression speed and/or ratio.
|
2016-09-27 13:25:20 +00:00
|
|
|
The function should be called just after deflateInit() or deflateReset() and before deflate() or deflateSetDictionary().
|
2017-08-18 23:52:05 +00:00
|
|
|
It's only helpful when data is compressed in blocks.
|
|
|
|
There will be no change in case of deflateInit() or deflateReset() immediately followed by deflate(strm, Z_FINISH)
|
2016-09-26 18:49:18 +00:00
|
|
|
as this case is automatically detected. */
|
2016-09-23 07:08:40 +00:00
|
|
|
int ZWRAP_setPledgedSrcSize(z_streamp strm, unsigned long long pledgedSrcSize);
|
2016-09-21 14:46:35 +00:00
|
|
|
|
2016-09-27 15:14:04 +00:00
|
|
|
/* Similar to deflateReset but preserves dictionary set using deflateSetDictionary.
|
2017-08-18 23:52:05 +00:00
|
|
|
It should improve compression speed because there will be less calls to deflateSetDictionary
|
2016-09-27 15:14:04 +00:00
|
|
|
When using zlib compression this method redirects to deflateReset. */
|
2016-09-27 15:27:43 +00:00
|
|
|
int ZWRAP_deflateReset_keepDict(z_streamp strm);
|
2016-05-12 15:15:41 +00:00
|
|
|
|
2016-09-27 14:56:07 +00:00
|
|
|
|
2016-09-27 15:14:04 +00:00
|
|
|
|
2016-09-27 14:56:07 +00:00
|
|
|
/*** DECOMPRESSION ***/
|
2016-09-23 07:08:40 +00:00
|
|
|
typedef enum { ZWRAP_FORCE_ZLIB, ZWRAP_AUTO } ZWRAP_decompress_type;
|
2016-09-22 09:52:00 +00:00
|
|
|
|
2017-02-23 17:28:48 +00:00
|
|
|
/* ZWRAP_setDecompressionType() enables/disables automatic recognition of zstd/zlib compressed data during runtime.
|
|
|
|
By default auto-detection of zstd and zlib streams in enabled (ZWRAP_AUTO).
|
|
|
|
Forcing zlib decompression with ZWRAP_setDecompressionType(ZWRAP_FORCE_ZLIB) slightly improves
|
|
|
|
decompression speed of zlib-encoded streams.
|
|
|
|
Be aware that ZWRAP_setDecompressionType() is not thread-safe and may lead to a race condition. */
|
2016-09-23 07:08:40 +00:00
|
|
|
void ZWRAP_setDecompressionType(ZWRAP_decompress_type type);
|
2016-09-22 09:52:00 +00:00
|
|
|
|
2016-09-27 14:56:07 +00:00
|
|
|
/* checks zstd decompression type */
|
2016-09-23 07:08:40 +00:00
|
|
|
ZWRAP_decompress_type ZWRAP_getDecompressionType(void);
|
2016-09-22 09:52:00 +00:00
|
|
|
|
2016-09-27 16:21:17 +00:00
|
|
|
/* Checks if zstd decompression is used for a given stream.
|
|
|
|
If will return 1 only when inflate() was called and zstd header was detected. */
|
2016-09-27 14:56:07 +00:00
|
|
|
int ZWRAP_isUsingZSTDdecompression(z_streamp strm);
|
2016-09-22 09:52:00 +00:00
|
|
|
|
2016-09-27 14:56:07 +00:00
|
|
|
/* Similar to inflateReset but preserves dictionary set using inflateSetDictionary.
|
2016-09-27 15:14:04 +00:00
|
|
|
inflate() will return Z_NEED_DICT only for the first time what will improve decompression speed.
|
|
|
|
For zlib streams this method redirects to inflateReset. */
|
2016-09-27 15:27:43 +00:00
|
|
|
int ZWRAP_inflateReset_keepDict(z_streamp strm);
|
2016-09-22 09:52:00 +00:00
|
|
|
|
|
|
|
|
2016-05-12 15:15:41 +00:00
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* ZSTD_ZLIBWRAPPER_H */
|