分享

How to use Zlib compression? | NewLC

 smallarmy 2008-02-15
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:

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多