Sunday, July 22, 2007

Compress / Decompress A File with less memory usage.

void CompressAFile(TDesC& aSrcName, TDesC& aDstName)
{
RFs fs;
User::LeaveIfError(fs.Connect());
fs.SetSessionPath(_L("C:\\")); // change to your req. Path

RFile file;
TInt err = file.Open(fs,aDstName,EFileRead);

CEZFileToGZip* zip = CEZFileToGZip::NewLC(fs, aSrcName, file);
TInt tempi = 0;
while(zip->DeflateL()) // while loop req. donot remove
{
tempi++;
}
CleanupStack::PopAndDestroy(); // zip

file.Close();
fs.Close();
}


void DeCompressAFile(TDesC& aSrcName, TDesC& aDstName)
{
RFs fs;
User::LeaveIfError(fs.Connect());
fs.SetSessionPath(_L("C:\\")); // change to your req. Path

RFile file;
TInt err = file.Open(fs,aDstName,EFileRead);

CEZGZipToFile *zip = CEZGZipToFile::NewLC(fs, aSrcName, file);
TInt tempi = 0;
while(zip->InflateL()) // while loop req. donot remove
{
tempi++;
}
CleanupStack::PopAndDestroy(); // zip

file.Close();
fs.Close();
}

1 comment:

Jayakumar said...
This comment has been removed by the author.
stats counter