gzflush -- flush a compressed file stream


#include <zlib.h>

int gzflush(gzFile file, int flush);


The gzflush() function shall flush pending output to the compressed file stream identified by file, which must be open for writing.

Flush Operation

The parameter flush determines which compressed bits are added to the output file. If flush is Z_NO_FLUSH, gzflush() may return with some data pending output, and not yet written to the file.

If flush is Z_SYNC_FLUSH, gzflush() shall flush all pending output to file and align the output to a byte boundary. There may still be data pending compression that is not flushed.

If flush is Z_FULL_FLUSH, all output shall be flushed, as for Z_SYNC_FLUSH, and the compression state shall be reset. There may still be data pending compression that is not flushed.

Rationale: Z_SYNC_FLUSH is intended to ensure that the compressed data contains all the data compressed so far, and allows a decompressor to reconstruct all of the input data. Z_FULL_FLUSH allows decompression to restart from this point if the previous compressed data has been lost or damaged. Flushing is likely to degrade the performance of the compression system, and should only be used where necessary.

If flush is set to Z_FINISH, all pending uncompressed data shall be compressed and all output shall be flushed.

Return Value

On success, gzflush() shall return the value Z_OK. Otherwise gzflush() shall return a value to indicate the error, and may set the error number associated with the compressed file stream file.

Note: If flush is set to Z_FINISH and the flush operation is successful, gzflush() will return Z_OK, but the compressed file stream error value may be set to Z_STREAM_END.


On error, gzwrite() shall return an error value, and may set the error number associated with the stream identified by file to indicate the error. Applications may use gzerror() to access this error value.


An underlying base library function has indicated an error. The global variable errno may be examined for further information.


The stream is invalid, is not open for writing, or is in an invalid state.


no compression progress is possible (see deflate()).


Insufficient memory available to compress.