1. How to obtain zlib
The home page of zlib is: http://www.zlib.net/
2. Use VC ++ 6.0 to open
DownloadSource codeDecompress and open. The vc6.0 project has been created. In \ projects \ visualc6. double-click zlib. DSW, you can see in VC ++ 6.0 that there are three projects: zlib is the library file (select Win32 lib debug/release for compilation settings), and how the project example uses zlib. lib example: How does the project minigzip use the zlib example to read and write the .gz file (*. GZ files are usually used in Linux ).
3. How to join my project
Compile zlib. after Lib, you get all the files required to call a static library (zlib. lib, zlib. h, zconf. h ). I don't need to talk about how to call the static library.
4. What can zlib do?
Let's take a look at all the functions provided by zlib in zlib. h, see a bunch of macros do not dizzy, in fact, is to be compatible with various compilers and some type definitions. the prototype Declaration of the major functions will not be affected by these things.
There are several key functions:
(1) int compress (bytef * DEST, ulogfn * destlen, const bytef * Source, ulong sourcelen );
Compressing the source buffer into a destination buffer is as simple as a function.
(2) int compress2 (bytef * DEST, ulofgx destlen, const bytef * Source, ulong sourcelen, int level );
Similar to the previous function, a single parameter can specify the relationship between the compression quality and the compression quantity (0-9). If you are not sure about this parameter, you don't need to care too much about it, just understand the truth: It takes more time to get a high compression ratio.
(3) ulong compressbound (ulong sourcelen );
Calculate the required buffer length. if you want to know how much data is compressed before compression, you can use this function to calculate the result, however, it ensures that the actual output length must be smaller than the calculated length.
(4) int uncompress (bytef * DEST, ulogfn * destlen, const bytef * Source, ulong sourcelen );
Decompress the package (see the name for details :)
(5) deflateinit () + deflate () + deflateend ()
The three functions are used in combination to complete the compression function. For details about the usage, refer to example. c's test_deflate () function. in fact, the compress () function is implemented internally using these three functions (compress of the zlib project. c file)
(6) inflateinit () + inflate () + inflateend ()
Similar to (5), the decompression function is completed.
(7) functions starting with GZ. used to operate *. GZ files are called in a similar way as stdio files. for more information, see example. c's test_gzio () function is very easy.
(8) other functions, such as obtaining a version, will not be mentioned.
Conclusion: As long as there are two functions: compress () and uncompress (), It is enough in most applications.