The Zip Compression Library, EZLib provides stream compression and decompression functionality for the Symbian platforms. This tutorial summarizes the procedure involved in the compression and decompression of memory streams by EZLib.
The functions used
for memory stream compression and decompression are provided by the CEZCompressor
class.
The compression can be executed in single or multiple steps. This is depenedent on the buffer size of the memory stream. Small buffers are compressed in a single step. Larger buffers are compressed in small chunks repeatedly till the entire buffer is compressed. Clients must respond to callbacks from the library to provide information and resources required to complete the task.
MEZBufferManager
.
CEZCompressor
.
CEZCompressor::CompressL()
for small buffers.
CEZCompressor::DeflateL()
repeatedly on larger
buffers until the entire buffer is compressed.
class CBufferManager : public CBase, public MEZBufferManager { public: CBufferManager* CBufferManager::NewLC(); CBufferManager* CBufferManager::NewL(); ~CBufferManager(); void InitializeL(CEZZStream &aZStream); void NeedInputL(CEZZStream &aZStream); void NeedOutputL(CEZZStream &aZStream); void FinalizeL(CEZZStream &aZStream); }; CBufferManager* CBufferManager::NewLC() { CBufferManager* bm = new (ELeave) CBufferManager(); CleanupStack::PushL(bm); return bm; } CBufferManager* CBufferManager::NewL() { CBufferManager* bm = new (ELeave) CBufferManager(); CleanupStack::PushL(bm); CleanupStack::Pop(); return bm; } static void doExampleL() { CBufferManager* bm = CBufferManager::NewLC(); //TInt aLevel = EDefaultCompression, TInt aWindowBits = EMaxWBits, TInt aMemLevel = EDefMemLevel, TStrategy aStrategy = EDefaultStrategy); CEZCompressor* iCEZCompressor = CEZCompressor::NewLC(*bm); // all other flag values are default in its constructer while(icompressor->DeflateL()) { } CleanupStack::PopAndDestroy(2); }
To decompress the memory streams:
Define a buffer manager
that implements MEZBufferManager
.
Create an instance of
the classs CEZDecompressor
.
Invoke CEZDecompressor::DecompressL()
for
small buffers.
Invoke CEZDecompressor::InflateL()
repeatedly
on larger buffers until the entire buffer is compressed.