gzip - How to compress and uncompress gzipped files in C/C+...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
How to compress and uncompress gzipped files in C/C++ ***************************************************** This is done using the zlib library (see www.zlib.net, which has much more info on the interface and on how to use the library in other languages such as Perl and Java). Here is some example code that takes an unsigned char array a, compresses it into another unsigned char array b, and then uncompresses b into c (make sure there is enough space in the destination arrays): #include <zlib.h> unsigned char a[1000]; unsigned char b[1000]; unsigned char c[1000]; int compressedSize, uncompressedSize; int status /* fill array a with data */ uncompressedSize = 800; for (i = 0; i < uncompressedSize; a[i] = (unsigned char)(i & 255); status = compress(b, &compressedSize, a, uncompressedSize); status = uncompress(c, &uncompressedSize, b, compressedSize); In this code, compress and uncompress are functions provided by zlib and defined as follows (from http://www.zlib.net/manual.html#Utility%20functions):
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/07/2010 for the course CS 6913 taught by Professor Torsensuel during the Spring '10 term at NYU Poly.

Ask a homework question - tutors are online