The Zip Compression Library, EZLib provides stream and file compression and decompression functionality for the Symbian platforms. The files can be compressed to two formats namely zip and gzip. Compression and Decompression are performed iteratively, till the completion of required task.
The following code demonstrates a compression procedure.
/* * Compresses the file into a zip file using the EZlib component. * It is assumed that the input and output file names are contained in a * provided ini file. */ void CEZlibEZipTests::DoEZlibDeflateL() { RFs iFs; iFS.connect(); //Open input file _LIT(KInputFileLocation, "c:\\private\\E80000B7\\zip\\input\\input.doc"); TFileName inputFile(KInputFileLocation); RFile input; err = input.Open(iFs, inputFile, EFileStream | EFileRead | EFileShareExclusive); if(err != KErrNone) { INFO_PRINTF1(KOpenFileError); User::Leave(err); } //open output file _LIT(KOutputFileLocation, "c:\\private\\E80000B7\\zip\\input\\output.zip"); TFileName outputFile(KOutputFileLocation); RFile output; err = output.Replace(iFs, outputFile, EFileStream | EFileWrite | EFileShareExclusive); if(err != KErrNone) { INFO_PRINTF1(KCreateFileError); User::Leave(err); } CEZFileBufferManager *bufferManager = CEZFileBufferManager::NewLC(input, output); CEZCompressor *compressor = CEZCompressor::NewLC(*bufferManager, aLevel, aWindowBits, aMemLevel, aStrategy); while(compressor->DeflateL()) { } output.Close(); input.Close(); iFS.Close(); }
The decompression of a .zip file can be achieved through the following the steps:
Pass the input and output files as parameters to construct an instance of CEZFileBufferManager . This returns a pointer to CEZFileBufferManager ( buffer).
Pass the buffer to the object of the CEZDecompressor class.
CEZDecompressor::InflateL() is called repeatedly until the decompression is complete.
The following code demonstrates the decompression procedure.
/* Decompresses the file contained in a Zip file using the EZlib component. * It is assumed that the input and output file names are contained in a * provided ini file. */ void CEZlibEZipTests::DoEZlibInflateL() { RFs iFs; iFS.connect(); //Open input file _LIT(KInputFileLocation, "c:\\private\\E80000B7\\zip\\input\\output.zip"); TFileName inputFile(KInputFileLocation); RFile input; err = input.Open(iRfs, inputFile, EFileStream | EFileRead | EFileShareExclusive); if(err != KErrNone) { INFO_PRINTF1(KOpenFileError); User::Leave(err); } //open output file _LIT(KOutputFile, "c:\\private\\E80000B7\\zip\\input\\input.doc"); TFileName outputFile(KOutputFile); RFile output; err = output.Replace(iFs, outputFile, EFileStream | EFileWrite | EFileShareExclusive); if(err != KErrNone) { INFO_PRINTF1(KCreateFileError); User::Leave(err); } CEZFileBufferManager *bufferManager = CEZFileBufferManager::NewLC(input, Output); CEZDecompressor *decompressor = CEZDecompressor::NewLC(*bufferManager, aWindowBits); while(decompressor->InflateL()) { } output.Close(); input.Close(); ifs.Close(); }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.