Wednesday, June 1, 2011

ZLib Static Library for Qt/Symbian

I've been surfing the internet looking for the zlib static library -which is missing from the Qt/Symbian SDK. I downloaded and installed some old Symbian SDKs and finally found the needed files.

You can download them from this link


Here is a code example of how I used it:

LIBS+= -lefsrv -lezlib -leikcore -lcone

#include <ezgzip.h>
#include <f32file.h>
#include <ezcompressor.h>
#include <ezdecompressor.h>
#include <ezfilebuffer.h>
#include <eikenv.h>

void CompressFileL(QString sourceFile, QString destinationFile)
{
    TPtrC16 aSrcFile(reinterpret_cast<const TUint16*>(sourceFile.utf16()));
    TPtrC16 aDesFile(reinterpret_cast<const TUint16*>(destinationFile.utf16()));
    
    CEZFileBufferManager* fileCompressor = NULL;
    CEZCompressor* comprsr = NULL;
    RFs iFs = CEikonEnv::Static()->FsSession();
    RFile inFile,outFile;
    User::LeaveIfError(inFile.Open(iFs,aSrcFile,EFileRead));
    CleanupClosePushL(inFile);
    User::LeaveIfError(outFile.Create(iFs,aDesFile,EFileRead | EFileWrite));
    CleanupClosePushL(outFile);

    fileCompressor = CEZFileBufferManager::NewLC(inFile,outFile);
    comprsr = CEZCompressor::NewLC(*fileCompressor,CEZCompressor::EBestCompression);

    TBool res = EFalse;
    do
    {
        res = comprsr->DeflateL();
    }while(res);

    CleanupStack::PopAndDestroy(4);//inputFile,outFile,fileCompressor,comprsr
}


void DecompressFileL(QString sourceFile, QString destinationFile)
{
    TPtrC16 aSrcFile(reinterpret_cast<const TUint16*>(sourceFile.utf16()));
    TPtrC16 aDesFile(reinterpret_cast<const TUint16*>(destinationFile.utf16()));
    
    CEZFileBufferManager* fileCompressor = NULL;
    CEZDecompressor* decomprsr = NULL;
    RFs iFs = CEikonEnv::Static()->FsSession();
    RFile inFile,outFile;
    User::LeaveIfError(inFile.Open(iFs,aSrcFile,EFileRead));
    CleanupClosePushL(inFile);
    User::LeaveIfError(outFile.Create(iFs,aDesFile,EFileRead | EFileWrite));
    CleanupClosePushL(outFile);

    fileCompressor = CEZFileBufferManager::NewLC(inFile,outFile);
    decomprsr = CEZDecompressor::NewLC(*fileCompressor);

    TBool res = EFalse;
    do
    {
        res = decomprsr->InflateL();
    }while(res);

    CleanupStack::PopAndDestroy(4);//inputFile,outFile,fileCompressor,decomprsr
}

No comments:

Post a Comment