Compressing and Decompressing File - GZip Format

The Zip Compression Library, EZLib provides file compression and decompression functionality for the Symbian platforms. The files can be compressed to two formats namely zip and gzip. gzip is normally used to compress single files.

Compression and Decompression are performed iteratively, till the completion of required task.


  1. Input the source file and the name of the target gzip file to an instance of the CEZFileToGZip class.

  2. CEZFileToGZip::DeflateL() is used to compress the file.

The code below depicts how the source file "input.doc" file is converted to target file "output.gz".

/*
 * If input and output file names are not specified then it is assumed that 
 * the file names are contained in a provided .ini file.
 */

void CEZlibEZipTests::DoEZlibGZipDeflateL()
    {
    

 RFs iFs;
 iFS.connect();
    

    //Open the source file in read mode
_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);
        }   
    
    
    //create a target file

_LIT(KOutputFileLocation, "c:\\private\\E80000B7\\zip\\input\\output.gz");
TFileName outputFile(KOutputFileLocation);


    
    CEZFileToGZip *compressor = CEZFileToGZip::NewLC(iFs, outputFile, input);

    
    while(compressor->DeflateL())
        {       
        }   
input.Close();
    iFS.Close();
        
    
    }

The decompression of a gzip file can be achieved through the following the steps:

  1. Pass the file to the constructor of the CEZGZipToFile class.

  2. CEZGZipToFile::InflateL() is called repeatedly to complete the decompression.

The code below depicts how "output.gz" is decompressed to "input.doc".

/*
 *  If  input and output file names are not specified then it is assumed that 
 * the file names are contained in a provided .ini file.
 */
void CEZlibEZipTests::DoEZlibGZipInflateL()
    {
      RFs iFs;
  iFS.connect();
    

    //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);
        }    
        

//input file


_LIT(KInputFileLocation, "c:\\private\\E80000B7\\zip\\input\\output.gz");
TFileName inputFile(KInputFileLocation);

    CEZGZipToFile *decompressor = CEZGZipToFile::NewLC(iFs, inputFile, output);

        while(decompressor->InflateL())
        {        
        }    

        output.Close();
    iFS.Close();
    ;
    }