The main objective of creating a zstd wrapper for zlib is to allow a quick and smooth transition to zstd for projects already using zlib.
To build the zstd wrapper for zlib the following files are required:
The first two files are required by all projects using zlib and they are not included with the zstd distribution. The further files are supplied with the zstd distribution.
Let's assume that your project that uses zlib is compiled with: gcc project.o -lz
To compile the zstd wrapper with your project you have to do the following:
#include "zlib.h"
to #include "zstd_zlibwrapper.h"
The linking should be changed to: gcc project.o zlib_wrapper.o -lz -lzstd
After embedding the zstd wrapper within your project the zstd library is turned off by default. Your project should work as before with zlib. There are two options to enable zstd compression:
-DZWRAP_USE_ZSTD=1
(or using #define ZWRAP_USE_ZSTD 1
before #include "zstd_zlibwrapper.h"
)void useZSTD(int turn_on)
function (declared in #include "zstd_zlibwrapper.h"
) There is no switch for zstd decompression because zlib and zstd streams are automatically detected and decompressed using a proper library.We have take the file test/example.c
from the zlib library distribution and copied it to zlibWrapper/examples/example.c. After compilation and execution it shows the following results:
zlib version 1.2.8 = 0x1280, compile flags = 0x65 uncompress(): hello, hello! gzread(): hello, hello! gzgets() after gzseek: hello! inflate(): hello, hello! large_inflate(): OK after inflateSync(): hello, hello! inflate with dictionary: hello, hello!
Then we have changed #include "zlib.h"
to #include "zstd_zlibwrapper.h"
, compiled the example.c file with -DZWRAP_USE_ZSTD=1
and linked with additional zlib_wrapper.o -lzstd
. We were forced to turn off the following functions: test_gzio
, test_flush
, test_sync
which use currently unsupported features. After running it shows the following results:
zlib version 1.2.8 = 0x1280, compile flags = 0x65 uncompress(): hello, hello! inflate(): hello, hello! large_inflate(): OK inflate with dictionary: hello, hello!
The script used for compilation can be found at zlibWrapper/Makefile.
After enabling zstd compression not all native zlib functions are supported. When calling unsupported methods they print error message and return an error value.
Supported methods:
Ignored methods (they do nothing):
Unsupported methods: