Yann Collet | 4ded9e5 | 2016-08-30 10:04:33 -0700 | [diff] [blame] | 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 | */ |
inikep | 3eabe9b | 2016-05-12 17:15:41 +0200 | [diff] [blame] | 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 Z_PREFIX |
| 19 | #include <zlib.h> |
| 20 | |
inikep | d0c3862 | 2016-05-27 12:33:19 +0200 | [diff] [blame] | 21 | #if !defined(z_const) |
inikep | bf25d7a | 2016-06-02 10:19:35 +0200 | [diff] [blame] | 22 | #if ZLIB_VERNUM >= 0x1260 |
Yann Collet | 4ded9e5 | 2016-08-30 10:04:33 -0700 | [diff] [blame] | 23 | #define z_const const |
inikep | bf25d7a | 2016-06-02 10:19:35 +0200 | [diff] [blame] | 24 | #else |
| 25 | #define z_const |
| 26 | #endif |
inikep | d0c3862 | 2016-05-27 12:33:19 +0200 | [diff] [blame] | 27 | #endif |
inikep | 3eabe9b | 2016-05-12 17:15:41 +0200 | [diff] [blame] | 28 | |
inikep | 230a61f | 2016-09-21 16:46:35 +0200 | [diff] [blame] | 29 | /* returns a string with version of zstd library */ |
inikep | 614fdde | 2016-06-02 18:40:41 +0200 | [diff] [blame] | 30 | const char * zstdVersion(void); |
inikep | 3eabe9b | 2016-05-12 17:15:41 +0200 | [diff] [blame] | 31 | |
inikep | d755717 | 2016-09-22 11:52:00 +0200 | [diff] [blame] | 32 | |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 33 | /*** COMPRESSION ***/ |
inikep | d755717 | 2016-09-22 11:52:00 +0200 | [diff] [blame] | 34 | /* enables/disables zstd compression during runtime */ |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 35 | void ZWRAP_useZSTDcompression(int turn_on); |
inikep | d755717 | 2016-09-22 11:52:00 +0200 | [diff] [blame] | 36 | |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 37 | /* checks if zstd compression is turned on */ |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 38 | int ZWRAP_isUsingZSTDcompression(void); |
inikep | d755717 | 2016-09-22 11:52:00 +0200 | [diff] [blame] | 39 | |
inikep | 7e79257 | 2016-09-21 17:17:29 +0200 | [diff] [blame] | 40 | /* Changes a pledged source size for a given compression stream. |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 41 | It will change ZSTD compression parameters what may improve compression speed and/or ratio. |
inikep | 572d428 | 2016-09-27 15:25:20 +0200 | [diff] [blame] | 42 | The function should be called just after deflateInit() or deflateReset() and before deflate() or deflateSetDictionary(). |
| 43 | It's only helpful when data is compressed in blocks. |
| 44 | There will be no change in case of deflateInit() or deflateReset() immediately followed by deflate(strm, Z_FINISH) |
inikep | 67a1f4d | 2016-09-26 20:49:18 +0200 | [diff] [blame] | 45 | as this case is automatically detected. */ |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 46 | int ZWRAP_setPledgedSrcSize(z_streamp strm, unsigned long long pledgedSrcSize); |
inikep | 230a61f | 2016-09-21 16:46:35 +0200 | [diff] [blame] | 47 | |
inikep | 856f91e | 2016-09-27 17:14:04 +0200 | [diff] [blame^] | 48 | /* Similar to deflateReset but preserves dictionary set using deflateSetDictionary. |
| 49 | It should improve compression speed because there will be less calls to deflateSetDictionary |
| 50 | When using zlib compression this method redirects to deflateReset. */ |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 51 | int ZWRAP_deflateResetWithoutDict(z_streamp strm); |
inikep | 3eabe9b | 2016-05-12 17:15:41 +0200 | [diff] [blame] | 52 | |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 53 | |
inikep | 856f91e | 2016-09-27 17:14:04 +0200 | [diff] [blame^] | 54 | |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 55 | /*** DECOMPRESSION ***/ |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 56 | typedef enum { ZWRAP_FORCE_ZLIB, ZWRAP_AUTO } ZWRAP_decompress_type; |
inikep | d755717 | 2016-09-22 11:52:00 +0200 | [diff] [blame] | 57 | |
| 58 | /* enables/disables automatic recognition of zstd/zlib compressed data during runtime */ |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 59 | void ZWRAP_setDecompressionType(ZWRAP_decompress_type type); |
inikep | d755717 | 2016-09-22 11:52:00 +0200 | [diff] [blame] | 60 | |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 61 | /* checks zstd decompression type */ |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 62 | ZWRAP_decompress_type ZWRAP_getDecompressionType(void); |
inikep | d755717 | 2016-09-22 11:52:00 +0200 | [diff] [blame] | 63 | |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 64 | /* checks if zstd decompression is used for a given stream */ |
| 65 | int ZWRAP_isUsingZSTDdecompression(z_streamp strm); |
inikep | d755717 | 2016-09-22 11:52:00 +0200 | [diff] [blame] | 66 | |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 67 | /* Similar to inflateReset but preserves dictionary set using inflateSetDictionary. |
inikep | 856f91e | 2016-09-27 17:14:04 +0200 | [diff] [blame^] | 68 | inflate() will return Z_NEED_DICT only for the first time what will improve decompression speed. |
| 69 | For zlib streams this method redirects to inflateReset. */ |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 70 | int ZWRAP_inflateResetWithoutDict(z_streamp strm); |
inikep | d755717 | 2016-09-22 11:52:00 +0200 | [diff] [blame] | 71 | |
| 72 | |
inikep | 3eabe9b | 2016-05-12 17:15:41 +0200 | [diff] [blame] | 73 | #if defined (__cplusplus) |
| 74 | } |
| 75 | #endif |
| 76 | |
| 77 | #endif /* ZSTD_ZLIBWRAPPER_H */ |