How to use Zlib compression?

Login to reply to this topic.
Wed, 2005-03-30 03:09
Joined: 2005-02-08
Forum posts: 4
Does anyone know how to use the Zlib compression library for Series 60 2.0? I've peeped at the various header files, such as ezcompressor.h etc, but they are way too difficult to understand for me.

What I want to do is compress a file.

Thanks for any help.

Wed, 2005-03-30 05:20
Joined: 2004-12-16
Forum posts: 50
How to use Zlib compression?
you have to inherit MEZBufferManager and implement its function.

For compression

Code:
MEZBufferManager* iBufferManager;
TBuf8<100> Source;
TBuf8<100> Dest;
_LIT(Path,"C:\\Nokia\\Others\\Problem.txt");
_LIT(Path1,"C:\\Nokia\\Others\\comProblem.txt");
_LIT(Path2,"C:\\Nokia\\Others\\decomProblem.txt");
CEZCompressor* iCompressor=CEZCompressor::NewLC(*this,Z_DEFAULT_COMPRESSION);
RFs fs;

User :: LeaveIfError (fs.Connect());
RFile ProblemFile;
HBufC8* tempBufferPtr = HBufC8::NewLC( 2000);
TPtr8 unCompressed( tempBufferPtr->Des());
if((ProblemFile.Open(fs,Path,EFileRead|EFileWrite|EFileShareAny|EFileStreamText))==KErrNone )
{


ProblemFile.Read(unCompressed);
}
ProblemFile.Close();
HBufC8* iCompressed=HBufC8::NewL(20000); // allocating space for output
TPtr8 ptrCompressed=iCompressed->Des();
iCompressor->CompressL(ptrCompressed,unCompressed);

if((ProblemFile.Replace(fs,Path1,EFileWrite))==KErrNone )
{

ProblemFile.Write(ptrCompressed);
}
ProblemFile.Close();


For decompression      
         
         
Code:
CEZDecompressor* iDecompressor=CEZDecompressor::NewLC(*this);

HBufC8* ideCompressed=HBufC8::NewL(20000); // allocating space for output
TPtr8 ptrdeCompressed=ideCompressed->Des();
iDecompressor->DecompressL(ptrdeCompressed,ptrCompressed);
if((ProblemFile.Replace(fs,Path2,EFileWrite))==KErrNone )
{

ProblemFile.Write(ptrdeCompressed);
}
ProblemFile.Close();
fs.Close();
TBool def=iCompressor->DeflateL();
}
Code:
Tue, 2005-08-23 13:46
Joined: 2004-06-29
Forum posts: 109
Re: How to use Zlib compression?
Hi Rose,

I am looking for a routine which does decompress the "deflated" content, which I receive via a HTTP response. However, until now I could not get my code to work. I have studied your code example above, and am a bit confused about your DecompressL() usage. Since DecompressL is a static method, it is AFAIK not necessary to instatiate such an object with NewL...

Or am I wrong, and this is the reason why my code does not work?

Thanks for any hint, Marcel
  • Login to reply to this topic.