Open C libz Example

The example demonstrates how to use the libz library to compress a file and decompress it. The library can compress and decompress any kind of file (txt, doc, xls, xml, mpeg, ppt, mp3 etc).


Click on the following link to download the example:

Click: browse to view the example code.

Design and Implementation

The following sections provide more information about the steps that the example performs.


Program capabilities are defined in openclibz.mmp: CAPABILITY None

Implementation details of EXE

This example is a console based application. This application can be launched from the icon (openclibz) in installed folder and also from eshell. When we launch it through icon it prompts the user to enter the mode to process. The strategy parameter is used to select the compression algorithm. For compressing a file, it reads the file and then compresses it using the API of the libz library and then stores the compressed content in a (.gz) file. If you want to decompress, type d. For decompressing a file, it opens the compressed (.gz) file using libz API's and then reads the content and decompresses it . To check what happens to the content of the string after compression then type s. Enter the string you want and see the data in compressed format . This option is to demonstrate compression of string using libz API's.

To run this application through eshell:

 Usage :  openclibz [-d] [-f] [-h] [-r] [-1 to -9] [files...]
   -d : decompress
   -f : compress with Z_FILTERED
   -h : compress with Huffman encoding
   -r : compress with run-length encoding
   -1 to -9 : compression level
   files : absolute path of files

Some usage tips

Once you choose compression process, enter the file name. You should provide absolute path of the file you want to compress. (drive letter):\[(folder name)\]filename. To get : on phone you have to press 1 few times. To get on phone you have to press 1 few times. To get on emulator is bit tricky. If you are lucky then pressing 1 will get it for you, otherwise change the mode. using "\ BUTTON" (Just above the enter button in the keyboard) and then try pressing 1. To press enter on phone we are supposed to press 0 four times.

Cross platform usage

We can compress the file on any platform and uncompress it on any other platform. For example Unix's gzip files can be compressed using the example application and decompressed using Unix's gunzip. Compression can be done in a single step, if the buffers are large enough; or compression can be done by repeated calls of the compression function. In the second scenario, application must provide more input and consume the output (providing more output space) before each call.

APIs Used

compress, uncompress, gzopen, gzclose, gzread, gzwrite, gzerror from libz library

fopen, fclose, fread, fwrite, mmap, munmap, fstat, unlink, printf, scanf from libc library

Building and Using

The Symbian build process describes how to build this example application.

To build the example application, go to the openclibz\group directory and build the application. The definition for the whole application can be found in the bld.inf file in the group subdirectory of the applications main directory.