Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Protected Attributes | List of all members
drwnCompressionBuffer Class Reference

Utility class for compressing data using the zlib library. More...

Public Member Functions

unsigned int originalBytes () const
 number of uncompressed bytes
unsigned int compressedBytes () const
 number of compressed bytes
void compress (const unsigned char *data, unsigned int size)
 compress size bytes of data into buffer
void decompress (unsigned char *data) const
 decompress buffer into data
size_t numBytesOnDisk () const
 number of bytes required to store buffer contents on disk
bool write (ostream &os) const
 write compression buffer to output stream
bool read (istream &is)
 read compression buffer from input stream
drwnCompressionBuffer clone () const
 clone the buffer
void free ()
 free all memory associated with the buffer

Protected Attributes

unsigned char * _data
unsigned int _bytesAllocated
unsigned int _bytesOriginal
unsigned int _bytesCompressed

Detailed Description

Utility class for compressing data using the zlib library.

The class holds compressed data. Copying the buffer does not copy the data (i.e., a shallow copy is performed). To copy the data use the clone member function. When decompressing data enough space must be allocated in output buffer. The following code snippet shows example usage:

// compress a string
string inputStr = getStringToCompress();
buffer.compress((unsigned char *)inputStr.c_str(), inputStr.size());
DRWN_LOG_MESSAGE("compressed " << buffer.originalBytes() << " bytes to "
<< buffer.compressedBytes() << " bytes");
// decompress a string
string recoveredStr;
buffer.decompress((unsigned char *)&recoveredStr[0]);
This class will simply copy data without compressing if compiled without DRWN_HAS_ZLIB defined.

The documentation for this class was generated from the following files: