Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site













SourceForge.net Logo

Zlib

 

class Zlib

This class encapsulates zlib library to provide compression/decompression utility.

Encapsulation is specifically designed to allow streaming mode of operations. Input data are fed using Put method and can be either obtained at output as partial String, or through output callback. If using String, it is also always possible to clear this output partial String to conserve memory.

 

Public Method List

 

Callback2<const void *, intWhenOut

Output callback. Represents "consumer function": When there are output data available, they are passed out using this callback. Default value stores data into output String inside Zlib.

 


 

void Compress()

Sets Zlib into compression mode ("deflate" in zlib terminology).

 


 

void Decompress()

Sets Zlib into decompression mode ("inflate" in zlib terminology).

 


 

void Put(const void *ptr, int size)

void Put(const String& s)

Puts a block of data to be processed (compressed or decompressed based on mode) by Zlib.

 


 

void End()

Signals the end of input stream.

 


 

void Clear()

Resets Zlib to initial state (throws out data).

 


 

const String& Get() const

operator const String&() const

const String& operator~() const

Returns current output String (it only gets created if WhenOut is not redirected somewhere else).

 


 

void ClearOut()

Clears output String. Can be called anytime.

 


 

dword GetCRC() const

Returns CRC of uncompressed stream, if CRC mode is active.

 


 

bool IsError() const

Returns true if there was error processing input.

 


 

String GetGZipName() const

If GZip mode is active and Gzip header is processed, returns the name of file.

 


 

String GetGZipComment() const

If GZip mode is active and Gzip header is processed, returns the gzip comment.

 


 

Zlib& GZip(bool gzip_ = true)

Activates GZip mode. In this mode Zlib is able to directly process .gzip file format.

 


 

Zlib& Header(bool hdr_ = true)

Activates zlib header (see zlib documentation for details).

 


 

Zlib& NoHeader()

Same as Header(false).

 


 

Zlib& CRC(bool b = true)

Activates CRC mode. In this mode, Zlib gathers CRC of uncompressed data that can be at the end obtained by GetCRC method.

 


 

Zlib& NoCRC()

Same as CRC(false).

 


 

Zlib& ChunkSize(int n)

Sets the maximum amount of input or output data to be processed in single zlib call.

 


 

Zlib& Level(int compression_lvl)

Sets the compresison level. Must be 1..9. Default level is 6.

 


 

Zlib()

Constructor.

 


 

~Zlib()

Destructor.

 

 

Compression / decompression functions

 

int64 ZCompress(Stream& out, Stream& in, int64 size, Gate2<int64, int64progress = false, bool hdr = true)

int64 ZCompress(Stream& out, Stream& in, Gate2<int64, int64progress = false)

String ZCompress(const void *data, int64 len, Gate2<int64, int64progress = false)

String ZCompress(const String& s, Gate2<int64, int64progress = false)

Compresses raw data using zlib from input stream in, memory data, len or input string s to output stream out (in this case returns a number of bytes written or negative integer to signal error) or into String return value (returns IsVoid String on error). progress can be used to track progress of operation, returning true cancels operation. Parameter hdr can be used to switch-off zlib header (see zlib documentation for details).

 


 

int64 ZDecompress(Stream& out, Stream& in, int64 size, Gate2<int64, int64progress = false, bool hdr = true)

int64 ZDecompress(Stream& out, Stream& in, int64 size, Gate2<int64, int64progress = false)

int64 ZDecompress(Stream& out, Stream& in, Gate2<int64, int64progress = false)

String ZDecompress(const void *data, int64 len, Gate2<int64, int64progress = false)

String ZDecompress(const String& s, Gate2<int64, int64progress = false)

Decompresses raw data using zlib from input stream in, memory data, len or input string s to output stream out (in this case returns a number of bytes written or negative integer to signal error) or into String return value (returns IsVoid String on error). progress can be used to track progress of operation, returning true cancels operation. Parameter hdr can be used to switch-off zlib header (see zlib documentation for details).

 


 

int64 GZCompress(Stream& out, Stream& in, int64 size, Gate2<int64, int64progress = false)

int64 GZCompress(Stream& out, Stream& in, Gate2<int64, int64progress = false)

String GZCompress(const void *data, int len, Gate2<int64, int64progress = false)

String GZCompress(const String& s, Gate2<int64, int64progress = false)

Compresses raw data into gzip file format from input stream in, memory data, len or input string s to output stream out (in this case returns a number of bytes written or negative integer to signal error) or into String return value (returns IsVoid String on error). progress can be used to track progress of operation, returning true cancels operation.

 


 

int64 GZDecompress(Stream& out, Stream& in, int64 size, Gate2<int64, int64progress = false)

int64 GZDecompress(Stream& out, Stream& in, Gate2<int64, int64progress = false)

String GZDecompress(const void *data, int len, Gate2<int64, int64progress = false)

String GZDecompress(const String& s, Gate2<int64, int64progress = false)

Decompresses raw data into gzip file format from input stream in, memory data, len or input string s to output stream out (in this case returns a number of bytes written or negative integer to signal error) or into String return value (returns IsVoid String on error). progress can be used to track progress of operation, returning true cancels operation.

 


 

bool GZCompressFile(const char *dstfile, const char *srcfile, Gate2<int64, int64progress = false)

bool GZCompressFile(const char *srcfile, Gate2<int64, int64progress = false)

Compresses file into gzip format. If dstfile is not present, the name is created by appending .gz extension to srcfile. Returns true on success.

 


 

bool GZDecompressFile(const char *dstfile, const char *srcfile, Gate2<int64, int64progress = false)

bool GZDecompressFile(const char *srcfile, Gate2<int64, int64progress = false)

Decompresses file from gzip format. If dstfile is not present, the name is created by removing .gz extension to srcfile. If srcfile does not have .gz extension, function returns false to signal error and does nothing. Returns true on success.

 

Last edit by cxl on 10/20/2014. Do you want to contribute?. T++