A library with portability for any operating system.
zlib is a cross-platform data compression library written by Jean-loup Gailly and Mark Adler as a generalization of the DEFLATE algorithm used in their gzip data compression program.
The first public version, originally intended for use in the libpng library, was released on May 1, 1995. zlib is distributed under an open-source license, the zlib license.
Currently, zlib is a de facto standard for compressing data in portable documents. Hundreds of applications for Unix and similar operating systems (like Linux) use it and its use is increasing in other systems (like Microsoft Windows and Palm OS).
Due to its high portability and its low memory requirements, zlib is also used in many embedded devices.
On Zlib’s official website you can find all documentation on how to implement it in your code. However, the examples are done using C language and the basic example is done using stdin and stdout.
But in this case I created a code in C++ with classes and you can use it without stdin and stdout, just invoke it like this:
Installation
First of all you need to have it (the library) on your system, most likely there will already be, but if not you can install it as follows:
Example of systems using APT.
Use
To COMPACT just run the generated binary and the file you want to compress:
The .Z (uppercase Z) extension file will be generated
Just check in the directory that ran the binary that there will be a file named: compressed file.txt.Z.
To UNZIP, just run the generated binary and the file you want to unzip with a .Z extension: The content will be extracted and will generate the: file.txt
I actually modified and adapted this example which is a minizip and the most important parts are commented out, but it’s easy to understand. I organized it into 4 files that are:
zpipe.hpp
zpipe.cpp
main.cpp
And finally a Makefile for us to compile by running only the make command.
Well, simple, right?! This is just an example for single files, for more details see the documentation: