deflateCopy -- copy compression stream


#include <zlib.h>

int deflateCopy(z_streamp dest, z_streamp source);


The deflateCopy() function shall copy the compression state information in source to the uninitialized z_stream structure referenced by dest.

On successful return, dest will be an exact copy of the stream referenced by source. The input and output buffer pointers in next_in and next_out will reference the same data.

Return Value

On success, deflateCopy() shall return Z_OK. Otherwise it shall return a value less than zero to indicate the error.


On error, deflateCopy() shall return a value as described below:


The state in source is inconsistent, or either source or dest was NULL.


Insufficient memory available.

Application Usage (informative)

This function can be useful when several compression strategies will be tried, for example when there are several ways of pre-processing the input data with a filter. The streams that will be discarded should then be freed by calling deflateEnd(). Note that deflateCopy() duplicates the internal compression state which can be quite large, so this strategy may be slow and can consume lots of memory.