{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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): int compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); Compresses the source buffer into the destination buffer. sourceLen is the
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Ask a homework question - tutors are online