Compression filter using zlib. More...
Public Member Functions
|Compressor (int level=-1, std::size_t bufferSize=16384)|
|void||pass (Chunk &chunk)|
|Do a compression step. |
|void||finish (Chunk &out)|
|Finish the compression operation. |
|unsigned int||getChecksum () const|
|Get checksum value after compression. |
|void||apply (Chunk &chunk)|
|Completelly filter the provided data. |
Protected Member Functions
|Wait for the pipeline to terminate. |
|Handy cleanup. |
|void||setStream (Stream *stream)|
|Change the owning stream. |
Compression filter using zlib.
This filter applies ZLib compression to each chunk of data passed. It keeps it's internal compression state between chunks.
Compressor computes the adler32 checksum of the decompressed data. You can obtain it by calling the function getChecksum(). You can store the checksum in some place (a database, a file, etc), and use it later when decompressing the same data, to check if integrity was maintained (if it wasn't corrupted from the outside).
Example of compressing a chunk of data in one step.
cx::Chunk myData; // fill myData ... // compress myData cx::Compressor compressor; compressor.apply(myData); unsigned int checksum = compressor.getChecksum();
Example of using the Compressor in a stream:
cx::File inputFile("original.txt"); cx::File outputFile("compressed.dat"); cx::Compressor compressor; cx::Stream stream(inputFile, compressor, outputFile); unsigned int checksum = compressor.getChecksum();
|cx::Compressor::Compressor||(||int|| level =
|std::size_t|| bufferSize = |
Initialize the zlib state.
The first argument is the compression rate, ranging from 0 to 9. Level 0 means no compression, level 9 means best (but slower) compression.
The constructor may throw a cx::DataException if the zlib fails it's initialization (due to invalid compression level for instance).
|takeChecksum||Function pointer that will receive the checksum.|
|level||Compression level (0-9).|
|bufferSize||Size of the internal zlib buffer. The bigger, the better (but don't put all your available memory on it).|
Clean up the zlib state.
|void cx::Filter::apply||(||Chunk &||chunk||)||
Completelly filter the provided data.
|[in,out]||chunk||The data to be filtered. It is directly modified by the filter.|
This function safelly wait for the stream conclusion (if assigned), so that classes can finally clean up their resources. This function should be called on derived classes destructors before cleaning up their critical structures. Otherwise, a stream may try to access strucutures during their destruction.
|void cx::Compressor::finish||(||Chunk &||out||)||
|unsigned int cx::Compressor::getChecksum||(||)||const|
Get checksum value after compression.
|void cx::Compressor::pass||(||Chunk &||chunk||)||
|void cx::ConcreteNode::setStream||(||Stream *||stream||)||
Change the owning stream.
This function is called by Stream itself when being constructed.
Wait for the pipeline to terminate.
If it's being used on a pipeline stream, it blocks execution until the stream finish.