1. download zlib. the attachment is zlib 1.2.3. linux generally comes with 2. decompress the code and open. \ projects \ visualc6 \ zlib. DSW. 3. build: zlib lib debug/zlib lib release, the generated zlib. LIB/zlibd. lib. 4. include the header file zlib in our project. h/zconf. h. Connect to the generated Lib. 5. test code write to file: char * pchdata = "XXX... ";
Gzfile fdata = gzopen (pchfile, "WB ");
Gzwrite (fdata, pchdata, strlen (pchdata ));
Gzclose (fdata); read from file: Char pchdata [2, 1024];
Gzfile fdata = gzopen (pchfile, "rb ");
Int n = gzread (fdata, pchdata, 1024 );
Gzclose (fdata); buffer test: # include <zlib. h> // raw data
Unsigned char pchsrc [] = "XXX ....";
Unsigned long nsclen = sizeof (pchsrc );
// Compressed data
Unsigned char achcomp [1024];
Unsigned long ncomplen = 1024;
// Decompressed data
Unsigned char achuncomp [1024];
Unsigned long nuncomplen= 1024;
// Compression
Compress (achcomp, & ncomplen, pchsrc, nsclen );
// Extract
Uncompress (achuncomp, & nuncomplen, achcomp, ncomplen );
// Display original data information
Printf ("Raw data (% d): \ n % s \ n", nsclen, pchsrc );
// Display compressed data
Printf ("compressed data (% d): \ n % s \ n", ncomplen, achcomp );
// Display the decompressed data
Printf ("extract data (% d): \ n % s \ n", nuncomplen, achuncomp );