Nokia N97 SDK
Example Applications Guide

Libz usage example "OpenCLibz : Compresses anything and Everything "

1. About this Example
2. Prerequisites
3. Design and Implementation


1. About this Example

Libz example demonstrates how to use libz library to compress files and decompress it.

Any kind of file (txt, doc, xls, xml, mpeg, ppt, mp3 etc) can be compressed .


2. Prerequisites

This example requires familiarity with the C programming language.


3. Design and Implementation

3.1 Capabilities

Program capabilities are defined in OpenCLibz.mmp: CAPABILITY is None

3.2 Implementation details of Application

OpenCLibz 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 to enter the mode to process.

Here we have to choose the strategy to compress. The strategy parameter is used to select the compression algorithm.

When asked to compress, it reads the file and then compresses it using libz api's and then stores the compressed content in a compressed (.gz) file.

If you want to decompress, type d.

When asked to decompress, it opens the compressed (.gz) file using libz api's and then reads the content and decompresses it.

If you want to check what happens to the content of the string after compression then type s. Here you can enter the string you want and see the data in compressed format .

This option is kept 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

3.3 Some usage tips

(drive letter):\[(folder name)\]filename.

  1. To get : on phone you have to press 1 few times.
  2. To get \ on phone you have to press 1 few times.
  3. 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.
  4. To press enter on phone we are supposed to press 0 four times.

3.4 Cross platform usage

We can compress the file on any platform and uncompress it on any other platform.

For example Using Unix's gzip files can be compressed and compressed files have .gz extension. Using this application you can decompress the files created by gzip. Otherwise we can compress the files using my example application and decompress it 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.

3.5 Files used

This application has following components:

All the components are written in pure C-code.

The application has its own icon and can be launched from the UI both in the emulator and in the device.

3.6 Api's used

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

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


© Nokia 2009

Back to top