0000: 0d 0a 2f 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a ../*=*=*=*=*=*=*
0010: 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a =*=*=*=*=*=*=*=*
0020: 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a =*=*=*=*=*=*=*=*
0030: 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a =*=*=*=*=*=*=*=*
0040: 3d 2a 2f 0d 0a 2f 2a 3d 20 54 68 69 73 20 73 6f =*/../*= This so
0050: 75 72 63 65 20 69 73 20 4d 6f 64 69 66 69 65 64 urce is Modified
0060: 20 61 20 6c 69 74 74 6c 65 20 62 79 20 4b 2e 49 a little by K.I
0070: 4e 41 42 41 2e 20 20 20 20 20 20 20 20 20 20 20 NABA.
0080: 20 20 20 3d 2a 2f 0d 0a 2f 2a 3d 20 20 20 20 20 =*/../*=
0090: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
00a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
00b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
00c0: 20 20 20 20 20 20 3d 2a 2f 0d 0a 2f 2a 3d 20 53 =*/../*= S
00d0: 69 6e 63 65 20 27 58 61 63 52 65 74 74 27 20 64 ince 'XacRett' d
00e0: 6f 65 73 6e 27 74 20 63 6f 6d 70 72 65 73 73 2c oesn't compress,
00f0: 20 49 20 72 65 6d 6f 76 65 64 20 20 20 20 20 20 I removed
0100: 20 20 20 20 20 20 20 20 20 3d 2a 2f 0d 0a 2f 2a =*/../*
0110: 3d 20 20 63 6f 6d 70 72 65 73 73 69 6f 6e 20 63 = compression c
0120: 6f 64 65 73 20 62 79 20 23 69 66 64 65 66 20 4b odes by #ifdef K
0130: 49 5f 47 5a 5f 4e 4f 5f 43 4f 4d 50 52 45 53 53 I_GZ_NO_COMPRESS
0140: 49 4f 4e 20 2e 20 20 20 20 20 20 20 3d 2a 2f 0d ION . =*/.
0150: 0a 2f 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d ./*=*=*=*=*=*=*=
0160: 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d *=*=*=*=*=*=*=*=
0170: 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d *=*=*=*=*=*=*=*=
0180: 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d 2a 3d *=*=*=*=*=*=*=*=
0190: 2a 2f 0d 0a 23 69 66 6e 64 65 66 20 4b 49 5f 47 */..#ifndef KI_G
01a0: 5a 5f 4e 4f 5f 43 4f 4d 50 52 45 53 53 49 4f 4e Z_NO_COMPRESSION
01b0: 0d 0a 23 64 65 66 69 6e 65 20 4b 49 5f 47 5a 5f ..#define KI_GZ_
01c0: 4e 4f 5f 43 4f 4d 50 52 45 53 53 49 4f 4e 0d 0a NO_COMPRESSION..
01d0: 23 65 6e 64 69 66 0d 0a 0d 0a 2f 2a 20 7a 6c 69 #endif..../* zli
01e0: 62 2e 68 20 2d 2d 20 69 6e 74 65 72 66 61 63 65 b.h -- interface
01f0: 20 6f 66 20 74 68 65 20 27 7a 6c 69 62 27 20 67 of the 'zlib' g
0200: 65 6e 65 72 61 6c 20 70 75 72 70 6f 73 65 20 63 eneral purpose c
0210: 6f 6d 70 72 65 73 73 69 6f 6e 20 6c 69 62 72 61 ompression libra
0220: 72 79 0a 20 20 76 65 72 73 69 6f 6e 20 31 2e 31 ry. version 1.1
0230: 2e 33 2c 20 4a 75 6c 79 20 39 74 68 2c 20 31 39 .3, July 9th, 19
0240: 39 38 0a 0a 20 20 43 6f 70 79 72 69 67 68 74 20 98.. Copyright
0250: 28 43 29 20 31 39 39 35 2d 31 39 39 38 20 4a 65 (C) 1995-1998 Je
0260: 61 6e 2d 6c 6f 75 70 20 47 61 69 6c 6c 79 20 61 an-loup Gailly a
0270: 6e 64 20 4d 61 72 6b 20 41 64 6c 65 72 0a 0a 20 nd Mark Adler..
0280: 20 54 68 69 73 20 73 6f 66 74 77 61 72 65 20 69 This software i
0290: 73 20 70 72 6f 76 69 64 65 64 20 27 61 73 2d 69 s provided 'as-i
02a0: 73 27 2c 20 77 69 74 68 6f 75 74 20 61 6e 79 20 s', without any
02b0: 65 78 70 72 65 73 73 20 6f 72 20 69 6d 70 6c 69 express or impli
02c0: 65 64 0a 20 20 77 61 72 72 61 6e 74 79 2e 20 20 ed. warranty.
02d0: 49 6e 20 6e 6f 20 65 76 65 6e 74 20 77 69 6c 6c In no event will
02e0: 20 74 68 65 20 61 75 74 68 6f 72 73 20 62 65 20 the authors be
02f0: 68 65 6c 64 20 6c 69 61 62 6c 65 20 66 6f 72 20 held liable for
0300: 61 6e 79 20 64 61 6d 61 67 65 73 0a 20 20 61 72 any damages. ar
0310: 69 73 69 6e 67 20 66 72 6f 6d 20 74 68 65 20 75 ising from the u
0320: 73 65 20 6f 66 20 74 68 69 73 20 73 6f 66 74 77 se of this softw
0330: 61 72 65 2e 0a 0a 20 20 50 65 72 6d 69 73 73 69 are... Permissi
0340: 6f 6e 20 69 73 20 67 72 61 6e 74 65 64 20 74 6f on is granted to
0350: 20 61 6e 79 6f 6e 65 20 74 6f 20 75 73 65 20 74 anyone to use t
0360: 68 69 73 20 73 6f 66 74 77 61 72 65 20 66 6f 72 his software for
0370: 20 61 6e 79 20 70 75 72 70 6f 73 65 2c 0a 20 20 any purpose,.
0380: 69 6e 63 6c 75 64 69 6e 67 20 63 6f 6d 6d 65 72 including commer
0390: 63 69 61 6c 20 61 70 70 6c 69 63 61 74 69 6f 6e cial application
03a0: 73 2c 20 61 6e 64 20 74 6f 20 61 6c 74 65 72 20 s, and to alter
03b0: 69 74 20 61 6e 64 20 72 65 64 69 73 74 72 69 62 it and redistrib
03c0: 75 74 65 20 69 74 0a 20 20 66 72 65 65 6c 79 2c ute it. freely,
03d0: 20 73 75 62 6a 65 63 74 20 74 6f 20 74 68 65 20 subject to the
03e0: 66 6f 6c 6c 6f 77 69 6e 67 20 72 65 73 74 72 69 following restri
03f0: 63 74 69 6f 6e 73 3a 0a 0a 20 20 31 2e 20 54 68 ctions:.. 1. Th
0400: 65 20 6f 72 69 67 69 6e 20 6f 66 20 74 68 69 73 e origin of this
0410: 20 73 6f 66 74 77 61 72 65 20 6d 75 73 74 20 6e software must n
0420: 6f 74 20 62 65 20 6d 69 73 72 65 70 72 65 73 65 ot be misreprese
0430: 6e 74 65 64 3b 20 79 6f 75 20 6d 75 73 74 20 6e nted; you must n
0440: 6f 74 0a 20 20 20 20 20 63 6c 61 69 6d 20 74 68 ot. claim th
0450: 61 74 20 79 6f 75 20 77 72 6f 74 65 20 74 68 65 at you wrote the
0460: 20 6f 72 69 67 69 6e 61 6c 20 73 6f 66 74 77 61 original softwa
0470: 72 65 2e 20 49 66 20 79 6f 75 20 75 73 65 20 74 re. If you use t
0480: 68 69 73 20 73 6f 66 74 77 61 72 65 0a 20 20 20 his software.
0490: 20 20 69 6e 20 61 20 70 72 6f 64 75 63 74 2c 20 in a product,
04a0: 61 6e 20 61 63 6b 6e 6f 77 6c 65 64 67 6d 65 6e an acknowledgmen
04b0: 74 20 69 6e 20 74 68 65 20 70 72 6f 64 75 63 74 t in the product
04c0: 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 77 documentation w
04d0: 6f 75 6c 64 20 62 65 0a 20 20 20 20 20 61 70 70 ould be. app
04e0: 72 65 63 69 61 74 65 64 20 62 75 74 20 69 73 20 reciated but is
04f0: 6e 6f 74 20 72 65 71 75 69 72 65 64 2e 0a 20 20 not required..
0500: 32 2e 20 41 6c 74 65 72 65 64 20 73 6f 75 72 63 2. Altered sourc
0510: 65 20 76 65 72 73 69 6f 6e 73 20 6d 75 73 74 20 e versions must
0520: 62 65 20 70 6c 61 69 6e 6c 79 20 6d 61 72 6b 65 be plainly marke
0530: 64 20 61 73 20 73 75 63 68 2c 20 61 6e 64 20 6d d as such, and m
0540: 75 73 74 20 6e 6f 74 20 62 65 0a 20 20 20 20 20 ust not be.
0550: 6d 69 73 72 65 70 72 65 73 65 6e 74 65 64 20 61 misrepresented a
0560: 73 20 62 65 69 6e 67 20 74 68 65 20 6f 72 69 67 s being the orig
0570: 69 6e 61 6c 20 73 6f 66 74 77 61 72 65 2e 0a 20 inal software..
0580: 20 33 2e 20 54 68 69 73 20 6e 6f 74 69 63 65 20 3. This notice
0590: 6d 61 79 20 6e 6f 74 20 62 65 20 72 65 6d 6f 76 may not be remov
05a0: 65 64 20 6f 72 20 61 6c 74 65 72 65 64 20 66 72 ed or altered fr
05b0: 6f 6d 20 61 6e 79 20 73 6f 75 72 63 65 20 64 69 om any source di
05c0: 73 74 72 69 62 75 74 69 6f 6e 2e 0a 0a 20 20 4a stribution... J
05d0: 65 61 6e 2d 6c 6f 75 70 20 47 61 69 6c 6c 79 20 ean-loup Gailly
05e0: 20 20 20 20 20 20 20 4d 61 72 6b 20 41 64 6c 65 Mark Adle
05f0: 72 0a 20 20 6a 6c 6f 75 70 40 67 7a 69 70 2e 6f r. jloup@gzip.o
0600: 72 67 20 20 20 20 20 20 20 20 20 20 6d 61 64 6c rg madl
0610: 65 72 40 61 6c 75 6d 6e 69 2e 63 61 6c 74 65 63 er@alumni.caltec
0620: 68 2e 65 64 75 0a 0a 0a 20 20 54 68 65 20 64 61 h.edu... The da
0630: 74 61 20 66 6f 72 6d 61 74 20 75 73 65 64 20 62 ta format used b
0640: 79 20 74 68 65 20 7a 6c 69 62 20 6c 69 62 72 61 y the zlib libra
0650: 72 79 20 69 73 20 64 65 73 63 72 69 62 65 64 20 ry is described
0660: 62 79 20 52 46 43 73 20 28 52 65 71 75 65 73 74 by RFCs (Request
0670: 20 66 6f 72 0a 20 20 43 6f 6d 6d 65 6e 74 73 29 for. Comments)
0680: 20 31 39 35 30 20 74 6f 20 31 39 35 32 20 69 6e 1950 to 1952 in
0690: 20 74 68 65 20 66 69 6c 65 73 20 66 74 70 3a 2f the files ftp:/
06a0: 2f 64 73 2e 69 6e 74 65 72 6e 69 63 2e 6e 65 74 /ds.internic.net
06b0: 2f 72 66 63 2f 72 66 63 31 39 35 30 2e 74 78 74 /rfc/rfc1950.txt
06c0: 0a 20 20 28 7a 6c 69 62 20 66 6f 72 6d 61 74 29 . (zlib format)
06d0: 2c 20 72 66 63 31 39 35 31 2e 74 78 74 20 28 64 , rfc1951.txt (d
06e0: 65 66 6c 61 74 65 20 66 6f 72 6d 61 74 29 20 61 eflate format) a
06f0: 6e 64 20 72 66 63 31 39 35 32 2e 74 78 74 20 28 nd rfc1952.txt (
0700: 67 7a 69 70 20 66 6f 72 6d 61 74 29 2e 0a 2a 2f gzip format)..*/
0710: 0a 0a 23 69 66 6e 64 65 66 20 5f 5a 4c 49 42 5f ..#ifndef _ZLIB_
0720: 48 0a 23 64 65 66 69 6e 65 20 5f 5a 4c 49 42 5f H.#define _ZLIB_
0730: 48 0a 0a 23 69 6e 63 6c 75 64 65 20 22 7a 63 6f H..#include "zco
0740: 6e 66 2e 68 22 0a 0a 23 69 66 64 65 66 20 5f 5f nf.h"..#ifdef __
0750: 63 70 6c 75 73 70 6c 75 73 0a 65 78 74 65 72 6e cplusplus.extern
0760: 20 22 43 22 20 7b 0a 23 65 6e 64 69 66 0a 0a 23 "C" {.#endif..#
0770: 64 65 66 69 6e 65 20 5a 4c 49 42 5f 56 45 52 53 define ZLIB_VERS
0780: 49 4f 4e 20 22 31 2e 31 2e 33 22 0a 0a 2f 2a 20 ION "1.1.3"../*
0790: 0a 20 20 20 20 20 54 68 65 20 27 7a 6c 69 62 27 . The 'zlib'
07a0: 20 63 6f 6d 70 72 65 73 73 69 6f 6e 20 6c 69 62 compression lib
07b0: 72 61 72 79 20 70 72 6f 76 69 64 65 73 20 69 6e rary provides in
07c0: 2d 6d 65 6d 6f 72 79 20 63 6f 6d 70 72 65 73 73 -memory compress
07d0: 69 6f 6e 20 61 6e 64 0a 20 20 64 65 63 6f 6d 70 ion and. decomp
07e0: 72 65 73 73 69 6f 6e 20 66 75 6e 63 74 69 6f 6e ression function
07f0: 73 2c 20 69 6e 63 6c 75 64 69 6e 67 20 69 6e 74 s, including int
0800: 65 67 72 69 74 79 20 63 68 65 63 6b 73 20 6f 66 egrity checks of
0810: 20 74 68 65 20 75 6e 63 6f 6d 70 72 65 73 73 65 the uncompresse
0820: 64 0a 20 20 64 61 74 61 2e 20 20 54 68 69 73 20 d. data. This
0830: 76 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 6c version of the l
0840: 69 62 72 61 72 79 20 73 75 70 70 6f 72 74 73 20 ibrary supports
0850: 6f 6e 6c 79 20 6f 6e 65 20 63 6f 6d 70 72 65 73 only one compres
0860: 73 69 6f 6e 20 6d 65 74 68 6f 64 0a 20 20 28 64 sion method. (d
0870: 65 66 6c 61 74 69 6f 6e 29 20 62 75 74 20 6f 74 eflation) but ot
0880: 68 65 72 20 61 6c 67 6f 72 69 74 68 6d 73 20 77 her algorithms w
0890: 69 6c 6c 20 62 65 20 61 64 64 65 64 20 6c 61 74 ill be added lat
08a0: 65 72 20 61 6e 64 20 77 69 6c 6c 20 68 61 76 65 er and will have
08b0: 20 74 68 65 20 73 61 6d 65 0a 20 20 73 74 72 65 the same. stre
08c0: 61 6d 20 69 6e 74 65 72 66 61 63 65 2e 0a 0a 20 am interface...
08d0: 20 20 20 20 43 6f 6d 70 72 65 73 73 69 6f 6e 20 Compression
08e0: 63 61 6e 20 62 65 20 64 6f 6e 65 20 69 6e 20 61 can be done in a
08f0: 20 73 69 6e 67 6c 65 20 73 74 65 70 20 69 66 20 single step if
0900: 74 68 65 20 62 75 66 66 65 72 73 20 61 72 65 20 the buffers are
0910: 6c 61 72 67 65 0a 20 20 65 6e 6f 75 67 68 20 28 large. enough (
0920: 66 6f 72 20 65 78 61 6d 70 6c 65 20 69 66 20 61 for example if a
0930: 6e 20 69 6e 70 75 74 20 66 69 6c 65 20 69 73 20 n input file is
0940: 6d 6d 61 70 27 65 64 29 2c 20 6f 72 20 63 61 6e mmap'ed), or can
0950: 20 62 65 20 64 6f 6e 65 20 62 79 0a 20 20 72 65 be done by. re
0960: 70 65 61 74 65 64 20 63 61 6c 6c 73 20 6f 66 20 peated calls of
0970: 74 68 65 20 63 6f 6d 70 72 65 73 73 69 6f 6e 20 the compression
0980: 66 75 6e 63 74 69 6f 6e 2e 20 20 49 6e 20 74 68 function. In th
0990: 65 20 6c 61 74 74 65 72 20 63 61 73 65 2c 20 74 e latter case, t
09a0: 68 65 0a 20 20 61 70 70 6c 69 63 61 74 69 6f 6e he. application
09b0: 20 6d 75 73 74 20 70 72 6f 76 69 64 65 20 6d 6f must provide mo
09c0: 72 65 20 69 6e 70 75 74 20 61 6e 64 2f 6f 72 20 re input and/or
09d0: 63 6f 6e 73 75 6d 65 20 74 68 65 20 6f 75 74 70 consume the outp
09e0: 75 74 0a 20 20 28 70 72 6f 76 69 64 69 6e 67 20 ut. (providing
09f0: 6d 6f 72 65 20 6f 75 74 70 75 74 20 73 70 61 63 more output spac
0a00: 65 29 20 62 65 66 6f 72 65 20 65 61 63 68 20 63 e) before each c
0a10: 61 6c 6c 2e 0a 0a 20 20 20 20 20 54 68 65 20 6c all... The l
0a20: 69 62 72 61 72 79 20 61 6c 73 6f 20 73 75 70 70 ibrary also supp
0a30: 6f 72 74 73 20 72 65 61 64 69 6e 67 20 61 6e 64 orts reading and
0a40: 20 77 72 69 74 69 6e 67 20 66 69 6c 65 73 20 69 writing files i
0a50: 6e 20 67 7a 69 70 20 28 2e 67 7a 29 20 66 6f 72 n gzip (.gz) for
0a60: 6d 61 74 0a 20 20 77 69 74 68 20 61 6e 20 69 6e mat. with an in
0a70: 74 65 72 66 61 63 65 20 73 69 6d 69 6c 61 72 20 terface similar
0a80: 74 6f 20 74 68 61 74 20 6f 66 20 73 74 64 69 6f to that of stdio
0a90: 2e 0a 0a 20 20 20 20 20 54 68 65 20 6c 69 62 72 ... The libr
0aa0: 61 72 79 20 64 6f 65 73 20 6e 6f 74 20 69 6e 73 ary does not ins
0ab0: 74 61 6c 6c 20 61 6e 79 20 73 69 67 6e 61 6c 20 tall any signal
0ac0: 68 61 6e 64 6c 65 72 2e 20 54 68 65 20 64 65 63 handler. The dec
0ad0: 6f 64 65 72 20 63 68 65 63 6b 73 0a 20 20 74 68 oder checks. th
0ae0: 65 20 63 6f 6e 73 69 73 74 65 6e 63 79 20 6f 66 e consistency of
0af0: 20 74 68 65 20 63 6f 6d 70 72 65 73 73 65 64 20 the compressed
0b00: 64 61 74 61 2c 20 73 6f 20 74 68 65 20 6c 69 62 data, so the lib
0b10: 72 61 72 79 20 73 68 6f 75 6c 64 20 6e 65 76 65 rary should neve
0b20: 72 0a 20 20 63 72 61 73 68 20 65 76 65 6e 20 69 r. crash even i
0b30: 6e 20 63 61 73 65 20 6f 66 20 63 6f 72 72 75 70 n case of corrup
0b40: 74 65 64 20 69 6e 70 75 74 2e 0a 2a 2f 0a 0a 74 ted input..*/..t
0b50: 79 70 65 64 65 66 20 76 6f 69 64 70 66 20 28 2a ypedef voidpf (*
0b60: 61 6c 6c 6f 63 5f 66 75 6e 63 29 20 4f 46 28 28 alloc_func) OF((
0b70: 76 6f 69 64 70 66 20 6f 70 61 71 75 65 2c 20 75 voidpf opaque, u
0b80: 49 6e 74 20 69 74 65 6d 73 2c 20 75 49 6e 74 20 Int items, uInt
0b90: 73 69 7a 65 29 29 3b 0a 74 79 70 65 64 65 66 20 size));.typedef
0ba0: 76 6f 69 64 20 20 20 28 2a 66 72 65 65 5f 66 75 void (*free_fu
0bb0: 6e 63 29 20 20 4f 46 28 28 76 6f 69 64 70 66 20 nc) OF((voidpf
0bc0: 6f 70 61 71 75 65 2c 20 76 6f 69 64 70 66 20 61 opaque, voidpf a
0bd0: 64 64 72 65 73 73 29 29 3b 0a 0a 73 74 72 75 63 ddress));..struc
0be0: 74 20 69 6e 74 65 72 6e 61 6c 5f 73 74 61 74 65 t internal_state
0bf0: 3b 0a 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 ;..typedef struc
0c00: 74 20 7a 5f 73 74 72 65 61 6d 5f 73 20 7b 0a 20 t z_stream_s {.
0c10: 20 20 20 42 79 74 65 66 20 20 20 20 2a 6e 65 78 Bytef *nex
0c20: 74 5f 69 6e 3b 20 20 2f 2a 20 6e 65 78 74 20 69 t_in; /* next i
0c30: 6e 70 75 74 20 62 79 74 65 20 2a 2f 0a 20 20 20 nput byte */.
0c40: 20 75 49 6e 74 20 20 20 20 20 61 76 61 69 6c 5f uInt avail_
0c50: 69 6e 3b 20 20 2f 2a 20 6e 75 6d 62 65 72 20 6f in; /* number o
0c60: 66 20 62 79 74 65 73 20 61 76 61 69 6c 61 62 6c f bytes availabl
0c70: 65 20 61 74 20 6e 65 78 74 5f 69 6e 20 2a 2f 0a e at next_in */.
0c80: 20 20 20 20 75 4c 6f 6e 67 20 20 20 20 74 6f 74 uLong tot
0c90: 61 6c 5f 69 6e 3b 20 20 2f 2a 20 74 6f 74 61 6c al_in; /* total
0ca0: 20 6e 62 20 6f 66 20 69 6e 70 75 74 20 62 79 74 nb of input byt
0cb0: 65 73 20 72 65 61 64 20 73 6f 20 66 61 72 20 2a es read so far *
0cc0: 2f 0a 0a 20 20 20 20 42 79 74 65 66 20 20 20 20 /.. Bytef
0cd0: 2a 6e 65 78 74 5f 6f 75 74 3b 20 2f 2a 20 6e 65 *next_out; /* ne
0ce0: 78 74 20 6f 75 74 70 75 74 20 62 79 74 65 20 73 xt output byte s
0cf0: 68 6f 75 6c 64 20 62 65 20 70 75 74 20 74 68 65 hould be put the
0d00: 72 65 20 2a 2f 0a 20 20 20 20 75 49 6e 74 20 20 re */. uInt
0d10: 20 20 20 61 76 61 69 6c 5f 6f 75 74 3b 20 2f 2a avail_out; /*
0d20: 20 72 65 6d 61 69 6e 69 6e 67 20 66 72 65 65 20 remaining free
0d30: 73 70 61 63 65 20 61 74 20 6e 65 78 74 5f 6f 75 space at next_ou
0d40: 74 20 2a 2f 0a 20 20 20 20 75 4c 6f 6e 67 20 20 t */. uLong
0d50: 20 20 74 6f 74 61 6c 5f 6f 75 74 3b 20 2f 2a 20 total_out; /*
0d60: 74 6f 74 61 6c 20 6e 62 20 6f 66 20 62 79 74 65 total nb of byte
0d70: 73 20 6f 75 74 70 75 74 20 73 6f 20 66 61 72 20 s output so far
0d80: 2a 2f 0a 0a 20 20 20 20 63 68 61 72 20 20 20 20 */.. char
0d90: 20 2a 6d 73 67 3b 20 20 20 20 20 20 2f 2a 20 6c *msg; /* l
0da0: 61 73 74 20 65 72 72 6f 72 20 6d 65 73 73 61 67 ast error messag
0db0: 65 2c 20 4e 55 4c 4c 20 69 66 20 6e 6f 20 65 72 e, NULL if no er
0dc0: 72 6f 72 20 2a 2f 0a 20 20 20 20 73 74 72 75 63 ror */. struc
0dd0: 74 20 69 6e 74 65 72 6e 61 6c 5f 73 74 61 74 65 t internal_state
0de0: 20 46 41 52 20 2a 73 74 61 74 65 3b 20 2f 2a 20 FAR *state; /*
0df0: 6e 6f 74 20 76 69 73 69 62 6c 65 20 62 79 20 61 not visible by a
0e00: 70 70 6c 69 63 61 74 69 6f 6e 73 20 2a 2f 0a 0a pplications */..
0e10: 20 20 20 20 61 6c 6c 6f 63 5f 66 75 6e 63 20 7a alloc_func z
0e20: 61 6c 6c 6f 63 3b 20 20 2f 2a 20 75 73 65 64 20 alloc; /* used
0e30: 74 6f 20 61 6c 6c 6f 63 61 74 65 20 74 68 65 20 to allocate the
0e40: 69 6e 74 65 72 6e 61 6c 20 73 74 61 74 65 20 2a internal state *
0e50: 2f 0a 20 20 20 20 66 72 65 65 5f 66 75 6e 63 20 /. free_func
0e60: 20 7a 66 72 65 65 3b 20 20 20 2f 2a 20 75 73 65 zfree; /* use
0e70: 64 20 74 6f 20 66 72 65 65 20 74 68 65 20 69 6e d to free the in
0e80: 74 65 72 6e 61 6c 20 73 74 61 74 65 20 2a 2f 0a ternal state */.
0e90: 20 20 20 20 76 6f 69 64 70 66 20 20 20 20 20 6f voidpf o
0ea0: 70 61 71 75 65 3b 20 20 2f 2a 20 70 72 69 76 61 paque; /* priva
0eb0: 74 65 20 64 61 74 61 20 6f 62 6a 65 63 74 20 70 te data object p
0ec0: 61 73 73 65 64 20 74 6f 20 7a 61 6c 6c 6f 63 20 assed to zalloc
0ed0: 61 6e 64 20 7a 66 72 65 65 20 2a 2f 0a 0a 20 20 and zfree */..
0ee0: 20 20 69 6e 74 20 20 20 20 20 64 61 74 61 5f 74 int data_t
0ef0: 79 70 65 3b 20 20 2f 2a 20 62 65 73 74 20 67 75 ype; /* best gu
0f00: 65 73 73 20 61 62 6f 75 74 20 74 68 65 20 64 61 ess about the da
0f10: 74 61 20 74 79 70 65 3a 20 61 73 63 69 69 20 6f ta type: ascii o
0f20: 72 20 62 69 6e 61 72 79 20 2a 2f 0a 20 20 20 20 r binary */.
0f30: 75 4c 6f 6e 67 20 20 20 61 64 6c 65 72 3b 20 20 uLong adler;
0f40: 20 20 20 20 2f 2a 20 61 64 6c 65 72 33 32 20 76 /* adler32 v
0f50: 61 6c 75 65 20 6f 66 20 74 68 65 20 75 6e 63 6f alue of the unco
0f60: 6d 70 72 65 73 73 65 64 20 64 61 74 61 20 2a 2f mpressed data */
0f70: 0a 20 20 20 20 75 4c 6f 6e 67 20 20 20 72 65 73 . uLong res
0f80: 65 72 76 65 64 3b 20 20 20 2f 2a 20 72 65 73 65 erved; /* rese
0f90: 72 76 65 64 20 66 6f 72 20 66 75 74 75 72 65 20 rved for future
0fa0: 75 73 65 20 2a 2f 0a 7d 20 7a 5f 73 74 72 65 61 use */.} z_strea
0fb0: 6d 3b 0a 0a 74 79 70 65 64 65 66 20 7a 5f 73 74 m;..typedef z_st
0fc0: 72 65 61 6d 20 46 41 52 20 2a 7a 5f 73 74 72 65 ream FAR *z_stre
0fd0: 61 6d 70 3b 0a 0a 2f 2a 0a 20 20 20 54 68 65 20 amp;../*. The
0fe0: 61 70 70 6c 69 63 61 74 69 6f 6e 20 6d 75 73 74 application must
0ff0: 20 75 70 64 61 74 65 20 6e 65 78 74 5f 69 6e 20 update next_in
1000: 61 6e 64 20 61 76 61 69 6c 5f 69 6e 20 77 68 65 and avail_in whe
1010: 6e 20 61 76 61 69 6c 5f 69 6e 20 68 61 73 0a 20 n avail_in has.
1020: 20 20 64 72 6f 70 70 65 64 20 74 6f 20 7a 65 72 dropped to zer
1030: 6f 2e 20 49 74 20 6d 75 73 74 20 75 70 64 61 74 o. It must updat
1040: 65 20 6e 65 78 74 5f 6f 75 74 20 61 6e 64 20 61 e next_out and a
1050: 76 61 69 6c 5f 6f 75 74 20 77 68 65 6e 20 61 76 vail_out when av
1060: 61 69 6c 5f 6f 75 74 0a 20 20 20 68 61 73 20 64 ail_out. has d
1070: 72 6f 70 70 65 64 20 74 6f 20 7a 65 72 6f 2e 20 ropped to zero.
1080: 54 68 65 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 The application
1090: 6d 75 73 74 20 69 6e 69 74 69 61 6c 69 7a 65 20 must initialize
10a0: 7a 61 6c 6c 6f 63 2c 20 7a 66 72 65 65 20 61 6e zalloc, zfree an
10b0: 64 0a 20 20 20 6f 70 61 71 75 65 20 62 65 66 6f d. opaque befo
10c0: 72 65 20 63 61 6c 6c 69 6e 67 20 74 68 65 20 69 re calling the i
10d0: 6e 69 74 20 66 75 6e 63 74 69 6f 6e 2e 20 41 6c nit function. Al
10e0: 6c 20 6f 74 68 65 72 20 66 69 65 6c 64 73 20 61 l other fields a
10f0: 72 65 20 73 65 74 20 62 79 20 74 68 65 0a 20 20 re set by the.
1100: 20 63 6f 6d 70 72 65 73 73 69 6f 6e 20 6c 69 62 compression lib
1110: 72 61 72 79 20 61 6e 64 20 6d 75 73 74 20 6e 6f rary and must no
1120: 74 20 62 65 20 75 70 64 61 74 65 64 20 62 79 20 t be updated by
1130: 74 68 65 20 61 70 70 6c 69 63 61 74 69 6f 6e 2e the application.
1140: 0a 0a 20 20 20 54 68 65 20 6f 70 61 71 75 65 20 .. The opaque
1150: 76 61 6c 75 65 20 70 72 6f 76 69 64 65 64 20 62 value provided b
1160: 79 20 74 68 65 20 61 70 70 6c 69 63 61 74 69 6f y the applicatio
1170: 6e 20 77 69 6c 6c 20 62 65 20 70 61 73 73 65 64 n will be passed
1180: 20 61 73 20 74 68 65 20 66 69 72 73 74 0a 20 20 as the first.
1190: 20 70 61 72 61 6d 65 74 65 72 20 66 6f 72 20 63 parameter for c
11a0: 61 6c 6c 73 20 6f 66 20 7a 61 6c 6c 6f 63 20 61 alls of zalloc a
11b0: 6e 64 20 7a 66 72 65 65 2e 20 54 68 69 73 20 63 nd zfree. This c
11c0: 61 6e 20 62 65 20 75 73 65 66 75 6c 20 66 6f 72 an be useful for
11d0: 20 63 75 73 74 6f 6d 0a 20 20 20 6d 65 6d 6f 72 custom. memor
11e0: 79 20 6d 61 6e 61 67 65 6d 65 6e 74 2e 20 54 68 y management. Th
11f0: 65 20 63 6f 6d 70 72 65 73 73 69 6f 6e 20 6c 69 e compression li
1200: 62 72 61 72 79 20 61 74 74 61 63 68 65 73 20 6e brary attaches n
1210: 6f 20 6d 65 61 6e 69 6e 67 20 74 6f 20 74 68 65 o meaning to the
1220: 0a 20 20 20 6f 70 61 71 75 65 20 76 61 6c 75 65 . opaque value
1230: 2e 0a 0a 20 20 20 7a 61 6c 6c 6f 63 20 6d 75 73 ... zalloc mus
1240: 74 20 72 65 74 75 72 6e 20 5a 5f 4e 55 4c 4c 20 t return Z_NULL
1250: 69 66 20 74 68 65 72 65 20 69 73 20 6e 6f 74 20 if there is not
1260: 65 6e 6f 75 67 68 20 6d 65 6d 6f 72 79 20 66 6f enough memory fo
1270: 72 20 74 68 65 20 6f 62 6a 65 63 74 2e 0a 20 20 r the object..
1280: 20 49 66 20 7a 6c 69 62 20 69 73 20 75 73 65 64 If zlib is used
1290: 20 69 6e 20 61 20 6d 75 6c 74 69 2d 74 68 72 65 in a multi-thre
12a0: 61 64 65 64 20 61 70 70 6c 69 63 61 74 69 6f 6e aded application
12b0: 2c 20 7a 61 6c 6c 6f 63 20 61 6e 64 20 7a 66 72 , zalloc and zfr
12c0: 65 65 20 6d 75 73 74 20 62 65 0a 20 20 20 74 68 ee must be. th
12d0: 72 65 61 64 20 73 61 66 65 2e 0a 0a 20 20 20 4f read safe... O
12e0: 6e 20 31 36 2d 62 69 74 20 73 79 73 74 65 6d 73 n 16-bit systems
12f0: 2c 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 73 20 , the functions
1300: 7a 61 6c 6c 6f 63 20 61 6e 64 20 7a 66 72 65 65 zalloc and zfree
1310: 20 6d 75 73 74 20 62 65 20 61 62 6c 65 20 74 6f must be able to
1320: 20 61 6c 6c 6f 63 61 74 65 0a 20 20 20 65 78 61 allocate. exa
1330: 63 74 6c 79 20 36 35 35 33 36 20 62 79 74 65 73 ctly 65536 bytes
1340: 2c 20 62 75 74 20 77 69 6c 6c 20 6e 6f 74 20 62 , but will not b
1350: 65 20 72 65 71 75 69 72 65 64 20 74 6f 20 61 6c e required to al
1360: 6c 6f 63 61 74 65 20 6d 6f 72 65 20 74 68 61 6e locate more than
1370: 20 74 68 69 73 0a 20 20 20 69 66 20 74 68 65 20 this. if the
1380: 73 79 6d 62 6f 6c 20 4d 41 58 53 45 47 5f 36 34 symbol MAXSEG_64
1390: 4b 20 69 73 20 64 65 66 69 6e 65 64 20 28 73 65 K is defined (se
13a0: 65 20 7a 63 6f 6e 66 2e 68 29 2e 20 57 41 52 4e e zconf.h). WARN
13b0: 49 4e 47 3a 20 4f 6e 20 4d 53 44 4f 53 2c 0a 20 ING: On MSDOS,.
13c0: 20 20 70 6f 69 6e 74 65 72 73 20 72 65 74 75 72 pointers retur
13d0: 6e 65 64 20 62 79 20 7a 61 6c 6c 6f 63 20 66 6f ned by zalloc fo
13e0: 72 20 6f 62 6a 65 63 74 73 20 6f 66 20 65 78 61 r objects of exa
13f0: 63 74 6c 79 20 36 35 35 33 36 20 62 79 74 65 73 ctly 65536 bytes
1400: 20 2a 6d 75 73 74 2a 0a 20 20 20 68 61 76 65 20 *must*. have
1410: 74 68 65 69 72 20 6f 66 66 73 65 74 20 6e 6f 72 their offset nor
1420: 6d 61 6c 69 7a 65 64 20 74 6f 20 7a 65 72 6f 2e malized to zero.
1430: 20 54 68 65 20 64 65 66 61 75 6c 74 20 61 6c 6c The default all
1440: 6f 63 61 74 69 6f 6e 20 66 75 6e 63 74 69 6f 6e ocation function
1450: 0a 20 20 20 70 72 6f 76 69 64 65 64 20 62 79 20 . provided by
1460: 74 68 69 73 20 6c 69 62 72 61 72 79 20 65 6e 73 this library ens
1470: 75 72 65 73 20 74 68 69 73 20 28 73 65 65 20 7a ures this (see z
1480: 75 74 69 6c 2e 63 29 2e 20 54 6f 20 72 65 64 75 util.c). To redu
1490: 63 65 20 6d 65 6d 6f 72 79 0a 20 20 20 72 65 71 ce memory. req
14a0: 75 69 72 65 6d 65 6e 74 73 20 61 6e 64 20 61 76 uirements and av
14b0: 6f 69 64 20 61 6e 79 20 61 6c 6c 6f 63 61 74 69 oid any allocati
14c0: 6f 6e 20 6f 66 20 36 34 4b 20 6f 62 6a 65 63 74 on of 64K object
14d0: 73 2c 20 61 74 20 74 68 65 20 65 78 70 65 6e 73 s, at the expens
14e0: 65 20 6f 66 0a 20 20 20 63 6f 6d 70 72 65 73 73 e of. compress
14f0: 69 6f 6e 20 72 61 74 69 6f 2c 20 63 6f 6d 70 69 ion ratio, compi
1500: 6c 65 20 74 68 65 20 6c 69 62 72 61 72 79 20 77 le the library w
1510: 69 74 68 20 2d 44 4d 41 58 5f 57 42 49 54 53 3d ith -DMAX_WBITS=
1520: 31 34 20 28 73 65 65 20 7a 63 6f 6e 66 2e 68 29 14 (see zconf.h)
1530: 2e 0a 0a 20 20 20 54 68 65 20 66 69 65 6c 64 73 ... The fields
1540: 20 74 6f 74 61 6c 5f 69 6e 20 61 6e 64 20 74 6f total_in and to
1550: 74 61 6c 5f 6f 75 74 20 63 61 6e 20 62 65 20 75 tal_out can be u
1560: 73 65 64 20 66 6f 72 20 73 74 61 74 69 73 74 69 sed for statisti
1570: 63 73 20 6f 72 0a 20 20 20 70 72 6f 67 72 65 73 cs or. progres
1580: 73 20 72 65 70 6f 72 74 73 2e 20 41 66 74 65 72 s reports. After
1590: 20 63 6f 6d 70 72 65 73 73 69 6f 6e 2c 20 74 6f compression, to
15a0: 74 61 6c 5f 69 6e 20 68 6f 6c 64 73 20 74 68 65 tal_in holds the
15b0: 20 74 6f 74 61 6c 20 73 69 7a 65 20 6f 66 0a 20 total size of.
15c0: 20 20 74 68 65 20 75 6e 63 6f 6d 70 72 65 73 73 the uncompress
15d0: 65 64 20 64 61 74 61 20 61 6e 64 20 6d 61 79 20 ed data and may
15e0: 62 65 20 73 61 76 65 64 20 66 6f 72 20 75 73 65 be saved for use
15f0: 20 69 6e 20 74 68 65 20 64 65 63 6f 6d 70 72 65 in the decompre
1600: 73 73 6f 72 0a 20 20 20 28 70 61 72 74 69 63 75 ssor. (particu
1610: 6c 61 72 6c 79 20 69 66 20 74 68 65 20 64 65 63 larly if the dec
1620: 6f 6d 70 72 65 73 73 6f 72 20 77 61 6e 74 73 20 ompressor wants
1630: 74 6f 20 64 65 63 6f 6d 70 72 65 73 73 20 65 76 to decompress ev
1640: 65 72 79 74 68 69 6e 67 20 69 6e 0a 20 20 20 61 erything in. a
1650: 20 73 69 6e 67 6c 65 20 73 74 65 70 29 2e 0a 2a single step)..*
1660: 2f 0a 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 /..
1670: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 63 6f /* co
1680: 6e 73 74 61 6e 74 73 20 2a 2f 0a 0a 23 64 65 66 nstants */..#def
1690: 69 6e 65 20 5a 5f 4e 4f 5f 46 4c 55 53 48 20 20 ine Z_NO_FLUSH
16a0: 20 20 20 20 30 0a 23 64 65 66 69 6e 65 20 5a 5f 0.#define Z_
16b0: 50 41 52 54 49 41 4c 5f 46 4c 55 53 48 20 31 20 PARTIAL_FLUSH 1
16c0: 2f 2a 20 77 69 6c 6c 20 62 65 20 72 65 6d 6f 76 /* will be remov
16d0: 65 64 2c 20 75 73 65 20 5a 5f 53 59 4e 43 5f 46 ed, use Z_SYNC_F
16e0: 4c 55 53 48 20 69 6e 73 74 65 61 64 20 2a 2f 0a LUSH instead */.
16f0: 23 64 65 66 69 6e 65 20 5a 5f 53 59 4e 43 5f 46 #define Z_SYNC_F
1700: 4c 55 53 48 20 20 20 20 32 0a 23 64 65 66 69 6e LUSH 2.#defin
1710: 65 20 5a 5f 46 55 4c 4c 5f 46 4c 55 53 48 20 20 e Z_FULL_FLUSH
1720: 20 20 33 0a 23 64 65 66 69 6e 65 20 5a 5f 46 49 3.#define Z_FI
1730: 4e 49 53 48 20 20 20 20 20 20 20 20 34 0a 2f 2a NISH 4./*
1740: 20 41 6c 6c 6f 77 65 64 20 66 6c 75 73 68 20 76 Allowed flush v
1750: 61 6c 75 65 73 3b 20 73 65 65 20 64 65 66 6c 61 alues; see defla
1760: 74 65 28 29 20 62 65 6c 6f 77 20 66 6f 72 20 64 te() below for d
1770: 65 74 61 69 6c 73 20 2a 2f 0a 0a 23 64 65 66 69 etails */..#defi
1780: 6e 65 20 5a 5f 4f 4b 20 20 20 20 20 20 20 20 20 ne Z_OK
1790: 20 20 20 30 0a 23 64 65 66 69 6e 65 20 5a 5f 53 0.#define Z_S
17a0: 54 52 45 41 4d 5f 45 4e 44 20 20 20 20 31 0a 23 TREAM_END 1.#
17b0: 64 65 66 69 6e 65 20 5a 5f 4e 45 45 44 5f 44 49 define Z_NEED_DI
17c0: 43 54 20 20 20 20 20 32 0a 23 64 65 66 69 6e 65 CT 2.#define
17d0: 20 5a 5f 45 52 52 4e 4f 20 20 20 20 20 20 20 20 Z_ERRNO
17e0: 28 2d 31 29 0a 23 64 65 66 69 6e 65 20 5a 5f 53 (-1).#define Z_S
17f0: 54 52 45 41 4d 5f 45 52 52 4f 52 20 28 2d 32 29 TREAM_ERROR (-2)
1800: 0a 23 64 65 66 69 6e 65 20 5a 5f 44 41 54 41 5f .#define Z_DATA_
1810: 45 52 52 4f 52 20 20 20 28 2d 33 29 0a 23 64 65 ERROR (-3).#de
1820: 66 69 6e 65 20 5a 5f 4d 45 4d 5f 45 52 52 4f 52 fine Z_MEM_ERROR
1830: 20 20 20 20 28 2d 34 29 0a 23 64 65 66 69 6e 65 (-4).#define
1840: 20 5a 5f 42 55 46 5f 45 52 52 4f 52 20 20 20 20 Z_BUF_ERROR
1850: 28 2d 35 29 0a 23 64 65 66 69 6e 65 20 5a 5f 56 (-5).#define Z_V
1860: 45 52 53 49 4f 4e 5f 45 52 52 4f 52 20 28 2d 36 ERSION_ERROR (-6
1870: 29 0a 2f 2a 20 52 65 74 75 72 6e 20 63 6f 64 65 )./* Return code
1880: 73 20 66 6f 72 20 74 68 65 20 63 6f 6d 70 72 65 s for the compre
1890: 73 73 69 6f 6e 2f 64 65 63 6f 6d 70 72 65 73 73 ssion/decompress
18a0: 69 6f 6e 20 66 75 6e 63 74 69 6f 6e 73 2e 20 4e ion functions. N
18b0: 65 67 61 74 69 76 65 0a 20 2a 20 76 61 6c 75 65 egative. * value
18c0: 73 20 61 72 65 20 65 72 72 6f 72 73 2c 20 70 6f s are errors, po
18d0: 73 69 74 69 76 65 20 76 61 6c 75 65 73 20 61 72 sitive values ar
18e0: 65 20 75 73 65 64 20 66 6f 72 20 73 70 65 63 69 e used for speci
18f0: 61 6c 20 62 75 74 20 6e 6f 72 6d 61 6c 20 65 76 al but normal ev
1900: 65 6e 74 73 2e 0a 20 2a 2f 0a 0a 23 64 65 66 69 ents.. */..#defi
1910: 6e 65 20 5a 5f 4e 4f 5f 43 4f 4d 50 52 45 53 53 ne Z_NO_COMPRESS
1920: 49 4f 4e 20 20 20 20 20 20 20 20 20 30 0a 23 64 ION 0.#d
1930: 65 66 69 6e 65 20 5a 5f 42 45 53 54 5f 53 50 45 efine Z_BEST_SPE
1940: 45 44 20 20 20 20 20 20 20 20 20 20 20 20 20 31 ED 1
1950: 0a 23 64 65 66 69 6e 65 20 5a 5f 42 45 53 54 5f .#define Z_BEST_
1960: 43 4f 4d 50 52 45 53 53 49 4f 4e 20 20 20 20 20 COMPRESSION
1970: 20 20 39 0a 23 64 65 66 69 6e 65 20 5a 5f 44 45 9.#define Z_DE
1980: 46 41 55 4c 54 5f 43 4f 4d 50 52 45 53 53 49 4f FAULT_COMPRESSIO
1990: 4e 20 20 28 2d 31 29 0a 2f 2a 20 63 6f 6d 70 72 N (-1)./* compr
19a0: 65 73 73 69 6f 6e 20 6c 65 76 65 6c 73 20 2a 2f ession levels */
19b0: 0a 0a 23 64 65 66 69 6e 65 20 5a 5f 46 49 4c 54 ..#define Z_FILT
19c0: 45 52 45 44 20 20 20 20 20 20 20 20 20 20 20 20 ERED
19d0: 31 0a 23 64 65 66 69 6e 65 20 5a 5f 48 55 46 46 1.#define Z_HUFF
19e0: 4d 41 4e 5f 4f 4e 4c 59 20 20 20 20 20 20 20 20 MAN_ONLY
19f0: 32 0a 23 64 65 66 69 6e 65 20 5a 5f 44 45 46 41 2.#define Z_DEFA
1a00: 55 4c 54 5f 53 54 52 41 54 45 47 59 20 20 20 20 ULT_STRATEGY
1a10: 30 0a 2f 2a 20 63 6f 6d 70 72 65 73 73 69 6f 6e 0./* compression
1a20: 20 73 74 72 61 74 65 67 79 3b 20 73 65 65 20 64 strategy; see d
1a30: 65 66 6c 61 74 65 49 6e 69 74 32 28 29 20 62 65 eflateInit2() be
1a40: 6c 6f 77 20 66 6f 72 20 64 65 74 61 69 6c 73 20 low for details
1a50: 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 5a 5f 42 49 */..#define Z_BI
1a60: 4e 41 52 59 20 20 20 30 0a 23 64 65 66 69 6e 65 NARY 0.#define
1a70: 20 5a 5f 41 53 43 49 49 20 20 20 20 31 0a 23 64 Z_ASCII 1.#d
1a80: 65 66 69 6e 65 20 5a 5f 55 4e 4b 4e 4f 57 4e 20 efine Z_UNKNOWN
1a90: 20 32 0a 2f 2a 20 50 6f 73 73 69 62 6c 65 20 76 2./* Possible v
1aa0: 61 6c 75 65 73 20 6f 66 20 74 68 65 20 64 61 74 alues of the dat
1ab0: 61 5f 74 79 70 65 20 66 69 65 6c 64 20 2a 2f 0a a_type field */.
1ac0: 0a 23 64 65 66 69 6e 65 20 5a 5f 44 45 46 4c 41 .#define Z_DEFLA
1ad0: 54 45 44 20 20 20 38 0a 2f 2a 20 54 68 65 20 64 TED 8./* The d
1ae0: 65 66 6c 61 74 65 20 63 6f 6d 70 72 65 73 73 69 eflate compressi
1af0: 6f 6e 20 6d 65 74 68 6f 64 20 28 74 68 65 20 6f on method (the o
1b00: 6e 6c 79 20 6f 6e 65 20 73 75 70 70 6f 72 74 65 nly one supporte
1b10: 64 20 69 6e 20 74 68 69 73 20 76 65 72 73 69 6f d in this versio
1b20: 6e 29 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 5a n) */..#define Z
1b30: 5f 4e 55 4c 4c 20 20 30 20 20 2f 2a 20 66 6f 72 _NULL 0 /* for
1b40: 20 69 6e 69 74 69 61 6c 69 7a 69 6e 67 20 7a 61 initializing za
1b50: 6c 6c 6f 63 2c 20 7a 66 72 65 65 2c 20 6f 70 61 lloc, zfree, opa
1b60: 71 75 65 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 que */..#define
1b70: 7a 6c 69 62 5f 76 65 72 73 69 6f 6e 20 7a 6c 69 zlib_version zli
1b80: 62 56 65 72 73 69 6f 6e 28 29 0a 2f 2a 20 66 6f bVersion()./* fo
1b90: 72 20 63 6f 6d 70 61 74 69 62 69 6c 69 74 79 20 r compatibility
1ba0: 77 69 74 68 20 76 65 72 73 69 6f 6e 73 20 3c 20 with versions <
1bb0: 31 2e 30 2e 32 20 2a 2f 0a 0a 20 20 20 20 20 20 1.0.2 */..
1bc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1bd0: 20 20 2f 2a 20 62 61 73 69 63 20 66 75 6e 63 74 /* basic funct
1be0: 69 6f 6e 73 20 2a 2f 0a 0a 5a 45 58 54 45 52 4e ions */..ZEXTERN
1bf0: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 20 5a 45 const char * ZE
1c00: 58 50 4f 52 54 20 7a 6c 69 62 56 65 72 73 69 6f XPORT zlibVersio
1c10: 6e 20 4f 46 28 28 76 6f 69 64 29 29 3b 0a 2f 2a n OF((void));./*
1c20: 20 54 68 65 20 61 70 70 6c 69 63 61 74 69 6f 6e The application
1c30: 20 63 61 6e 20 63 6f 6d 70 61 72 65 20 7a 6c 69 can compare zli
1c40: 62 56 65 72 73 69 6f 6e 20 61 6e 64 20 5a 4c 49 bVersion and ZLI
1c50: 42 5f 56 45 52 53 49 4f 4e 20 66 6f 72 20 63 6f B_VERSION for co
1c60: 6e 73 69 73 74 65 6e 63 79 2e 0a 20 20 20 49 66 nsistency.. If
1c70: 20 74 68 65 20 66 69 72 73 74 20 63 68 61 72 61 the first chara
1c80: 63 74 65 72 20 64 69 66 66 65 72 73 2c 20 74 68 cter differs, th
1c90: 65 20 6c 69 62 72 61 72 79 20 63 6f 64 65 20 61 e library code a
1ca0: 63 74 75 61 6c 6c 79 20 75 73 65 64 20 69 73 0a ctually used is.
1cb0: 20 20 20 6e 6f 74 20 63 6f 6d 70 61 74 69 62 6c not compatibl
1cc0: 65 20 77 69 74 68 20 74 68 65 20 7a 6c 69 62 2e e with the zlib.
1cd0: 68 20 68 65 61 64 65 72 20 66 69 6c 65 20 75 73 h header file us
1ce0: 65 64 20 62 79 20 74 68 65 20 61 70 70 6c 69 63 ed by the applic
1cf0: 61 74 69 6f 6e 2e 0a 20 20 20 54 68 69 73 20 63 ation.. This c
1d00: 68 65 63 6b 20 69 73 20 61 75 74 6f 6d 61 74 69 heck is automati
1d10: 63 61 6c 6c 79 20 6d 61 64 65 20 62 79 20 64 65 cally made by de
1d20: 66 6c 61 74 65 49 6e 69 74 20 61 6e 64 20 69 6e flateInit and in
1d30: 66 6c 61 74 65 49 6e 69 74 2e 0a 20 2a 2f 0a 0a flateInit.. */..
1d40: 2f 2a 20 0a 5a 45 58 54 45 52 4e 20 69 6e 74 20 /* .ZEXTERN int
1d50: 5a 45 58 50 4f 52 54 20 64 65 66 6c 61 74 65 49 ZEXPORT deflateI
1d60: 6e 69 74 20 4f 46 28 28 7a 5f 73 74 72 65 61 6d nit OF((z_stream
1d70: 70 20 73 74 72 6d 2c 20 69 6e 74 20 6c 65 76 65 p strm, int leve
1d80: 6c 29 29 3b 0a 0a 20 20 20 20 20 49 6e 69 74 69 l));.. Initi
1d90: 61 6c 69 7a 65 73 20 74 68 65 20 69 6e 74 65 72 alizes the inter
1da0: 6e 61 6c 20 73 74 72 65 61 6d 20 73 74 61 74 65 nal stream state
1db0: 20 66 6f 72 20 63 6f 6d 70 72 65 73 73 69 6f 6e for compression
1dc0: 2e 20 54 68 65 20 66 69 65 6c 64 73 0a 20 20 20 . The fields.
1dd0: 7a 61 6c 6c 6f 63 2c 20 7a 66 72 65 65 20 61 6e zalloc, zfree an
1de0: 64 20 6f 70 61 71 75 65 20 6d 75 73 74 20 62 65 d opaque must be
1df0: 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 62 65 66 initialized bef
1e00: 6f 72 65 20 62 79 20 74 68 65 20 63 61 6c 6c 65 ore by the calle
1e10: 72 2e 0a 20 20 20 49 66 20 7a 61 6c 6c 6f 63 20 r.. If zalloc
1e20: 61 6e 64 20 7a 66 72 65 65 20 61 72 65 20 73 65 and zfree are se
1e30: 74 20 74 6f 20 5a 5f 4e 55 4c 4c 2c 20 64 65 66 t to Z_NULL, def
1e40: 6c 61 74 65 49 6e 69 74 20 75 70 64 61 74 65 73 lateInit updates
1e50: 20 74 68 65 6d 20 74 6f 0a 20 20 20 75 73 65 20 them to. use
1e60: 64 65 66 61 75 6c 74 20 61 6c 6c 6f 63 61 74 69 default allocati
1e70: 6f 6e 20 66 75 6e 63 74 69 6f 6e 73 2e 0a 0a 20 on functions...
1e80: 20 20 20 20 54 68 65 20 63 6f 6d 70 72 65 73 73 The compress
1e90: 69 6f 6e 20 6c 65 76 65 6c 20 6d 75 73 74 20 62 ion level must b
1ea0: 65 20 5a 5f 44 45 46 41 55 4c 54 5f 43 4f 4d 50 e Z_DEFAULT_COMP
1eb0: 52 45 53 53 49 4f 4e 2c 20 6f 72 20 62 65 74 77 RESSION, or betw
1ec0: 65 65 6e 20 30 20 61 6e 64 20 39 3a 0a 20 20 20 een 0 and 9:.
1ed0: 31 20 67 69 76 65 73 20 62 65 73 74 20 73 70 65 1 gives best spe
1ee0: 65 64 2c 20 39 20 67 69 76 65 73 20 62 65 73 74 ed, 9 gives best
1ef0: 20 63 6f 6d 70 72 65 73 73 69 6f 6e 2c 20 30 20 compression, 0
1f00: 67 69 76 65 73 20 6e 6f 20 63 6f 6d 70 72 65 73 gives no compres
1f10: 73 69 6f 6e 20 61 74 0a 20 20 20 61 6c 6c 20 28 sion at. all (
1f20: 74 68 65 20 69 6e 70 75 74 20 64 61 74 61 20 69 the input data i
1f30: 73 20 73 69 6d 70 6c 79 20 63 6f 70 69 65 64 20 s simply copied
1f40: 61 20 62 6c 6f 63 6b 20 61 74 20 61 20 74 69 6d a block at a tim
1f50: 65 29 2e 0a 20 20 20 5a 5f 44 45 46 41 55 4c 54 e).. Z_DEFAULT
1f60: 5f 43 4f 4d 50 52 45 53 53 49 4f 4e 20 72 65 71 _COMPRESSION req
1f70: 75 65 73 74 73 20 61 20 64 65 66 61 75 6c 74 20 uests a default
1f80: 63 6f 6d 70 72 6f 6d 69 73 65 20 62 65 74 77 65 compromise betwe
1f90: 65 6e 20 73 70 65 65 64 20 61 6e 64 0a 20 20 20 en speed and.
1fa0: 63 6f 6d 70 72 65 73 73 69 6f 6e 20 28 63 75 72 compression (cur
1fb0: 72 65 6e 74 6c 79 20 65 71 75 69 76 61 6c 65 6e rently equivalen
1fc0: 74 20 74 6f 20 6c 65 76 65 6c 20 36 29 2e 0a 0a t to level 6)...
1fd0: 20 20 20 20 20 64 65 66 6c 61 74 65 49 6e 69 74 deflateInit
1fe0: 20 72 65 74 75 72 6e 73 20 5a 5f 4f 4b 20 69 66 returns Z_OK if
1ff0: 20 73 75 63 63 65 73 73 2c 20 5a 5f 4d 45 4d 5f success, Z_MEM_
2000: 45 52 52 4f 52 20 69 66 20 74 68 65 72 65 20 77 ERROR if there w
2010: 61 73 20 6e 6f 74 0a 20 20 20 65 6e 6f 75 67 68 as not. enough
2020: 20 6d 65 6d 6f 72 79 2c 20 5a 5f 53 54 52 45 41 memory, Z_STREA
2030: 4d 5f 45 52 52 4f 52 20 69 66 20 6c 65 76 65 6c M_ERROR if level
2040: 20 69 73 20 6e 6f 74 20 61 20 76 61 6c 69 64 20 is not a valid
2050: 63 6f 6d 70 72 65 73 73 69 6f 6e 20 6c 65 76 65 compression leve
2060: 6c 2c 0a 20 20 20 5a 5f 56 45 52 53 49 4f 4e 5f l,. Z_VERSION_
2070: 45 52 52 4f 52 20 69 66 20 74 68 65 20 7a 6c 69 ERROR if the zli
2080: 62 20 6c 69 62 72 61 72 79 20 76 65 72 73 69 6f b library versio
2090: 6e 20 28 7a 6c 69 62 5f 76 65 72 73 69 6f 6e 29 n (zlib_version)
20a0: 20 69 73 20 69 6e 63 6f 6d 70 61 74 69 62 6c 65 is incompatible
20b0: 0a 20 20 20 77 69 74 68 20 74 68 65 20 76 65 72 . with the ver
20c0: 73 69 6f 6e 20 61 73 73 75 6d 65 64 20 62 79 20 sion assumed by
20d0: 74 68 65 20 63 61 6c 6c 65 72 20 28 5a 4c 49 42 the caller (ZLIB
20e0: 5f 56 45 52 53 49 4f 4e 29 2e 0a 20 20 20 6d 73 _VERSION).. ms
20f0: 67 20 69 73 20 73 65 74 20 74 6f 20 6e 75 6c 6c g is set to null
2100: 20 69 66 20 74 68 65 72 65 20 69 73 20 6e 6f 20 if there is no
2110: 65 72 72 6f 72 20 6d 65 73 73 61 67 65 2e 20 20 error message.
2120: 64 65 66 6c 61 74 65 49 6e 69 74 20 64 6f 65 73 deflateInit does
2130: 20 6e 6f 74 0a 20 20 20 70 65 72 66 6f 72 6d 20 not. perform
2140: 61 6e 79 20 63 6f 6d 70 72 65 73 73 69 6f 6e 3a any compression:
2150: 20 74 68 69 73 20 77 69 6c 6c 20 62 65 20 64 6f this will be do
2160: 6e 65 20 62 79 20 64 65 66 6c 61 74 65 28 29 2e ne by deflate().
2170: 0a 2a 2f 0a 0a 23 69 66 6e 64 65 66 20 4b 49 5f .*/..#ifndef KI_
2180: 47 5a 5f 4e 4f 5f 43 4f 4d 50 52 45 53 53 49 4f GZ_NO_COMPRESSIO
2190: 4e 0d 0a 0a 5a 45 58 54 45 52 4e 20 69 6e 74 20 N...ZEXTERN int
21a0: 5a 45 58 50 4f 52 54 20 64 65 66 6c 61 74 65 20 ZEXPORT deflate
21b0: 4f 46 28 28 7a 5f 73 74 72 65 61 6d 70 20 73 74 OF((z_streamp st
21c0: 72 6d 2c 20 69 6e 74 20 66 6c 75 73 68 29 29 3b rm, int flush));
21d0: 0a 2f 2a 0a 20 20 20 20 64 65 66 6c 61 74 65 20 ./*. deflate
21e0: 63 6f 6d 70 72 65 73 73 65 73 20 61 73 20 6d 75 compresses as mu
21f0: 63 68 20 64 61 74 61 20 61 73 20 70 6f 73 73 69 ch data as possi
2200: 62 6c 65 2c 20 61 6e 64 20 73 74 6f 70 73 20 77 ble, and stops w
2210: 68 65 6e 20 74 68 65 20 69 6e 70 75 74 0a 20 20 hen the input.
2220: 62 75 66 66 65 72 20 62 65 63 6f 6d 65 73 20 65 buffer becomes e
2230: 6d 70 74 79 20 6f 72 20 74 68 65 20 6f 75 74 70 mpty or the outp
2240: 75 74 20 62 75 66 66 65 72 20 62 65 63 6f 6d 65 ut buffer become
2250: 73 20 66 75 6c 6c 2e 20 49 74 20 6d 61 79 20 69 s full. It may i
2260: 6e 74 72 6f 64 75 63 65 20 73 6f 6d 65 0a 20 20 ntroduce some.
2270: 6f 75 74 70 75 74 20 6c 61 74 65 6e 63 79 20 28 output latency (
2280: 72 65 61 64 69 6e 67 20 69 6e 70 75 74 20 77 69 reading input wi
2290: 74 68 6f 75 74 20 70 72 6f 64 75 63 69 6e 67 20 thout producing
22a0: 61 6e 79 20 6f 75 74 70 75 74 29 20 65 78 63 65 any output) exce
22b0: 70 74 20 77 68 65 6e 0a 20 20 66 6f 72 63 65 64 pt when. forced
22c0: 20 74 6f 20 66 6c 75 73 68 2e 0a 0a 20 20 20 20 to flush...
22d0: 54 68 65 20 64 65 74 61 69 6c 65 64 20 73 65 6d The detailed sem
22e0: 61 6e 74 69 63 73 20 61 72 65 20 61 73 20 66 6f antics are as fo
22f0: 6c 6c 6f 77 73 2e 20 64 65 66 6c 61 74 65 20 70 llows. deflate p
2300: 65 72 66 6f 72 6d 73 20 6f 6e 65 20 6f 72 20 62 erforms one or b
2310: 6f 74 68 20 6f 66 20 74 68 65 0a 20 20 66 6f 6c oth of the. fol
2320: 6c 6f 77 69 6e 67 20 61 63 74 69 6f 6e 73 3a 0a lowing actions:.
2330: 0a 20 20 2d 20 43 6f 6d 70 72 65 73 73 20 6d 6f . - Compress mo
2340: 72 65 20 69 6e 70 75 74 20 73 74 61 72 74 69 6e re input startin
2350: 67 20 61 74 20 6e 65 78 74 5f 69 6e 20 61 6e 64 g at next_in and
2360: 20 75 70 64 61 74 65 20 6e 65 78 74 5f 69 6e 20 update next_in
2370: 61 6e 64 20 61 76 61 69 6c 5f 69 6e 0a 20 20 20 and avail_in.
2380: 20 61 63 63 6f 72 64 69 6e 67 6c 79 2e 20 49 66 accordingly. If
2390: 20 6e 6f 74 20 61 6c 6c 20 69 6e 70 75 74 20 63 not all input c
23a0: 61 6e 20 62 65 20 70 72 6f 63 65 73 73 65 64 20 an be processed
23b0: 28 62 65 63 61 75 73 65 20 74 68 65 72 65 20 69 (because there i
23c0: 73 20 6e 6f 74 0a 20 20 20 20 65 6e 6f 75 67 68 s not. enough
23d0: 20 72 6f 6f 6d 20 69 6e 20 74 68 65 20 6f 75 74 room in the out
23e0: 70 75 74 20 62 75 66 66 65 72 29 2c 20 6e 65 78 put buffer), nex
23f0: 74 5f 69 6e 20 61 6e 64 20 61 76 61 69 6c 5f 69 t_in and avail_i
2400: 6e 20 61 72 65 20 75 70 64 61 74 65 64 20 61 6e n are updated an
2410: 64 0a 20 20 20 20 70 72 6f 63 65 73 73 69 6e 67 d. processing
2420: 20 77 69 6c 6c 20 72 65 73 75 6d 65 20 61 74 20 will resume at
2430: 74 68 69 73 20 70 6f 69 6e 74 20 66 6f 72 20 74 this point for t
2440: 68 65 20 6e 65 78 74 20 63 61 6c 6c 20 6f 66 20 he next call of
2450: 64 65 66 6c 61 74 65 28 29 2e 0a 0a 20 20 2d 20 deflate()... -
2460: 50 72 6f 76 69 64 65 20 6d 6f 72 65 20 6f 75 74 Provide more out
2470: 70 75 74 20 73 74 61 72 74 69 6e 67 20 61 74 20 put starting at
2480: 6e 65 78 74 5f 6f 75 74 20 61 6e 64 20 75 70 64 next_out and upd
2490: 61 74 65 20 6e 65 78 74 5f 6f 75 74 20 61 6e 64 ate next_out and
24a0: 20 61 76 61 69 6c 5f 6f 75 74 0a 20 20 20 20 61 avail_out. a
24b0: 63 63 6f 72 64 69 6e 67 6c 79 2e 20 54 68 69 73 ccordingly. This
24c0: 20 61 63 74 69 6f 6e 20 69 73 20 66 6f 72 63 65 action is force
24d0: 64 20 69 66 20 74 68 65 20 70 61 72 61 6d 65 74 d if the paramet
24e0: 65 72 20 66 6c 75 73 68 20 69 73 20 6e 6f 6e 20 er flush is non
24f0: 7a 65 72 6f 2e 0a 20 20 20 20 46 6f 72 63 69 6e zero.. Forcin
2500: 67 20 66 6c 75 73 68 20 66 72 65 71 75 65 6e 74 g flush frequent
2510: 6c 79 20 64 65 67 72 61 64 65 73 20 74 68 65 20 ly degrades the
2520: 63 6f 6d 70 72 65 73 73 69 6f 6e 20 72 61 74 69 compression rati
2530: 6f 2c 20 73 6f 20 74 68 69 73 20 70 61 72 61 6d o, so this param
2540: 65 74 65 72 0a 20 20 20 20 73 68 6f 75 6c 64 20 eter. should
2550: 62 65 20 73 65 74 20 6f 6e 6c 79 20 77 68 65 6e be set only when
2560: 20 6e 65 63 65 73 73 61 72 79 20 28 69 6e 20 69 necessary (in i
2570: 6e 74 65 72 61 63 74 69 76 65 20 61 70 70 6c 69 nteractive appli
2580: 63 61 74 69 6f 6e 73 29 2e 0a 20 20 20 20 53 6f cations).. So
2590: 6d 65 20 6f 75 74 70 75 74 20 6d 61 79 20 62 65 me output may be
25a0: 20 70 72 6f 76 69 64 65 64 20 65 76 65 6e 20 69 provided even i
25b0: 66 20 66 6c 75 73 68 20 69 73 20 6e 6f 74 20 73 f flush is not s
25c0: 65 74 2e 0a 0a 20 20 42 65 66 6f 72 65 20 74 68 et... Before th
25d0: 65 20 63 61 6c 6c 20 6f 66 20 64 65 66 6c 61 74 e call of deflat
25e0: 65 28 29 2c 20 74 68 65 20 61 70 70 6c 69 63 61 e(), the applica
25f0: 74 69 6f 6e 20 73 68 6f 75 6c 64 20 65 6e 73 75 tion should ensu
2600: 72 65 20 74 68 61 74 20 61 74 20 6c 65 61 73 74 re that at least
2610: 0a 20 20 6f 6e 65 20 6f 66 20 74 68 65 20 61 63 . one of the ac
2620: 74 69 6f 6e 73 20 69 73 20 70 6f 73 73 69 62 6c tions is possibl
2630: 65 2c 20 62 79 20 70 72 6f 76 69 64 69 6e 67 20 e, by providing
2640: 6d 6f 72 65 20 69 6e 70 75 74 20 61 6e 64 2f 6f more input and/o
2650: 72 20 63 6f 6e 73 75 6d 69 6e 67 0a 20 20 6d 6f r consuming. mo
2660: 72 65 20 6f 75 74 70 75 74 2c 20 61 6e 64 20 75 re output, and u
2670: 70 64 61 74 69 6e 67 20 61 76 61 69 6c 5f 69 6e pdating avail_in
2680: 20 6f 72 20 61 76 61 69 6c 5f 6f 75 74 20 61 63 or avail_out ac
2690: 63 6f 72 64 69 6e 67 6c 79 3b 20 61 76 61 69 6c cordingly; avail
26a0: 5f 6f 75 74 0a 20 20 73 68 6f 75 6c 64 20 6e 65 _out. should ne
26b0: 76 65 72 20 62 65 20 7a 65 72 6f 20 62 65 66 6f ver be zero befo
26c0: 72 65 20 74 68 65 20 63 61 6c 6c 2e 20 54 68 65 re the call. The
26d0: 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 63 61 6e application can
26e0: 20 63 6f 6e 73 75 6d 65 20 74 68 65 0a 20 20 63 consume the. c
26f0: 6f 6d 70 72 65 73 73 65 64 20 6f 75 74 70 75 74 ompressed output
2700: 20 77 68 65 6e 20 69 74 20 77 61 6e 74 73 2c 20 when it wants,
2710: 66 6f 72 20 65 78 61 6d 70 6c 65 20 77 68 65 6e for example when
2720: 20 74 68 65 20 6f 75 74 70 75 74 20 62 75 66 66 the output buff
2730: 65 72 20 69 73 20 66 75 6c 6c 0a 20 20 28 61 76 er is full. (av
2740: 61 69 6c 5f 6f 75 74 20 3d 3d 20 30 29 2c 20 6f ail_out == 0), o
2750: 72 20 61 66 74 65 72 20 65 61 63 68 20 63 61 6c r after each cal
2760: 6c 20 6f 66 20 64 65 66 6c 61 74 65 28 29 2e 20 l of deflate().
2770: 49 66 20 64 65 66 6c 61 74 65 20 72 65 74 75 72 If deflate retur
2780: 6e 73 20 5a 5f 4f 4b 0a 20 20 61 6e 64 20 77 69 ns Z_OK. and wi
2790: 74 68 20 7a 65 72 6f 20 61 76 61 69 6c 5f 6f 75 th zero avail_ou
27a0: 74 2c 20 69 74 20 6d 75 73 74 20 62 65 20 63 61 t, it must be ca
27b0: 6c 6c 65 64 20 61 67 61 69 6e 20 61 66 74 65 72 lled again after
27c0: 20 6d 61 6b 69 6e 67 20 72 6f 6f 6d 20 69 6e 20 making room in
27d0: 74 68 65 0a 20 20 6f 75 74 70 75 74 20 62 75 66 the. output buf
27e0: 66 65 72 20 62 65 63 61 75 73 65 20 74 68 65 72 fer because ther
27f0: 65 20 6d 69 67 68 74 20 62 65 20 6d 6f 72 65 20 e might be more
2800: 6f 75 74 70 75 74 20 70 65 6e 64 69 6e 67 2e 0a output pending..
2810: 0a 20 20 20 20 49 66 20 74 68 65 20 70 61 72 61 . If the para
2820: 6d 65 74 65 72 20 66 6c 75 73 68 20 69 73 20 73 meter flush is s
2830: 65 74 20 74 6f 20 5a 5f 53 59 4e 43 5f 46 4c 55 et to Z_SYNC_FLU
2840: 53 48 2c 20 61 6c 6c 20 70 65 6e 64 69 6e 67 20 SH, all pending
2850: 6f 75 74 70 75 74 20 69 73 0a 20 20 66 6c 75 73 output is. flus
2860: 68 65 64 20 74 6f 20 74 68 65 20 6f 75 74 70 75 hed to the outpu
2870: 74 20 62 75 66 66 65 72 20 61 6e 64 20 74 68 65 t buffer and the
2880: 20 6f 75 74 70 75 74 20 69 73 20 61 6c 69 67 6e output is align
2890: 65 64 20 6f 6e 20 61 20 62 79 74 65 20 62 6f 75 ed on a byte bou
28a0: 6e 64 61 72 79 2c 20 73 6f 0a 20 20 74 68 61 74 ndary, so. that
28b0: 20 74 68 65 20 64 65 63 6f 6d 70 72 65 73 73 6f the decompresso
28c0: 72 20 63 61 6e 20 67 65 74 20 61 6c 6c 20 69 6e r can get all in
28d0: 70 75 74 20 64 61 74 61 20 61 76 61 69 6c 61 62 put data availab
28e0: 6c 65 20 73 6f 20 66 61 72 2e 20 28 49 6e 20 70 le so far. (In p
28f0: 61 72 74 69 63 75 6c 61 72 0a 20 20 61 76 61 69 articular. avai
2900: 6c 5f 69 6e 20 69 73 20 7a 65 72 6f 20 61 66 74 l_in is zero aft
2910: 65 72 20 74 68 65 20 63 61 6c 6c 20 69 66 20 65 er the call if e
2920: 6e 6f 75 67 68 20 6f 75 74 70 75 74 20 73 70 61 nough output spa
2930: 63 65 20 68 61 73 20 62 65 65 6e 20 70 72 6f 76 ce has been prov
2940: 69 64 65 64 0a 20 20 62 65 66 6f 72 65 20 74 68 ided. before th
2950: 65 20 63 61 6c 6c 2e 29 20 20 46 6c 75 73 68 69 e call.) Flushi
2960: 6e 67 20 6d 61 79 20 64 65 67 72 61 64 65 20 63 ng may degrade c
2970: 6f 6d 70 72 65 73 73 69 6f 6e 20 66 6f 72 20 73 ompression for s
2980: 6f 6d 65 20 63 6f 6d 70 72 65 73 73 69 6f 6e 0a ome compression.
2990: 20 20 61 6c 67 6f 72 69 74 68 6d 73 20 61 6e 64 algorithms and
29a0: 20 73 6f 20 69 74 20 73 68 6f 75 6c 64 20 62 65 so it should be
29b0: 20 75 73 65 64 20 6f 6e 6c 79 20 77 68 65 6e 20 used only when
29c0: 6e 65 63 65 73 73 61 72 79 2e 0a 0a 20 20 20 20 necessary...
29d0: 49 66 20 66 6c 75 73 68 20 69 73 20 73 65 74 20 If flush is set
29e0: 74 6f 20 5a 5f 46 55 4c 4c 5f 46 4c 55 53 48 2c to Z_FULL_FLUSH,
29f0: 20 61 6c 6c 20 6f 75 74 70 75 74 20 69 73 20 66 all output is f
2a00: 6c 75 73 68 65 64 20 61 73 20 77 69 74 68 0a 20 lushed as with.
2a10: 20 5a 5f 53 59 4e 43 5f 46 4c 55 53 48 2c 20 61 Z_SYNC_FLUSH, a
2a20: 6e 64 20 74 68 65 20 63 6f 6d 70 72 65 73 73 69 nd the compressi
2a30: 6f 6e 20 73 74 61 74 65 20 69 73 20 72 65 73 65 on state is rese
2a40: 74 20 73 6f 20 74 68 61 74 20 64 65 63 6f 6d 70 t so that decomp
2a50: 72 65 73 73 69 6f 6e 20 63 61 6e 0a 20 20 72 65 ression can. re
2a60: 73 74 61 72 74 20 66 72 6f 6d 20 74 68 69 73 20 start from this
2a70: 70 6f 69 6e 74 20 69 66 20 70 72 65 76 69 6f 75 point if previou
2a80: 73 20 63 6f 6d 70 72 65 73 73 65 64 20 64 61 74 s compressed dat
2a90: 61 20 68 61 73 20 62 65 65 6e 20 64 61 6d 61 67 a has been damag
2aa0: 65 64 20 6f 72 20 69 66 0a 20 20 72 61 6e 64 6f ed or if. rando
2ab0: 6d 20 61 63 63 65 73 73 20 69 73 20 64 65 73 69 m access is desi
2ac0: 72 65 64 2e 20 55 73 69 6e 67 20 5a 5f 46 55 4c red. Using Z_FUL
2ad0: 4c 5f 46 4c 55 53 48 20 74 6f 6f 20 6f 66 74 65 L_FLUSH too ofte
2ae0: 6e 20 63 61 6e 20 73 65 72 69 6f 75 73 6c 79 20 n can seriously
2af0: 64 65 67 72 61 64 65 0a 20 20 74 68 65 20 63 6f degrade. the co
2b00: 6d 70 72 65 73 73 69 6f 6e 2e 0a 0a 20 20 20 20 mpression...
2b10: 49 66 20 64 65 66 6c 61 74 65 20 72 65 74 75 72 If deflate retur
2b20: 6e 73 20 77 69 74 68 20 61 76 61 69 6c 5f 6f 75 ns with avail_ou
2b30: 74 20 3d 3d 20 30 2c 20 74 68 69 73 20 66 75 6e t == 0, this fun
2b40: 63 74 69 6f 6e 20 6d 75 73 74 20 62 65 20 63 61 ction must be ca
2b50: 6c 6c 65 64 20 61 67 61 69 6e 0a 20 20 77 69 74 lled again. wit
2b60: 68 20 74 68 65 20 73 61 6d 65 20 76 61 6c 75 65 h the same value
2b70: 20 6f 66 20 74 68 65 20 66 6c 75 73 68 20 70 61 of the flush pa
2b80: 72 61 6d 65 74 65 72 20 61 6e 64 20 6d 6f 72 65 rameter and more
2b90: 20 6f 75 74 70 75 74 20 73 70 61 63 65 20 28 75 output space (u
2ba0: 70 64 61 74 65 64 0a 20 20 61 76 61 69 6c 5f 6f pdated. avail_o
2bb0: 75 74 29 2c 20 75 6e 74 69 6c 20 74 68 65 20 66 ut), until the f
2bc0: 6c 75 73 68 20 69 73 20 63 6f 6d 70 6c 65 74 65 lush is complete
2bd0: 20 28 64 65 66 6c 61 74 65 20 72 65 74 75 72 6e (deflate return
2be0: 73 20 77 69 74 68 20 6e 6f 6e 2d 7a 65 72 6f 0a s with non-zero.
2bf0: 20 20 61 76 61 69 6c 5f 6f 75 74 29 2e 0a 0a 20 avail_out)...
2c00: 20 20 20 49 66 20 74 68 65 20 70 61 72 61 6d 65 If the parame
2c10: 74 65 72 20 66 6c 75 73 68 20 69 73 20 73 65 74 ter flush is set
2c20: 20 74 6f 20 5a 5f 46 49 4e 49 53 48 2c 20 70 65 to Z_FINISH, pe
2c30: 6e 64 69 6e 67 20 69 6e 70 75 74 20 69 73 20 70 nding input is p
2c40: 72 6f 63 65 73 73 65 64 2c 0a 20 20 70 65 6e 64 rocessed,. pend
2c50: 69 6e 67 20 6f 75 74 70 75 74 20 69 73 20 66 6c ing output is fl
2c60: 75 73 68 65 64 20 61 6e 64 20 64 65 66 6c 61 74 ushed and deflat
2c70: 65 20 72 65 74 75 72 6e 73 20 77 69 74 68 20 5a e returns with Z
2c80: 5f 53 54 52 45 41 4d 5f 45 4e 44 20 69 66 20 74 _STREAM_END if t
2c90: 68 65 72 65 0a 20 20 77 61 73 20 65 6e 6f 75 67 here. was enoug
2ca0: 68 20 6f 75 74 70 75 74 20 73 70 61 63 65 3b 20 h output space;
2cb0: 69 66 20 64 65 66 6c 61 74 65 20 72 65 74 75 72 if deflate retur
2cc0: 6e 73 20 77 69 74 68 20 5a 5f 4f 4b 2c 20 74 68 ns with Z_OK, th
2cd0: 69 73 20 66 75 6e 63 74 69 6f 6e 20 6d 75 73 74 is function must
2ce0: 20 62 65 0a 20 20 63 61 6c 6c 65 64 20 61 67 61 be. called aga
2cf0: 69 6e 20 77 69 74 68 20 5a 5f 46 49 4e 49 53 48 in with Z_FINISH
2d00: 20 61 6e 64 20 6d 6f 72 65 20 6f 75 74 70 75 74 and more output
2d10: 20 73 70 61 63 65 20 28 75 70 64 61 74 65 64 20 space (updated
2d20: 61 76 61 69 6c 5f 6f 75 74 29 20 62 75 74 20 6e avail_out) but n
2d30: 6f 0a 20 20 6d 6f 72 65 20 69 6e 70 75 74 20 64 o. more input d
2d40: 61 74 61 2c 20 75 6e 74 69 6c 20 69 74 20 72 65 ata, until it re
2d50: 74 75 72 6e 73 20 77 69 74 68 20 5a 5f 53 54 52 turns with Z_STR
2d60: 45 41 4d 5f 45 4e 44 20 6f 72 20 61 6e 20 65 72 EAM_END or an er
2d70: 72 6f 72 2e 20 41 66 74 65 72 0a 20 20 64 65 66 ror. After. def
2d80: 6c 61 74 65 20 68 61 73 20 72 65 74 75 72 6e 65 late has returne
2d90: 64 20 5a 5f 53 54 52 45 41 4d 5f 45 4e 44 2c 20 d Z_STREAM_END,
2da0: 74 68 65 20 6f 6e 6c 79 20 70 6f 73 73 69 62 6c the only possibl
2db0: 65 20 6f 70 65 72 61 74 69 6f 6e 73 20 6f 6e 20 e operations on
2dc0: 74 68 65 0a 20 20 73 74 72 65 61 6d 20 61 72 65 the. stream are
2dd0: 20 64 65 66 6c 61 74 65 52 65 73 65 74 20 6f 72 deflateReset or
2de0: 20 64 65 66 6c 61 74 65 45 6e 64 2e 0a 20 20 0a deflateEnd.. .
2df0: 20 20 20 20 5a 5f 46 49 4e 49 53 48 20 63 61 6e Z_FINISH can
2e00: 20 62 65 20 75 73 65 64 20 69 6d 6d 65 64 69 61 be used immedia
2e10: 74 65 6c 79 20 61 66 74 65 72 20 64 65 66 6c 61 tely after defla
2e20: 74 65 49 6e 69 74 20 69 66 20 61 6c 6c 20 74 68 teInit if all th
2e30: 65 20 63 6f 6d 70 72 65 73 73 69 6f 6e 0a 20 20 e compression.
2e40: 69 73 20 74 6f 20 62 65 20 64 6f 6e 65 20 69 6e is to be done in
2e50: 20 61 20 73 69 6e 67 6c 65 20 73 74 65 70 2e 20 a single step.
2e60: 49 6e 20 74 68 69 73 20 63 61 73 65 2c 20 61 76 In this case, av
2e70: 61 69 6c 5f 6f 75 74 20 6d 75 73 74 20 62 65 20 ail_out must be
2e80: 61 74 20 6c 65 61 73 74 0a 20 20 30 2e 31 25 20 at least. 0.1%
2e90: 6c 61 72 67 65 72 20 74 68 61 6e 20 61 76 61 69 larger than avai
2ea0: 6c 5f 69 6e 20 70 6c 75 73 20 31 32 20 62 79 74 l_in plus 12 byt
2eb0: 65 73 2e 20 20 49 66 20 64 65 66 6c 61 74 65 20 es. If deflate
2ec0: 64 6f 65 73 20 6e 6f 74 20 72 65 74 75 72 6e 0a does not return.
2ed0: 20 20 5a 5f 53 54 52 45 41 4d 5f 45 4e 44 2c 20 Z_STREAM_END,
2ee0: 74 68 65 6e 20 69 74 20 6d 75 73 74 20 62 65 20 then it must be
2ef0: 63 61 6c 6c 65 64 20 61 67 61 69 6e 20 61 73 20 called again as
2f00: 64 65 73 63 72 69 62 65 64 20 61 62 6f 76 65 2e described above.
2f10: 0a 0a 20 20 20 20 64 65 66 6c 61 74 65 28 29 20 .. deflate()
2f20: 73 65 74 73 20 73 74 72 6d 2d 3e 61 64 6c 65 72 sets strm->adler
2f30: 20 74 6f 20 74 68 65 20 61 64 6c 65 72 33 32 20 to the adler32
2f40: 63 68 65 63 6b 73 75 6d 20 6f 66 20 61 6c 6c 20 checksum of all
2f50: 69 6e 70 75 74 20 72 65 61 64 0a 20 20 73 6f 20 input read. so
2f60: 66 61 72 20 28 74 68 61 74 20 69 73 2c 20 74 6f far (that is, to
2f70: 74 61 6c 5f 69 6e 20 62 79 74 65 73 29 2e 0a 0a tal_in bytes)...
2f80: 20 20 20 20 64 65 66 6c 61 74 65 28 29 20 6d 61 deflate() ma
2f90: 79 20 75 70 64 61 74 65 20 64 61 74 61 5f 74 79 y update data_ty
2fa0: 70 65 20 69 66 20 69 74 20 63 61 6e 20 6d 61 6b pe if it can mak
2fb0: 65 20 61 20 67 6f 6f 64 20 67 75 65 73 73 20 61 e a good guess a
2fc0: 62 6f 75 74 0a 20 20 74 68 65 20 69 6e 70 75 74 bout. the input
2fd0: 20 64 61 74 61 20 74 79 70 65 20 28 5a 5f 41 53 data type (Z_AS
2fe0: 43 49 49 20 6f 72 20 5a 5f 42 49 4e 41 52 59 29 CII or Z_BINARY)
2ff0: 2e 20 49 6e 20 64 6f 75 62 74 2c 20 74 68 65 20 . In doubt, the
3000: 64 61 74 61 20 69 73 20 63 6f 6e 73 69 64 65 72 data is consider
3010: 65 64 0a 20 20 62 69 6e 61 72 79 2e 20 54 68 69 ed. binary. Thi
3020: 73 20 66 69 65 6c 64 20 69 73 20 6f 6e 6c 79 20 s field is only
3030: 66 6f 72 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 for information
3040: 70 75 72 70 6f 73 65 73 20 61 6e 64 20 64 6f 65 purposes and doe
3050: 73 20 6e 6f 74 20 61 66 66 65 63 74 0a 20 20 74 s not affect. t
3060: 68 65 20 63 6f 6d 70 72 65 73 73 69 6f 6e 20 61 he compression a
3070: 6c 67 6f 72 69 74 68 6d 20 69 6e 20 61 6e 79 20 lgorithm in any
3080: 6d 61 6e 6e 65 72 2e 0a 0a 20 20 20 20 64 65 66 manner... def
3090: 6c 61 74 65 28 29 20 72 65 74 75 72 6e 73 20 5a late() returns Z
30a0: 5f 4f 4b 20 69 66 20 73 6f 6d 65 20 70 72 6f 67 _OK if some prog
30b0: 72 65 73 73 20 68 61 73 20 62 65 65 6e 20 6d 61 ress has been ma
30c0: 64 65 20 28 6d 6f 72 65 20 69 6e 70 75 74 0a 20 de (more input.
30d0: 20 70 72 6f 63 65 73 73 65 64 20 6f 72 20 6d 6f processed or mo
30e0: 72 65 20 6f 75 74 70 75 74 20 70 72 6f 64 75 63 re output produc
30f0: 65 64 29 2c 20 5a 5f 53 54 52 45 41 4d 5f 45 4e ed), Z_STREAM_EN
3100: 44 20 69 66 20 61 6c 6c 20 69 6e 70 75 74 20 68 D if all input h
3110: 61 73 20 62 65 65 6e 0a 20 20 63 6f 6e 73 75 6d as been. consum
3120: 65 64 20 61 6e 64 20 61 6c 6c 20 6f 75 74 70 75 ed and all outpu
3130: 74 20 68 61 73 20 62 65 65 6e 20 70 72 6f 64 75 t has been produ
3140: 63 65 64 20 28 6f 6e 6c 79 20 77 68 65 6e 20 66 ced (only when f
3150: 6c 75 73 68 20 69 73 20 73 65 74 20 74 6f 0a 20 lush is set to.
3160: 20 5a 5f 46 49 4e 49 53 48 29 2c 20 5a 5f 53 54 Z_FINISH), Z_ST
3170: 52 45 41 4d 5f 45 52 52 4f 52 20 69 66 20 74 68 REAM_ERROR if th
3180: 65 20 73 74 72 65 61 6d 20 73 74 61 74 65 20 77 e stream state w
3190: 61 73 20 69 6e 63 6f 6e 73 69 73 74 65 6e 74 20 as inconsistent
31a0: 28 66 6f 72 20 65 78 61 6d 70 6c 65 0a 20 20 69 (for example. i
31b0: 66 20 6e 65 78 74 5f 69 6e 20 6f 72 20 6e 65 78 f next_in or nex
31c0: 74 5f 6f 75 74 20 77 61 73 20 4e 55 4c 4c 29 2c t_out was NULL),
31d0: 20 5a 5f 42 55 46 5f 45 52 52 4f 52 20 69 66 20 Z_BUF_ERROR if
31e0: 6e 6f 20 70 72 6f 67 72 65 73 73 20 69 73 20 70 no progress is p
31f0: 6f 73 73 69 62 6c 65 0a 20 20 28 66 6f 72 20 65 ossible. (for e
3200: 78 61 6d 70 6c 65 20 61 76 61 69 6c 5f 69 6e 20 xample avail_in
3210: 6f 72 20 61 76 61 69 6c 5f 6f 75 74 20 77 61 73 or avail_out was
3220: 20 7a 65 72 6f 29 2e 0a 2a 2f 0a 0a 0a 5a 45 58 zero)..*/...ZEX
3230: 54 45 52 4e 20 69 6e 74 20 5a 45 58 50 4f 52 54 TERN int ZEXPORT
3240: 20 64 65 66 6c 61 74 65 45 6e 64 20 4f 46 28 28 deflateEnd OF((
3250: 7a 5f 73 74 72 65 61 6d 70 20 73 74 72 6d 29 29 z_streamp strm))
3260: 3b 0a 2f 2a 0a 20 20 20 20 20 41 6c 6c 20 64 79 ;./*. All dy
3270: 6e 61 6d 69 63 61 6c 6c 79 20 61 6c 6c 6f 63 61 namically alloca
3280: 74 65 64 20 64 61 74 61 20 73 74 72 75 63 74 75 ted data structu
3290: 72 65 73 20 66 6f 72 20 74 68 69 73 20 73 74 72 res for this str
32a0: 65 61 6d 20 61 72 65 20 66 72 65 65 64 2e 0a 20 eam are freed..
32b0: 20 20 54 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 This function
32c0: 64 69 73 63 61 72 64 73 20 61 6e 79 20 75 6e 70 discards any unp
32d0: 72 6f 63 65 73 73 65 64 20 69 6e 70 75 74 20 61 rocessed input a
32e0: 6e 64 20 64 6f 65 73 20 6e 6f 74 20 66 6c 75 73 nd does not flus
32f0: 68 20 61 6e 79 0a 20 20 20 70 65 6e 64 69 6e 67 h any. pending
3300: 20 6f 75 74 70 75 74 2e 0a 0a 20 20 20 20 20 64 output... d
3310: 65 66 6c 61 74 65 45 6e 64 20 72 65 74 75 72 6e eflateEnd return
3320: 73 20 5a 5f 4f 4b 20 69 66 20 73 75 63 63 65 73 s Z_OK if succes
3330: 73 2c 20 5a 5f 53 54 52 45 41 4d 5f 45 52 52 4f s, Z_STREAM_ERRO
3340: 52 20 69 66 20 74 68 65 0a 20 20 20 73 74 72 65 R if the. stre
3350: 61 6d 20 73 74 61 74 65 20 77 61 73 20 69 6e 63 am state was inc
3360: 6f 6e 73 69 73 74 65 6e 74 2c 20 5a 5f 44 41 54 onsistent, Z_DAT
3370: 41 5f 45 52 52 4f 52 20 69 66 20 74 68 65 20 73 A_ERROR if the s
3380: 74 72 65 61 6d 20 77 61 73 20 66 72 65 65 64 0a tream was freed.
3390: 20 20 20 70 72 65 6d 61 74 75 72 65 6c 79 20 28 prematurely (
33a0: 73 6f 6d 65 20 69 6e 70 75 74 20 6f 72 20 6f 75 some input or ou
33b0: 74 70 75 74 20 77 61 73 20 64 69 73 63 61 72 64 tput was discard
33c0: 65 64 29 2e 20 49 6e 20 74 68 65 20 65 72 72 6f ed). In the erro
33d0: 72 20 63 61 73 65 2c 0a 20 20 20 6d 73 67 20 6d r case,. msg m
33e0: 61 79 20 62 65 20 73 65 74 20 62 75 74 20 74 68 ay be set but th
33f0: 65 6e 20 70 6f 69 6e 74 73 20 74 6f 20 61 20 73 en points to a s
3400: 74 61 74 69 63 20 73 74 72 69 6e 67 20 28 77 68 tatic string (wh
3410: 69 63 68 20 6d 75 73 74 20 6e 6f 74 20 62 65 0a ich must not be.
3420: 20 20 20 64 65 61 6c 6c 6f 63 61 74 65 64 29 2e deallocated).
3430: 0a 2a 2f 0a 0a 23 65 6e 64 69 66 20 2f 2a 20 4b .*/..#endif /* K
3440: 49 5f 47 5a 5f 4e 4f 5f 43 4f 4d 50 52 45 53 53 I_GZ_NO_COMPRESS
3450: 49 4f 4e 20 2a 2f 0d 0a 0a 2f 2a 20 0a 5a 45 58 ION */.../* .ZEX
3460: 54 45 52 4e 20 69 6e 74 20 5a 45 58 50 4f 52 54 TERN int ZEXPORT
3470: 20 69 6e 66 6c 61 74 65 49 6e 69 74 20 4f 46 28 inflateInit OF(
3480: 28 7a 5f 73 74 72 65 61 6d 70 20 73 74 72 6d 29 (z_streamp strm)
3490: 29 3b 0a 0a 20 20 20 20 20 49 6e 69 74 69 61 6c );.. Initial
34a0: 69 7a 65 73 20 74 68 65 20 69 6e 74 65 72 6e 61 izes the interna
34b0: 6c 20 73 74 72 65 61 6d 20 73 74 61 74 65 20 66 l stream state f
34c0: 6f 72 20 64 65 63 6f 6d 70 72 65 73 73 69 6f 6e or decompression
34d0: 2e 20 54 68 65 20 66 69 65 6c 64 73 0a 20 20 20 . The fields.
34e0: 6e 65 78 74 5f 69 6e 2c 20 61 76 61 69 6c 5f 69 next_in, avail_i
34f0: 6e 2c 20 7a 61 6c 6c 6f 63 2c 20 7a 66 72 65 65 n, zalloc, zfree
3500: 20 61 6e 64 20 6f 70 61 71 75 65 20 6d 75 73 74 and opaque must
3510: 20 62 65 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 be initialized
3520: 62 65 66 6f 72 65 20 62 79 0a 20 20 20 74 68 65 before by. the
3530: 20 63 61 6c 6c 65 72 2e 20 49 66 20 6e 65 78 74 caller. If next
3540: 5f 69 6e 20 69 73 20 6e 6f 74 20 5a 5f 4e 55 4c _in is not Z_NUL
3550: 4c 20 61 6e 64 20 61 76 61 69 6c 5f 69 6e 20 69 L and avail_in i
3560: 73 20 6c 61 72 67 65 20 65 6e 6f 75 67 68 20 28 s large enough (
3570: 74 68 65 20 65 78 61 63 74 0a 20 20 20 76 61 6c the exact. val
3580: 75 65 20 64 65 70 65 6e 64 73 20 6f 6e 20 74 68 ue depends on th
3590: 65 20 63 6f 6d 70 72 65 73 73 69 6f 6e 20 6d 65 e compression me
35a0: 74 68 6f 64 29 2c 20 69 6e 66 6c 61 74 65 49 6e thod), inflateIn
35b0: 69 74 20 64 65 74 65 72 6d 69 6e 65 73 20 74 68 it determines th
35c0: 65 0a 20 20 20 63 6f 6d 70 72 65 73 73 69 6f 6e e. compression
35d0: 20 6d 65 74 68 6f 64 20 66 72 6f 6d 20 74 68 65 method from the
35e0: 20 7a 6c 69 62 20 68 65 61 64 65 72 20 61 6e 64 zlib header and
35f0: 20 61 6c 6c 6f 63 61 74 65 73 20 61 6c 6c 20 64 allocates all d
3600: 61 74 61 20 73 74 72 75 63 74 75 72 65 73 0a 20 ata structures.
3610: 20 20 61 63 63 6f 72 64 69 6e 67 6c 79 3b 20 6f accordingly; o
3620: 74 68 65 72 77 69 73 65 20 74 68 65 20 61 6c 6c therwise the all
3630: 6f 63 61 74 69 6f 6e 20 77 69 6c 6c 20 62 65 20 ocation will be
3640: 64 65 66 65 72 72 65 64 20 74 6f 20 74 68 65 20 deferred to the
3650: 66 69 72 73 74 20 63 61 6c 6c 20 6f 66 0a 20 20 first call of.
3660: 20 69 6e 66 6c 61 74 65 2e 20 20 49 66 20 7a 61 inflate. If za
3670: 6c 6c 6f 63 20 61 6e 64 20 7a 66 72 65 65 20 61 lloc and zfree a
3680: 72 65 20 73 65 74 20 74 6f 20 5a 5f 4e 55 4c 4c re set to Z_NULL
3690: 2c 20 69 6e 66 6c 61 74 65 49 6e 69 74 20 75 70 , inflateInit up
36a0: 64 61 74 65 73 20 74 68 65 6d 20 74 6f 0a 20 20 dates them to.
36b0: 20 75 73 65 20 64 65 66 61 75 6c 74 20 61 6c 6c use default all
36c0: 6f 63 61 74 69 6f 6e 20 66 75 6e 63 74 69 6f 6e ocation function
36d0: 73 2e 0a 0a 20 20 20 20 20 69 6e 66 6c 61 74 65 s... inflate
36e0: 49 6e 69 74 20 72 65 74 75 72 6e 73 20 5a 5f 4f Init returns Z_O
36f0: 4b 20 69 66 20 73 75 63 63 65 73 73 2c 20 5a 5f K if success, Z_
3700: 4d 45 4d 5f 45 52 52 4f 52 20 69 66 20 74 68 65 MEM_ERROR if the
3710: 72 65 20 77 61 73 20 6e 6f 74 20 65 6e 6f 75 67 re was not enoug
3720: 68 0a 20 20 20 6d 65 6d 6f 72 79 2c 20 5a 5f 56 h. memory, Z_V
3730: 45 52 53 49 4f 4e 5f 45 52 52 4f 52 20 69 66 20 ERSION_ERROR if
3740: 74 68 65 20 7a 6c 69 62 20 6c 69 62 72 61 72 79 the zlib library
3750: 20 76 65 72 73 69 6f 6e 20 69 73 20 69 6e 63 6f version is inco
3760: 6d 70 61 74 69 62 6c 65 20 77 69 74 68 20 74 68 mpatible with th
3770: 65 0a 20 20 20 76 65 72 73 69 6f 6e 20 61 73 73 e. version ass
3780: 75 6d 65 64 20 62 79 20 74 68 65 20 63 61 6c 6c umed by the call
3790: 65 72 2e 20 20 6d 73 67 20 69 73 20 73 65 74 20 er. msg is set
37a0: 74 6f 20 6e 75 6c 6c 20 69 66 20 74 68 65 72 65 to null if there
37b0: 20 69 73 20 6e 6f 20 65 72 72 6f 72 0a 20 20 20 is no error.
37c0: 6d 65 73 73 61 67 65 2e 20 69 6e 66 6c 61 74 65 message. inflate
37d0: 49 6e 69 74 20 64 6f 65 73 20 6e 6f 74 20 70 65 Init does not pe
37e0: 72 66 6f 72 6d 20 61 6e 79 20 64 65 63 6f 6d 70 rform any decomp
37f0: 72 65 73 73 69 6f 6e 20 61 70 61 72 74 20 66 72 ression apart fr
3800: 6f 6d 20 72 65 61 64 69 6e 67 0a 20 20 20 74 68 om reading. th
3810: 65 20 7a 6c 69 62 20 68 65 61 64 65 72 20 69 66 e zlib header if
3820: 20 70 72 65 73 65 6e 74 3a 20 74 68 69 73 20 77 present: this w
3830: 69 6c 6c 20 62 65 20 64 6f 6e 65 20 62 79 20 69 ill be done by i
3840: 6e 66 6c 61 74 65 28 29 2e 20 20 28 53 6f 20 6e nflate(). (So n
3850: 65 78 74 5f 69 6e 20 61 6e 64 0a 20 20 20 61 76 ext_in and. av
3860: 61 69 6c 5f 69 6e 20 6d 61 79 20 62 65 20 6d 6f ail_in may be mo
3870: 64 69 66 69 65 64 2c 20 62 75 74 20 6e 65 78 74 dified, but next
3880: 5f 6f 75 74 20 61 6e 64 20 61 76 61 69 6c 5f 6f _out and avail_o
3890: 75 74 20 61 72 65 20 75 6e 63 68 61 6e 67 65 64 ut are unchanged
38a0: 2e 29 0a 2a 2f 0a 0a 0a 5a 45 58 54 45 52 4e 20 .).*/...ZEXTERN
38b0: 69 6e 74 20 5a 45 58 50 4f 52 54 20 69 6e 66 6c int ZEXPORT infl
38c0: 61 74 65 20 4f 46 28 28 7a 5f 73 74 72 65 61 6d ate OF((z_stream
38d0: 70 20 73 74 72 6d 2c 20 69 6e 74 20 66 6c 75 73 p strm, int flus
38e0: 68 29 29 3b 0a 2f 2a 0a 20 20 20 20 69 6e 66 6c h));./*. infl
38f0: 61 74 65 20 64 65 63 6f 6d 70 72 65 73 73 65 73 ate decompresses
3900: 20 61 73 20 6d 75 63 68 20 64 61 74 61 20 61 73 as much data as
3910: 20 70 6f 73 73 69 62 6c 65 2c 20 61 6e 64 20 73 possible, and s
3920: 74 6f 70 73 20 77 68 65 6e 20 74 68 65 20 69 6e tops when the in
3930: 70 75 74 0a 20 20 62 75 66 66 65 72 20 62 65 63 put. buffer bec
3940: 6f 6d 65 73 20 65 6d 70 74 79 20 6f 72 20 74 68 omes empty or th
3950: 65 20 6f 75 74 70 75 74 20 62 75 66 66 65 72 20 e output buffer
3960: 62 65 63 6f 6d 65 73 20 66 75 6c 6c 2e 20 49 74 becomes full. It
3970: 20 6d 61 79 20 73 6f 6d 65 0a 20 20 69 6e 74 72 may some. intr
3980: 6f 64 75 63 65 20 73 6f 6d 65 20 6f 75 74 70 75 oduce some outpu
3990: 74 20 6c 61 74 65 6e 63 79 20 28 72 65 61 64 69 t latency (readi
39a0: 6e 67 20 69 6e 70 75 74 20 77 69 74 68 6f 75 74 ng input without
39b0: 20 70 72 6f 64 75 63 69 6e 67 20 61 6e 79 20 6f producing any o
39c0: 75 74 70 75 74 29 0a 20 20 65 78 63 65 70 74 20 utput). except
39d0: 77 68 65 6e 20 66 6f 72 63 65 64 20 74 6f 20 66 when forced to f
39e0: 6c 75 73 68 2e 0a 0a 20 20 54 68 65 20 64 65 74 lush... The det
39f0: 61 69 6c 65 64 20 73 65 6d 61 6e 74 69 63 73 20 ailed semantics
3a00: 61 72 65 20 61 73 20 66 6f 6c 6c 6f 77 73 2e 20 are as follows.
3a10: 69 6e 66 6c 61 74 65 20 70 65 72 66 6f 72 6d 73 inflate performs
3a20: 20 6f 6e 65 20 6f 72 20 62 6f 74 68 20 6f 66 20 one or both of
3a30: 74 68 65 0a 20 20 66 6f 6c 6c 6f 77 69 6e 67 20 the. following
3a40: 61 63 74 69 6f 6e 73 3a 0a 0a 20 20 2d 20 44 65 actions:.. - De
3a50: 63 6f 6d 70 72 65 73 73 20 6d 6f 72 65 20 69 6e compress more in
3a60: 70 75 74 20 73 74 61 72 74 69 6e 67 20 61 74 20 put starting at
3a70: 6e 65 78 74 5f 69 6e 20 61 6e 64 20 75 70 64 61 next_in and upda
3a80: 74 65 20 6e 65 78 74 5f 69 6e 20 61 6e 64 20 61 te next_in and a
3a90: 76 61 69 6c 5f 69 6e 0a 20 20 20 20 61 63 63 6f vail_in. acco
3aa0: 72 64 69 6e 67 6c 79 2e 20 49 66 20 6e 6f 74 20 rdingly. If not
3ab0: 61 6c 6c 20 69 6e 70 75 74 20 63 61 6e 20 62 65 all input can be
3ac0: 20 70 72 6f 63 65 73 73 65 64 20 28 62 65 63 61 processed (beca
3ad0: 75 73 65 20 74 68 65 72 65 20 69 73 20 6e 6f 74 use there is not
3ae0: 0a 20 20 20 20 65 6e 6f 75 67 68 20 72 6f 6f 6d . enough room
3af0: 20 69 6e 20 74 68 65 20 6f 75 74 70 75 74 20 62 in the output b
3b00: 75 66 66 65 72 29 2c 20 6e 65 78 74 5f 69 6e 20 uffer), next_in
3b10: 69 73 20 75 70 64 61 74 65 64 20 61 6e 64 20 70 is updated and p
3b20: 72 6f 63 65 73 73 69 6e 67 0a 20 20 20 20 77 69 rocessing. wi
3b30: 6c 6c 20 72 65 73 75 6d 65 20 61 74 20 74 68 69 ll resume at thi
3b40: 73 20 70 6f 69 6e 74 20 66 6f 72 20 74 68 65 20 s point for the
3b50: 6e 65 78 74 20 63 61 6c 6c 20 6f 66 20 69 6e 66 next call of inf
3b60: 6c 61 74 65 28 29 2e 0a 0a 20 20 2d 20 50 72 6f late()... - Pro
3b70: 76 69 64 65 20 6d 6f 72 65 20 6f 75 74 70 75 74 vide more output
3b80: 20 73 74 61 72 74 69 6e 67 20 61 74 20 6e 65 78 starting at nex
3b90: 74 5f 6f 75 74 20 61 6e 64 20 75 70 64 61 74 65 t_out and update
3ba0: 20 6e 65 78 74 5f 6f 75 74 20 61 6e 64 20 61 76 next_out and av
3bb0: 61 69 6c 5f 6f 75 74 0a 20 20 20 20 61 63 63 6f ail_out. acco
3bc0: 72 64 69 6e 67 6c 79 2e 20 20 69 6e 66 6c 61 74 rdingly. inflat
3bd0: 65 28 29 20 70 72 6f 76 69 64 65 73 20 61 73 20 e() provides as
3be0: 6d 75 63 68 20 6f 75 74 70 75 74 20 61 73 20 70 much output as p
3bf0: 6f 73 73 69 62 6c 65 2c 20 75 6e 74 69 6c 20 74 ossible, until t
3c00: 68 65 72 65 0a 20 20 20 20 69 73 20 6e 6f 20 6d here. is no m
3c10: 6f 72 65 20 69 6e 70 75 74 20 64 61 74 61 20 6f ore input data o
3c20: 72 20 6e 6f 20 6d 6f 72 65 20 73 70 61 63 65 20 r no more space
3c30: 69 6e 20 74 68 65 20 6f 75 74 70 75 74 20 62 75 in the output bu
3c40: 66 66 65 72 20 28 73 65 65 20 62 65 6c 6f 77 0a ffer (see below.
3c50: 20 20 20 20 61 62 6f 75 74 20 74 68 65 20 66 6c about the fl
3c60: 75 73 68 20 70 61 72 61 6d 65 74 65 72 29 2e 0a ush parameter)..
3c70: 0a 20 20 42 65 66 6f 72 65 20 74 68 65 20 63 61 . Before the ca
3c80: 6c 6c 20 6f 66 20 69 6e 66 6c 61 74 65 28 29 2c ll of inflate(),
3c90: 20 74 68 65 20 61 70 70 6c 69 63 61 74 69 6f 6e the application
3ca0: 20 73 68 6f 75 6c 64 20 65 6e 73 75 72 65 20 74 should ensure t
3cb0: 68 61 74 20 61 74 20 6c 65 61 73 74 0a 20 20 6f hat at least. o
3cc0: 6e 65 20 6f 66 20 74 68 65 20 61 63 74 69 6f 6e ne of the action
3cd0: 73 20 69 73 20 70 6f 73 73 69 62 6c 65 2c 20 62 s is possible, b
3ce0: 79 20 70 72 6f 76 69 64 69 6e 67 20 6d 6f 72 65 y providing more
3cf0: 20 69 6e 70 75 74 20 61 6e 64 2f 6f 72 20 63 6f input and/or co
3d00: 6e 73 75 6d 69 6e 67 0a 20 20 6d 6f 72 65 20 6f nsuming. more o
3d10: 75 74 70 75 74 2c 20 61 6e 64 20 75 70 64 61 74 utput, and updat
3d20: 69 6e 67 20 74 68 65 20 6e 65 78 74 5f 2a 20 61 ing the next_* a
3d30: 6e 64 20 61 76 61 69 6c 5f 2a 20 76 61 6c 75 65 nd avail_* value
3d40: 73 20 61 63 63 6f 72 64 69 6e 67 6c 79 2e 0a 20 s accordingly..
3d50: 20 54 68 65 20 61 70 70 6c 69 63 61 74 69 6f 6e The application
3d60: 20 63 61 6e 20 63 6f 6e 73 75 6d 65 20 74 68 65 can consume the
3d70: 20 75 6e 63 6f 6d 70 72 65 73 73 65 64 20 6f 75 uncompressed ou
3d80: 74 70 75 74 20 77 68 65 6e 20 69 74 20 77 61 6e tput when it wan
3d90: 74 73 2c 20 66 6f 72 0a 20 20 65 78 61 6d 70 6c ts, for. exampl
3da0: 65 20 77 68 65 6e 20 74 68 65 20 6f 75 74 70 75 e when the outpu
3db0: 74 20 62 75 66 66 65 72 20 69 73 20 66 75 6c 6c t buffer is full
3dc0: 20 28 61 76 61 69 6c 5f 6f 75 74 20 3d 3d 20 30 (avail_out == 0
3dd0: 29 2c 20 6f 72 20 61 66 74 65 72 20 65 61 63 68 ), or after each
3de0: 0a 20 20 63 61 6c 6c 20 6f 66 20 69 6e 66 6c 61 . call of infla
3df0: 74 65 28 29 2e 20 49 66 20 69 6e 66 6c 61 74 65 te(). If inflate
3e00: 20 72 65 74 75 72 6e 73 20 5a 5f 4f 4b 20 61 6e returns Z_OK an
3e10: 64 20 77 69 74 68 20 7a 65 72 6f 20 61 76 61 69 d with zero avai
3e20: 6c 5f 6f 75 74 2c 20 69 74 0a 20 20 6d 75 73 74 l_out, it. must
3e30: 20 62 65 20 63 61 6c 6c 65 64 20 61 67 61 69 6e be called again
3e40: 20 61 66 74 65 72 20 6d 61 6b 69 6e 67 20 72 6f after making ro
3e50: 6f 6d 20 69 6e 20 74 68 65 20 6f 75 74 70 75 74 om in the output
3e60: 20 62 75 66 66 65 72 20 62 65 63 61 75 73 65 20 buffer because
3e70: 74 68 65 72 65 0a 20 20 6d 69 67 68 74 20 62 65 there. might be
3e80: 20 6d 6f 72 65 20 6f 75 74 70 75 74 20 70 65 6e more output pen
3e90: 64 69 6e 67 2e 0a 0a 20 20 20 20 49 66 20 74 68 ding... If th
3ea0: 65 20 70 61 72 61 6d 65 74 65 72 20 66 6c 75 73 e parameter flus
3eb0: 68 20 69 73 20 73 65 74 20 74 6f 20 5a 5f 53 59 h is set to Z_SY
3ec0: 4e 43 5f 46 4c 55 53 48 2c 20 69 6e 66 6c 61 74 NC_FLUSH, inflat
3ed0: 65 20 66 6c 75 73 68 65 73 20 61 73 20 6d 75 63 e flushes as muc
3ee0: 68 0a 20 20 6f 75 74 70 75 74 20 61 73 20 70 6f h. output as po
3ef0: 73 73 69 62 6c 65 20 74 6f 20 74 68 65 20 6f 75 ssible to the ou
3f00: 74 70 75 74 20 62 75 66 66 65 72 2e 20 54 68 65 tput buffer. The
3f10: 20 66 6c 75 73 68 69 6e 67 20 62 65 68 61 76 69 flushing behavi
3f20: 6f 72 20 6f 66 20 69 6e 66 6c 61 74 65 20 69 73 or of inflate is
3f30: 0a 20 20 6e 6f 74 20 73 70 65 63 69 66 69 65 64 . not specified
3f40: 20 66 6f 72 20 76 61 6c 75 65 73 20 6f 66 20 74 for values of t
3f50: 68 65 20 66 6c 75 73 68 20 70 61 72 61 6d 65 74 he flush paramet
3f60: 65 72 20 6f 74 68 65 72 20 74 68 61 6e 20 5a 5f er other than Z_
3f70: 53 59 4e 43 5f 46 4c 55 53 48 0a 20 20 61 6e 64 SYNC_FLUSH. and
3f80: 20 5a 5f 46 49 4e 49 53 48 2c 20 62 75 74 20 74 Z_FINISH, but t
3f90: 68 65 20 63 75 72 72 65 6e 74 20 69 6d 70 6c 65 he current imple
3fa0: 6d 65 6e 74 61 74 69 6f 6e 20 61 63 74 75 61 6c mentation actual
3fb0: 6c 79 20 66 6c 75 73 68 65 73 20 61 73 20 6d 75 ly flushes as mu
3fc0: 63 68 20 6f 75 74 70 75 74 0a 20 20 61 73 20 70 ch output. as p
3fd0: 6f 73 73 69 62 6c 65 20 61 6e 79 77 61 79 2e 0a ossible anyway..
3fe0: 0a 20 20 20 20 69 6e 66 6c 61 74 65 28 29 20 73 . inflate() s
3ff0: 68 6f 75 6c 64 20 6e 6f 72 6d 61 6c 6c 79 20 62 hould normally b
4000: 65 20 63 61 6c 6c 65 64 20 75 6e 74 69 6c 20 69 e called until i
4010: 74 20 72 65 74 75 72 6e 73 20 5a 5f 53 54 52 45 t returns Z_STRE
4020: 41 4d 5f 45 4e 44 20 6f 72 20 61 6e 0a 20 20 65 AM_END or an. e
4030: 72 72 6f 72 2e 20 48 6f 77 65 76 65 72 20 69 66 rror. However if
4040: 20 61 6c 6c 20 64 65 63 6f 6d 70 72 65 73 73 69 all decompressi
4050: 6f 6e 20 69 73 20 74 6f 20 62 65 20 70 65 72 66 on is to be perf
4060: 6f 72 6d 65 64 20 69 6e 20 61 20 73 69 6e 67 6c ormed in a singl
4070: 65 20 73 74 65 70 0a 20 20 28 61 20 73 69 6e 67 e step. (a sing
4080: 6c 65 20 63 61 6c 6c 20 6f 66 20 69 6e 66 6c 61 le call of infla
4090: 74 65 29 2c 20 74 68 65 20 70 61 72 61 6d 65 74 te), the paramet
40a0: 65 72 20 66 6c 75 73 68 20 73 68 6f 75 6c 64 20 er flush should
40b0: 62 65 20 73 65 74 20 74 6f 0a 20 20 5a 5f 46 49 be set to. Z_FI
40c0: 4e 49 53 48 2e 20 49 6e 20 74 68 69 73 20 63 61 NISH. In this ca
40d0: 73 65 20 61 6c 6c 20 70 65 6e 64 69 6e 67 20 69 se all pending i
40e0: 6e 70 75 74 20 69 73 20 70 72 6f 63 65 73 73 65 nput is processe
40f0: 64 20 61 6e 64 20 61 6c 6c 20 70 65 6e 64 69 6e d and all pendin
4100: 67 0a 20 20 6f 75 74 70 75 74 20 69 73 20 66 6c g. output is fl
4110: 75 73 68 65 64 3b 20 61 76 61 69 6c 5f 6f 75 74 ushed; avail_out
4120: 20 6d 75 73 74 20 62 65 20 6c 61 72 67 65 20 65 must be large e
4130: 6e 6f 75 67 68 20 74 6f 20 68 6f 6c 64 20 61 6c nough to hold al
4140: 6c 20 74 68 65 0a 20 20 75 6e 63 6f 6d 70 72 65 l the. uncompre
4150: 73 73 65 64 20 64 61 74 61 2e 20 28 54 68 65 20 ssed data. (The
4160: 73 69 7a 65 20 6f 66 20 74 68 65 20 75 6e 63 6f size of the unco
4170: 6d 70 72 65 73 73 65 64 20 64 61 74 61 20 6d 61 mpressed data ma
4180: 79 20 68 61 76 65 20 62 65 65 6e 20 73 61 76 65 y have been save
4190: 64 0a 20 20 62 79 20 74 68 65 20 63 6f 6d 70 72 d. by the compr
41a0: 65 73 73 6f 72 20 66 6f 72 20 74 68 69 73 20 70 essor for this p
41b0: 75 72 70 6f 73 65 2e 29 20 54 68 65 20 6e 65 78 urpose.) The nex
41c0: 74 20 6f 70 65 72 61 74 69 6f 6e 20 6f 6e 20 74 t operation on t
41d0: 68 69 73 20 73 74 72 65 61 6d 20 6d 75 73 74 0a his stream must.
41e0: 20 20 62 65 20 69 6e 66 6c 61 74 65 45 6e 64 20 be inflateEnd
41f0: 74 6f 20 64 65 61 6c 6c 6f 63 61 74 65 20 74 68 to deallocate th
4200: 65 20 64 65 63 6f 6d 70 72 65 73 73 69 6f 6e 20 e decompression
4210: 73 74 61 74 65 2e 20 54 68 65 20 75 73 65 20 6f state. The use o
4220: 66 20 5a 5f 46 49 4e 49 53 48 0a 20 20 69 73 20 f Z_FINISH. is
4230: 6e 65 76 65 72 20 72 65 71 75 69 72 65 64 2c 20 never required,
4240: 62 75 74 20 63 61 6e 20 62 65 20 75 73 65 64 20 but can be used
4250: 74 6f 20 69 6e 66 6f 72 6d 20 69 6e 66 6c 61 74 to inform inflat
4260: 65 20 74 68 61 74 20 61 20 66 61 73 74 65 72 20 e that a faster
4270: 72 6f 75 74 69 6e 65 0a 20 20 6d 61 79 20 62 65 routine. may be
4280: 20 75 73 65 64 20 66 6f 72 20 74 68 65 20 73 69 used for the si
4290: 6e 67 6c 65 20 69 6e 66 6c 61 74 65 28 29 20 63 ngle inflate() c
42a0: 61 6c 6c 2e 0a 0a 20 20 20 20 20 49 66 20 61 20 all... If a
42b0: 70 72 65 73 65 74 20 64 69 63 74 69 6f 6e 61 72 preset dictionar
42c0: 79 20 69 73 20 6e 65 65 64 65 64 20 61 74 20 74 y is needed at t
42d0: 68 69 73 20 70 6f 69 6e 74 20 28 73 65 65 20 69 his point (see i
42e0: 6e 66 6c 61 74 65 53 65 74 44 69 63 74 69 6f 6e nflateSetDiction
42f0: 61 72 79 0a 20 20 62 65 6c 6f 77 29 2c 20 69 6e ary. below), in
4300: 66 6c 61 74 65 20 73 65 74 73 20 73 74 72 6d 2d flate sets strm-
4310: 61 64 6c 65 72 20 74 6f 20 74 68 65 20 61 64 6c adler to the adl
4320: 65 72 33 32 20 63 68 65 63 6b 73 75 6d 20 6f 66 er32 checksum of
4330: 20 74 68 65 0a 20 20 64 69 63 74 69 6f 6e 61 72 the. dictionar
4340: 79 20 63 68 6f 73 65 6e 20 62 79 20 74 68 65 20 y chosen by the
4350: 63 6f 6d 70 72 65 73 73 6f 72 20 61 6e 64 20 72 compressor and r
4360: 65 74 75 72 6e 73 20 5a 5f 4e 45 45 44 5f 44 49 eturns Z_NEED_DI
4370: 43 54 3b 20 6f 74 68 65 72 77 69 73 65 20 0a 20 CT; otherwise .
4380: 20 69 74 20 73 65 74 73 20 73 74 72 6d 2d 3e 61 it sets strm->a
4390: 64 6c 65 72 20 74 6f 20 74 68 65 20 61 64 6c 65 dler to the adle
43a0: 72 33 32 20 63 68 65 63 6b 73 75 6d 20 6f 66 20 r32 checksum of
43b0: 61 6c 6c 20 6f 75 74 70 75 74 20 70 72 6f 64 75 all output produ
43c0: 63 65 64 0a 20 20 73 6f 20 66 61 72 20 28 74 68 ced. so far (th
43d0: 61 74 20 69 73 2c 20 74 6f 74 61 6c 5f 6f 75 74 at is, total_out
43e0: 20 62 79 74 65 73 29 20 61 6e 64 20 72 65 74 75 bytes) and retu
43f0: 72 6e 73 20 5a 5f 4f 4b 2c 20 5a 5f 53 54 52 45 rns Z_OK, Z_STRE
4400: 41 4d 5f 45 4e 44 20 6f 72 0a 20 20 61 6e 20 65 AM_END or. an e
4410: 72 72 6f 72 20 63 6f 64 65 20 61 73 20 64 65 73 rror code as des
4420: 63 72 69 62 65 64 20 62 65 6c 6f 77 2e 20 41 74 cribed below. At
4430: 20 74 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 the end of the
4440: 73 74 72 65 61 6d 2c 20 69 6e 66 6c 61 74 65 28 stream, inflate(
4450: 29 0a 20 20 63 68 65 63 6b 73 20 74 68 61 74 20 ). checks that
4460: 69 74 73 20 63 6f 6d 70 75 74 65 64 20 61 64 6c its computed adl
4470: 65 72 33 32 20 63 68 65 63 6b 73 75 6d 20 69 73 er32 checksum is
4480: 20 65 71 75 61 6c 20 74 6f 20 74 68 61 74 20 73 equal to that s
4490: 61 76 65 64 20 62 79 20 74 68 65 0a 20 20 63 6f aved by the. co
44a0: 6d 70 72 65 73 73 6f 72 20 61 6e 64 20 72 65 74 mpressor and ret
44b0: 75 72 6e 73 20 5a 5f 53 54 52 45 41 4d 5f 45 4e urns Z_STREAM_EN
44c0: 44 20 6f 6e 6c 79 20 69 66 20 74 68 65 20 63 68 D only if the ch
44d0: 65 63 6b 73 75 6d 20 69 73 20 63 6f 72 72 65 63 ecksum is correc
44e0: 74 2e 0a 0a 20 20 20 20 69 6e 66 6c 61 74 65 28 t... inflate(
44f0: 29 20 72 65 74 75 72 6e 73 20 5a 5f 4f 4b 20 69 ) returns Z_OK i
4500: 66 20 73 6f 6d 65 20 70 72 6f 67 72 65 73 73 20 f some progress
4510: 68 61 73 20 62 65 65 6e 20 6d 61 64 65 20 28 6d has been made (m
4520: 6f 72 65 20 69 6e 70 75 74 20 70 72 6f 63 65 73 ore input proces
4530: 73 65 64 0a 20 20 6f 72 20 6d 6f 72 65 20 6f 75 sed. or more ou
4540: 74 70 75 74 20 70 72 6f 64 75 63 65 64 29 2c 20 tput produced),
4550: 5a 5f 53 54 52 45 41 4d 5f 45 4e 44 20 69 66 20 Z_STREAM_END if
4560: 74 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 63 the end of the c
4570: 6f 6d 70 72 65 73 73 65 64 20 64 61 74 61 20 68 ompressed data h
4580: 61 73 0a 20 20 62 65 65 6e 20 72 65 61 63 68 65 as. been reache
4590: 64 20 61 6e 64 20 61 6c 6c 20 75 6e 63 6f 6d 70 d and all uncomp
45a0: 72 65 73 73 65 64 20 6f 75 74 70 75 74 20 68 61 ressed output ha
45b0: 73 20 62 65 65 6e 20 70 72 6f 64 75 63 65 64 2c s been produced,
45c0: 20 5a 5f 4e 45 45 44 5f 44 49 43 54 20 69 66 20 Z_NEED_DICT if
45d0: 61 0a 20 20 70 72 65 73 65 74 20 64 69 63 74 69 a. preset dicti
45e0: 6f 6e 61 72 79 20 69 73 20 6e 65 65 64 65 64 20 onary is needed
45f0: 61 74 20 74 68 69 73 20 70 6f 69 6e 74 2c 20 5a at this point, Z
4600: 5f 44 41 54 41 5f 45 52 52 4f 52 20 69 66 20 74 _DATA_ERROR if t
4610: 68 65 20 69 6e 70 75 74 20 64 61 74 61 20 77 61 he input data wa
4620: 73 0a 20 20 63 6f 72 72 75 70 74 65 64 20 28 69 s. corrupted (i
4630: 6e 70 75 74 20 73 74 72 65 61 6d 20 6e 6f 74 20 nput stream not
4640: 63 6f 6e 66 6f 72 6d 69 6e 67 20 74 6f 20 74 68 conforming to th
4650: 65 20 7a 6c 69 62 20 66 6f 72 6d 61 74 20 6f 72 e zlib format or
4660: 20 69 6e 63 6f 72 72 65 63 74 0a 20 20 61 64 6c incorrect. adl
4670: 65 72 33 32 20 63 68 65 63 6b 73 75 6d 29 2c 20 er32 checksum),
4680: 5a 5f 53 54 52 45 41 4d 5f 45 52 52 4f 52 20 69 Z_STREAM_ERROR i
4690: 66 20 74 68 65 20 73 74 72 65 61 6d 20 73 74 72 f the stream str
46a0: 75 63 74 75 72 65 20 77 61 73 20 69 6e 63 6f 6e ucture was incon
46b0: 73 69 73 74 65 6e 74 0a 20 20 28 66 6f 72 20 65 sistent. (for e
46c0: 78 61 6d 70 6c 65 20 69 66 20 6e 65 78 74 5f 69 xample if next_i
46d0: 6e 20 6f 72 20 6e 65 78 74 5f 6f 75 74 20 77 61 n or next_out wa
46e0: 73 20 4e 55 4c 4c 29 2c 20 5a 5f 4d 45 4d 5f 45 s NULL), Z_MEM_E
46f0: 52 52 4f 52 20 69 66 20 74 68 65 72 65 20 77 61 RROR if there wa
4700: 73 20 6e 6f 74 0a 20 20 65 6e 6f 75 67 68 20 6d s not. enough m
4710: 65 6d 6f 72 79 2c 20 5a 5f 42 55 46 5f 45 52 52 emory, Z_BUF_ERR
4720: 4f 52 20 69 66 20 6e 6f 20 70 72 6f 67 72 65 73 OR if no progres
4730: 73 20 69 73 20 70 6f 73 73 69 62 6c 65 20 6f 72 s is possible or
4740: 20 69 66 20 74 68 65 72 65 20 77 61 73 20 6e 6f if there was no
4750: 74 0a 20 20 65 6e 6f 75 67 68 20 72 6f 6f 6d 20 t. enough room
4760: 69 6e 20 74 68 65 20 6f 75 74 70 75 74 20 62 75 in the output bu
4770: 66 66 65 72 20 77 68 65 6e 20 5a 5f 46 49 4e 49 ffer when Z_FINI
4780: 53 48 20 69 73 20 75 73 65 64 2e 20 49 6e 20 74 SH is used. In t
4790: 68 65 20 5a 5f 44 41 54 41 5f 45 52 52 4f 52 0a he Z_DATA_ERROR.
47a0: 20 20 63 61 73 65 2c 20 74 68 65 20 61 70 70 6c case, the appl
47b0: 69 63 61 74 69 6f 6e 20 6d 61 79 20 74 68 65 6e ication may then
47c0: 20 63 61 6c 6c 20 69 6e 66 6c 61 74 65 53 79 6e call inflateSyn
47d0: 63 20 74 6f 20 6c 6f 6f 6b 20 66 6f 72 20 61 20 c to look for a
47e0: 67 6f 6f 64 0a 20 20 63 6f 6d 70 72 65 73 73 69 good. compressi
47f0: 6f 6e 20 62 6c 6f 63 6b 2e 0a 2a 2f 0a 0a 0a 5a on block..*/...Z
4800: 45 58 54 45 52 4e 20 69 6e 74 20 5a 45 58 50 4f EXTERN int ZEXPO
4810: 52 54 20 69 6e 66 6c 61 74 65 45 6e 64 20 4f 46 RT inflateEnd OF
4820: 28 28 7a 5f 73 74 72 65 61 6d 70 20 73 74 72 6d ((z_streamp strm
4830: 29 29 3b 0a 2f 2a 0a 20 20 20 20 20 41 6c 6c 20 ));./*. All
4840: 64 79 6e 61 6d 69 63 61 6c 6c 79 20 61 6c 6c 6f dynamically allo
4850: 63 61 74 65 64 20 64 61 74 61 20 73 74 72 75 63 cated data struc
4860: 74 75 72 65 73 20 66 6f 72 20 74 68 69 73 20 73 tures for this s
4870: 74 72 65 61 6d 20 61 72 65 20 66 72 65 65 64 2e tream are freed.
4880: 0a 20 20 20 54 68 69 73 20 66 75 6e 63 74 69 6f . This functio
4890: 6e 20 64 69 73 63 61 72 64 73 20 61 6e 79 20 75 n discards any u
48a0: 6e 70 72 6f 63 65 73 73 65 64 20 69 6e 70 75 74 nprocessed input
48b0: 20 61 6e 64 20 64 6f 65 73 20 6e 6f 74 20 66 6c and does not fl
48c0: 75 73 68 20 61 6e 79 0a 20 20 20 70 65 6e 64 69 ush any. pendi
48d0: 6e 67 20 6f 75 74 70 75 74 2e 0a 0a 20 20 20 20 ng output...
48e0: 20 69 6e 66 6c 61 74 65 45 6e 64 20 72 65 74 75 inflateEnd retu
48f0: 72 6e 73 20 5a 5f 4f 4b 20 69 66 20 73 75 63 63 rns Z_OK if succ
4900: 65 73 73 2c 20 5a 5f 53 54 52 45 41 4d 5f 45 52 ess, Z_STREAM_ER
4910: 52 4f 52 20 69 66 20 74 68 65 20 73 74 72 65 61 ROR if the strea
4920: 6d 20 73 74 61 74 65 0a 20 20 20 77 61 73 20 69 m state. was i
4930: 6e 63 6f 6e 73 69 73 74 65 6e 74 2e 20 49 6e 20 nconsistent. In
4940: 74 68 65 20 65 72 72 6f 72 20 63 61 73 65 2c 20 the error case,
4950: 6d 73 67 20 6d 61 79 20 62 65 20 73 65 74 20 62 msg may be set b
4960: 75 74 20 74 68 65 6e 20 70 6f 69 6e 74 73 20 74 ut then points t
4970: 6f 20 61 0a 20 20 20 73 74 61 74 69 63 20 73 74 o a. static st
4980: 72 69 6e 67 20 28 77 68 69 63 68 20 6d 75 73 74 ring (which must
4990: 20 6e 6f 74 20 62 65 20 64 65 61 6c 6c 6f 63 61 not be dealloca
49a0: 74 65 64 29 2e 0a 2a 2f 0a 0a 20 20 20 20 20 20 ted)..*/..
49b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
49c0: 20 20 2f 2a 20 41 64 76 61 6e 63 65 64 20 66 75 /* Advanced fu
49d0: 6e 63 74 69 6f 6e 73 20 2a 2f 0a 0a 2f 2a 0a 20 nctions */../*.
49e0: 20 20 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 The following
49f0: 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 6e functions are n
4a00: 65 65 64 65 64 20 6f 6e 6c 79 20 69 6e 20 73 6f eeded only in so
4a10: 6d 65 20 73 70 65 63 69 61 6c 20 61 70 70 6c 69 me special appli
4a20: 63 61 74 69 6f 6e 73 2e 0a 2a 2f 0a 0a 2f 2a 20 cations..*/../*
4a30: 20 20 0a 5a 45 58 54 45 52 4e 20 69 6e 74 20 5a .ZEXTERN int Z
4a40: 45 58 50 4f 52 54 20 64 65 66 6c 61 74 65 49 6e EXPORT deflateIn
4a50: 69 74 32 20 4f 46 28 28 7a 5f 73 74 72 65 61 6d it2 OF((z_stream
4a60: 70 20 73 74 72 6d 2c 0a 20 20 20 20 20 20 20 20 p strm,.
4a70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4a80: 20 20 20 20 20 20 20 20 20 20 20 20 20 69 6e 74 int
4a90: 20 20 6c 65 76 65 6c 2c 0a 20 20 20 20 20 20 20 level,.
4aa0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4ab0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 6e in
4ac0: 74 20 20 6d 65 74 68 6f 64 2c 0a 20 20 20 20 20 t method,.
4ad0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4ae0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4af0: 69 6e 74 20 20 77 69 6e 64 6f 77 42 69 74 73 2c int windowBits,
4b00: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
4b10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4b20: 20 20 20 20 20 20 69 6e 74 20 20 6d 65 6d 4c 65 int memLe
4b30: 76 65 6c 2c 0a 20 20 20 20 20 20 20 20 20 20 20 vel,.
4b40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4b50: 20 20 20 20 20 20 20 20 20 20 69 6e 74 20 20 73 int s
4b60: 74 72 61 74 65 67 79 29 29 3b 0a 0a 20 20 20 20 trategy));..
4b70: 20 54 68 69 73 20 69 73 20 61 6e 6f 74 68 65 72 This is another
4b80: 20 76 65 72 73 69 6f 6e 20 6f 66 20 64 65 66 6c version of defl
4b90: 61 74 65 49 6e 69 74 20 77 69 74 68 20 6d 6f 72 ateInit with mor
4ba0: 65 20 63 6f 6d 70 72 65 73 73 69 6f 6e 20 6f 70 e compression op
4bb0: 74 69 6f 6e 73 2e 20 54 68 65 0a 20 20 20 66 69 tions. The. fi
4bc0: 65 6c 64 73 20 6e 65 78 74 5f 69 6e 2c 20 7a 61 elds next_in, za
4bd0: 6c 6c 6f 63 2c 20 7a 66 72 65 65 20 61 6e 64 20 lloc, zfree and
4be0: 6f 70 61 71 75 65 20 6d 75 73 74 20 62 65 20 69 opaque must be i
4bf0: 6e 69 74 69 61 6c 69 7a 65 64 20 62 65 66 6f 72 nitialized befor
4c00: 65 20 62 79 0a 20 20 20 74 68 65 20 63 61 6c 6c e by. the call
4c10: 65 72 2e 0a 0a 20 20 20 20 20 54 68 65 20 6d 65 er... The me
4c20: 74 68 6f 64 20 70 61 72 61 6d 65 74 65 72 20 69 thod parameter i
4c30: 73 20 74 68 65 20 63 6f 6d 70 72 65 73 73 69 6f s the compressio
4c40: 6e 20 6d 65 74 68 6f 64 2e 20 49 74 20 6d 75 73 n method. It mus
4c50: 74 20 62 65 20 5a 5f 44 45 46 4c 41 54 45 44 20 t be Z_DEFLATED
4c60: 69 6e 0a 20 20 20 74 68 69 73 20 76 65 72 73 69 in. this versi
4c70: 6f 6e 20 6f 66 20 74 68 65 20 6c 69 62 72 61 72 on of the librar
4c80: 79 2e 0a 0a 20 20 20 20 20 54 68 65 20 77 69 6e y... The win
4c90: 64 6f 77 42 69 74 73 20 70 61 72 61 6d 65 74 65 dowBits paramete
4ca0: 72 20 69 73 20 74 68 65 20 62 61 73 65 20 74 77 r is the base tw
4cb0: 6f 20 6c 6f 67 61 72 69 74 68 6d 20 6f 66 20 74 o logarithm of t
4cc0: 68 65 20 77 69 6e 64 6f 77 20 73 69 7a 65 0a 20 he window size.
4cd0: 20 20 28 74 68 65 20 73 69 7a 65 20 6f 66 20 74 (the size of t
4ce0: 68 65 20 68 69 73 74 6f 72 79 20 62 75 66 66 65 he history buffe
4cf0: 72 29 2e 20 20 49 74 20 73 68 6f 75 6c 64 20 62 r). It should b
4d00: 65 20 69 6e 20 74 68 65 20 72 61 6e 67 65 20 38 e in the range 8
4d10: 2e 2e 31 35 20 66 6f 72 20 74 68 69 73 0a 20 20 ..15 for this.
4d20: 20 76 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 version of the
4d30: 6c 69 62 72 61 72 79 2e 20 4c 61 72 67 65 72 20 library. Larger
4d40: 76 61 6c 75 65 73 20 6f 66 20 74 68 69 73 20 70 values of this p
4d50: 61 72 61 6d 65 74 65 72 20 72 65 73 75 6c 74 20 arameter result
4d60: 69 6e 20 62 65 74 74 65 72 0a 20 20 20 63 6f 6d in better. com
4d70: 70 72 65 73 73 69 6f 6e 20 61 74 20 74 68 65 20 pression at the
4d80: 65 78 70 65 6e 73 65 20 6f 66 20 6d 65 6d 6f 72 expense of memor
4d90: 79 20 75 73 61 67 65 2e 20 54 68 65 20 64 65 66 y usage. The def
4da0: 61 75 6c 74 20 76 61 6c 75 65 20 69 73 20 31 35 ault value is 15
4db0: 20 69 66 0a 20 20 20 64 65 66 6c 61 74 65 49 6e if. deflateIn
4dc0: 69 74 20 69 73 20 75 73 65 64 20 69 6e 73 74 65 it is used inste
4dd0: 61 64 2e 0a 0a 20 20 20 20 20 54 68 65 20 6d 65 ad... The me
4de0: 6d 4c 65 76 65 6c 20 70 61 72 61 6d 65 74 65 72 mLevel parameter
4df0: 20 73 70 65 63 69 66 69 65 73 20 68 6f 77 20 6d specifies how m
4e00: 75 63 68 20 6d 65 6d 6f 72 79 20 73 68 6f 75 6c uch memory shoul
4e10: 64 20 62 65 20 61 6c 6c 6f 63 61 74 65 64 0a 20 d be allocated.
4e20: 20 20 66 6f 72 20 74 68 65 20 69 6e 74 65 72 6e for the intern
4e30: 61 6c 20 63 6f 6d 70 72 65 73 73 69 6f 6e 20 73 al compression s
4e40: 74 61 74 65 2e 20 6d 65 6d 4c 65 76 65 6c 3d 31 tate. memLevel=1
4e50: 20 75 73 65 73 20 6d 69 6e 69 6d 75 6d 20 6d 65 uses minimum me
4e60: 6d 6f 72 79 20 62 75 74 0a 20 20 20 69 73 20 73 mory but. is s
4e70: 6c 6f 77 20 61 6e 64 20 72 65 64 75 63 65 73 20 low and reduces
4e80: 63 6f 6d 70 72 65 73 73 69 6f 6e 20 72 61 74 69 compression rati
4e90: 6f 3b 20 6d 65 6d 4c 65 76 65 6c 3d 39 20 75 73 o; memLevel=9 us
4ea0: 65 73 20 6d 61 78 69 6d 75 6d 20 6d 65 6d 6f 72 es maximum memor
4eb0: 79 0a 20 20 20 66 6f 72 20 6f 70 74 69 6d 61 6c y. for optimal
4ec0: 20 73 70 65 65 64 2e 20 54 68 65 20 64 65 66 61 speed. The defa
4ed0: 75 6c 74 20 76 61 6c 75 65 20 69 73 20 38 2e 20 ult value is 8.
4ee0: 53 65 65 20 7a 63 6f 6e 66 2e 68 20 66 6f 72 20 See zconf.h for
4ef0: 74 6f 74 61 6c 20 6d 65 6d 6f 72 79 0a 20 20 20 total memory.
4f00: 75 73 61 67 65 20 61 73 20 61 20 66 75 6e 63 74 usage as a funct
4f10: 69 6f 6e 20 6f 66 20 77 69 6e 64 6f 77 42 69 74 ion of windowBit
4f20: 73 20 61 6e 64 20 6d 65 6d 4c 65 76 65 6c 2e 0a s and memLevel..
4f30: 0a 20 20 20 20 20 54 68 65 20 73 74 72 61 74 65 . The strate
4f40: 67 79 20 70 61 72 61 6d 65 74 65 72 20 69 73 20 gy parameter is
4f50: 75 73 65 64 20 74 6f 20 74 75 6e 65 20 74 68 65 used to tune the
4f60: 20 63 6f 6d 70 72 65 73 73 69 6f 6e 20 61 6c 67 compression alg
4f70: 6f 72 69 74 68 6d 2e 20 55 73 65 20 74 68 65 0a orithm. Use the.
4f80: 20 20 20 76 61 6c 75 65 20 5a 5f 44 45 46 41 55 value Z_DEFAU
4f90: 4c 54 5f 53 54 52 41 54 45 47 59 20 66 6f 72 20 LT_STRATEGY for
4fa0: 6e 6f 72 6d 61 6c 20 64 61 74 61 2c 20 5a 5f 46 normal data, Z_F
4fb0: 49 4c 54 45 52 45 44 20 66 6f 72 20 64 61 74 61 ILTERED for data
4fc0: 20 70 72 6f 64 75 63 65 64 20 62 79 20 61 0a 20 produced by a.
4fd0: 20 20 66 69 6c 74 65 72 20 28 6f 72 20 70 72 65 filter (or pre
4fe0: 64 69 63 74 6f 72 29 2c 20 6f 72 20 5a 5f 48 55 dictor), or Z_HU
4ff0: 46 46 4d 41 4e 5f 4f 4e 4c 59 20 74 6f 20 66 6f FFMAN_ONLY to fo
5000: 72 63 65 20 48 75 66 66 6d 61 6e 20 65 6e 63 6f rce Huffman enco
5010: 64 69 6e 67 20 6f 6e 6c 79 20 28 6e 6f 0a 20 20 ding only (no.
5020: 20 73 74 72 69 6e 67 20 6d 61 74 63 68 29 2e 20 string match).
5030: 20 46 69 6c 74 65 72 65 64 20 64 61 74 61 20 63 Filtered data c
5040: 6f 6e 73 69 73 74 73 20 6d 6f 73 74 6c 79 20 6f onsists mostly o
5050: 66 20 73 6d 61 6c 6c 20 76 61 6c 75 65 73 20 77 f small values w
5060: 69 74 68 20 61 0a 20 20 20 73 6f 6d 65 77 68 61 ith a. somewha
5070: 74 20 72 61 6e 64 6f 6d 20 64 69 73 74 72 69 62 t random distrib
5080: 75 74 69 6f 6e 2e 20 49 6e 20 74 68 69 73 20 63 ution. In this c
5090: 61 73 65 2c 20 74 68 65 20 63 6f 6d 70 72 65 73 ase, the compres
50a0: 73 69 6f 6e 20 61 6c 67 6f 72 69 74 68 6d 20 69 sion algorithm i
50b0: 73 0a 20 20 20 74 75 6e 65 64 20 74 6f 20 63 6f s. tuned to co
50c0: 6d 70 72 65 73 73 20 74 68 65 6d 20 62 65 74 74 mpress them bett
50d0: 65 72 2e 20 54 68 65 20 65 66 66 65 63 74 20 6f er. The effect o
50e0: 66 20 5a 5f 46 49 4c 54 45 52 45 44 20 69 73 20 f Z_FILTERED is
50f0: 74 6f 20 66 6f 72 63 65 20 6d 6f 72 65 0a 20 20 to force more.
5100: 20 48 75 66 66 6d 61 6e 20 63 6f 64 69 6e 67 20 Huffman coding
5110: 61 6e 64 20 6c 65 73 73 20 73 74 72 69 6e 67 20 and less string
5120: 6d 61 74 63 68 69 6e 67 3b 20 69 74 20 69 73 20 matching; it is
5130: 73 6f 6d 65 77 68 61 74 20 69 6e 74 65 72 6d 65 somewhat interme
5140: 64 69 61 74 65 0a 20 20 20 62 65 74 77 65 65 6e diate. between
5150: 20 5a 5f 44 45 46 41 55 4c 54 20 61 6e 64 20 5a Z_DEFAULT and Z
5160: 5f 48 55 46 46 4d 41 4e 5f 4f 4e 4c 59 2e 20 54 _HUFFMAN_ONLY. T
5170: 68 65 20 73 74 72 61 74 65 67 79 20 70 61 72 61 he strategy para
5180: 6d 65 74 65 72 20 6f 6e 6c 79 20 61 66 66 65 63 meter only affec
5190: 74 73 0a 20 20 20 74 68 65 20 63 6f 6d 70 72 65 ts. the compre
51a0: 73 73 69 6f 6e 20 72 61 74 69 6f 20 62 75 74 20 ssion ratio but
51b0: 6e 6f 74 20 74 68 65 20 63 6f 72 72 65 63 74 6e not the correctn
51c0: 65 73 73 20 6f 66 20 74 68 65 20 63 6f 6d 70 72 ess of the compr
51d0: 65 73 73 65 64 20 6f 75 74 70 75 74 20 65 76 65 essed output eve
51e0: 6e 0a 20 20 20 69 66 20 69 74 20 69 73 20 6e 6f n. if it is no
51f0: 74 20 73 65 74 20 61 70 70 72 6f 70 72 69 61 74 t set appropriat
5200: 65 6c 79 2e 0a 0a 20 20 20 20 20 20 64 65 66 6c ely... defl
5210: 61 74 65 49 6e 69 74 32 20 72 65 74 75 72 6e 73 ateInit2 returns
5220: 20 5a 5f 4f 4b 20 69 66 20 73 75 63 63 65 73 73 Z_OK if success
5230: 2c 20 5a 5f 4d 45 4d 5f 45 52 52 4f 52 20 69 66 , Z_MEM_ERROR if
5240: 20 74 68 65 72 65 20 77 61 73 20 6e 6f 74 20 65 there was not e
5250: 6e 6f 75 67 68 0a 20 20 20 6d 65 6d 6f 72 79 2c nough. memory,
5260: 20 5a 5f 53 54 52 45 41 4d 5f 45 52 52 4f 52 20 Z_STREAM_ERROR
5270: 69 66 20 61 20 70 61 72 61 6d 65 74 65 72 20 69 if a parameter i
5280: 73 20 69 6e 76 61 6c 69 64 20 28 73 75 63 68 20 s invalid (such
5290: 61 73 20 61 6e 20 69 6e 76 61 6c 69 64 0a 20 20 as an invalid.
52a0: 20 6d 65 74 68 6f 64 29 2e 20 6d 73 67 20 69 73 method). msg is
52b0: 20 73 65 74 20 74 6f 20 6e 75 6c 6c 20 69 66 20 set to null if
52c0: 74 68 65 72 65 20 69 73 20 6e 6f 20 65 72 72 6f there is no erro
52d0: 72 20 6d 65 73 73 61 67 65 2e 20 20 64 65 66 6c r message. defl
52e0: 61 74 65 49 6e 69 74 32 20 64 6f 65 73 0a 20 20 ateInit2 does.
52f0: 20 6e 6f 74 20 70 65 72 66 6f 72 6d 20 61 6e 79 not perform any
5300: 20 63 6f 6d 70 72 65 73 73 69 6f 6e 3a 20 74 68 compression: th
5310: 69 73 20 77 69 6c 6c 20 62 65 20 64 6f 6e 65 20 is will be done
5320: 62 79 20 64 65 66 6c 61 74 65 28 29 2e 0a 2a 2f by deflate()..*/
5330: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
5340: 20 20 20 20 20 20 20 20 20 20 20 20 20 0a 23 69 .#i
5350: 66 6e 64 65 66 20 4b 49 5f 47 5a 5f 4e 4f 5f 43 fndef KI_GZ_NO_C
5360: 4f 4d 50 52 45 53 53 49 4f 4e 0d 0a 0d 0a 5a 45 OMPRESSION....ZE
5370: 58 54 45 52 4e 20 69 6e 74 20 5a 45 58 50 4f 52 XTERN int ZEXPOR
5380: 54 20 64 65 66 6c 61 74 65 53 65 74 44 69 63 74 T deflateSetDict
5390: 69 6f 6e 61 72 79 20 4f 46 28 28 7a 5f 73 74 72 ionary OF((z_str
53a0: 65 61 6d 70 20 73 74 72 6d 2c 0a 20 20 20 20 20 eamp strm,.
53b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
53c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
53d0: 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 42 79 const By
53e0: 74 65 66 20 2a 64 69 63 74 69 6f 6e 61 72 79 2c tef *dictionary,
53f0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
5400: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5410: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 75 49 uI
5420: 6e 74 20 20 64 69 63 74 4c 65 6e 67 74 68 29 29 nt dictLength))
5430: 3b 0a 2f 2a 0a 20 20 20 20 20 49 6e 69 74 69 61 ;./*. Initia
5440: 6c 69 7a 65 73 20 74 68 65 20 63 6f 6d 70 72 65 lizes the compre
5450: 73 73 69 6f 6e 20 64 69 63 74 69 6f 6e 61 72 79 ssion dictionary
5460: 20 66 72 6f 6d 20 74 68 65 20 67 69 76 65 6e 20 from the given
5470: 62 79 74 65 20 73 65 71 75 65 6e 63 65 0a 20 20 byte sequence.
5480: 20 77 69 74 68 6f 75 74 20 70 72 6f 64 75 63 69 without produci
5490: 6e 67 20 61 6e 79 20 63 6f 6d 70 72 65 73 73 65 ng any compresse
54a0: 64 20 6f 75 74 70 75 74 2e 20 54 68 69 73 20 66 d output. This f
54b0: 75 6e 63 74 69 6f 6e 20 6d 75 73 74 20 62 65 20 unction must be
54c0: 63 61 6c 6c 65 64 0a 20 20 20 69 6d 6d 65 64 69 called. immedi
54d0: 61 74 65 6c 79 20 61 66 74 65 72 20 64 65 66 6c ately after defl
54e0: 61 74 65 49 6e 69 74 2c 20 64 65 66 6c 61 74 65 ateInit, deflate
54f0: 49 6e 69 74 32 20 6f 72 20 64 65 66 6c 61 74 65 Init2 or deflate
5500: 52 65 73 65 74 2c 20 62 65 66 6f 72 65 20 61 6e Reset, before an
5510: 79 0a 20 20 20 63 61 6c 6c 20 6f 66 20 64 65 66 y. call of def
5520: 6c 61 74 65 2e 20 54 68 65 20 63 6f 6d 70 72 65 late. The compre
5530: 73 73 6f 72 20 61 6e 64 20 64 65 63 6f 6d 70 72 ssor and decompr
5540: 65 73 73 6f 72 20 6d 75 73 74 20 75 73 65 20 65 essor must use e
5550: 78 61 63 74 6c 79 20 74 68 65 20 73 61 6d 65 0a xactly the same.
5560: 20 20 20 64 69 63 74 69 6f 6e 61 72 79 20 28 73 dictionary (s
5570: 65 65 20 69 6e 66 6c 61 74 65 53 65 74 44 69 63 ee inflateSetDic
5580: 74 69 6f 6e 61 72 79 29 2e 0a 0a 20 20 20 20 20 tionary)...
5590: 54 68 65 20 64 69 63 74 69 6f 6e 61 72 79 20 73 The dictionary s
55a0: 68 6f 75 6c 64 20 63 6f 6e 73 69 73 74 20 6f 66 hould consist of
55b0: 20 73 74 72 69 6e 67 73 20 28 62 79 74 65 20 73 strings (byte s
55c0: 65 71 75 65 6e 63 65 73 29 20 74 68 61 74 20 61 equences) that a
55d0: 72 65 20 6c 69 6b 65 6c 79 0a 20 20 20 74 6f 20 re likely. to
55e0: 62 65 20 65 6e 63 6f 75 6e 74 65 72 65 64 20 6c be encountered l
55f0: 61 74 65 72 20 69 6e 20 74 68 65 20 64 61 74 61 ater in the data
5600: 20 74 6f 20 62 65 20 63 6f 6d 70 72 65 73 73 65 to be compresse
5610: 64 2c 20 77 69 74 68 20 74 68 65 20 6d 6f 73 74 d, with the most
5620: 20 63 6f 6d 6d 6f 6e 6c 79 0a 20 20 20 75 73 65 commonly. use
5630: 64 20 73 74 72 69 6e 67 73 20 70 72 65 66 65 72 d strings prefer
5640: 61 62 6c 79 20 70 75 74 20 74 6f 77 61 72 64 73 ably put towards
5650: 20 74 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 the end of the
5660: 64 69 63 74 69 6f 6e 61 72 79 2e 20 55 73 69 6e dictionary. Usin
5670: 67 20 61 0a 20 20 20 64 69 63 74 69 6f 6e 61 72 g a. dictionar
5680: 79 20 69 73 20 6d 6f 73 74 20 75 73 65 66 75 6c y is most useful
5690: 20 77 68 65 6e 20 74 68 65 20 64 61 74 61 20 74 when the data t
56a0: 6f 20 62 65 20 63 6f 6d 70 72 65 73 73 65 64 20 o be compressed
56b0: 69 73 20 73 68 6f 72 74 20 61 6e 64 20 63 61 6e is short and can
56c0: 20 62 65 0a 20 20 20 70 72 65 64 69 63 74 65 64 be. predicted
56d0: 20 77 69 74 68 20 67 6f 6f 64 20 61 63 63 75 72 with good accur
56e0: 61 63 79 3b 20 74 68 65 20 64 61 74 61 20 63 61 acy; the data ca
56f0: 6e 20 74 68 65 6e 20 62 65 20 63 6f 6d 70 72 65 n then be compre
5700: 73 73 65 64 20 62 65 74 74 65 72 20 74 68 61 6e ssed better than
5710: 0a 20 20 20 77 69 74 68 20 74 68 65 20 64 65 66 . with the def
5720: 61 75 6c 74 20 65 6d 70 74 79 20 64 69 63 74 69 ault empty dicti
5730: 6f 6e 61 72 79 2e 0a 0a 20 20 20 20 20 44 65 70 onary... Dep
5740: 65 6e 64 69 6e 67 20 6f 6e 20 74 68 65 20 73 69 ending on the si
5750: 7a 65 20 6f 66 20 74 68 65 20 63 6f 6d 70 72 65 ze of the compre
5760: 73 73 69 6f 6e 20 64 61 74 61 20 73 74 72 75 63 ssion data struc
5770: 74 75 72 65 73 20 73 65 6c 65 63 74 65 64 20 62 tures selected b
5780: 79 0a 20 20 20 64 65 66 6c 61 74 65 49 6e 69 74 y. deflateInit
5790: 20 6f 72 20 64 65 66 6c 61 74 65 49 6e 69 74 32 or deflateInit2
57a0: 2c 20 61 20 70 61 72 74 20 6f 66 20 74 68 65 20 , a part of the
57b0: 64 69 63 74 69 6f 6e 61 72 79 20 6d 61 79 20 69 dictionary may i
57c0: 6e 20 65 66 66 65 63 74 20 62 65 0a 20 20 20 64 n effect be. d
57d0: 69 73 63 61 72 64 65 64 2c 20 66 6f 72 20 65 78 iscarded, for ex
57e0: 61 6d 70 6c 65 20 69 66 20 74 68 65 20 64 69 63 ample if the dic
57f0: 74 69 6f 6e 61 72 79 20 69 73 20 6c 61 72 67 65 tionary is large
5800: 72 20 74 68 61 6e 20 74 68 65 20 77 69 6e 64 6f r than the windo
5810: 77 20 73 69 7a 65 20 69 6e 0a 20 20 20 64 65 66 w size in. def
5820: 6c 61 74 65 20 6f 72 20 64 65 66 6c 61 74 65 32 late or deflate2
5830: 2e 20 54 68 75 73 20 74 68 65 20 73 74 72 69 6e . Thus the strin
5840: 67 73 20 6d 6f 73 74 20 6c 69 6b 65 6c 79 20 74 gs most likely t
5850: 6f 20 62 65 20 75 73 65 66 75 6c 20 73 68 6f 75 o be useful shou
5860: 6c 64 20 62 65 0a 20 20 20 70 75 74 20 61 74 20 ld be. put at
5870: 74 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 64 the end of the d
5880: 69 63 74 69 6f 6e 61 72 79 2c 20 6e 6f 74 20 61 ictionary, not a
5890: 74 20 74 68 65 20 66 72 6f 6e 74 2e 0a 0a 20 20 t the front...
58a0: 20 20 20 55 70 6f 6e 20 72 65 74 75 72 6e 20 6f Upon return o
58b0: 66 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 2c f this function,
58c0: 20 73 74 72 6d 2d 3e 61 64 6c 65 72 20 69 73 20 strm->adler is
58d0: 73 65 74 20 74 6f 20 74 68 65 20 41 64 6c 65 72 set to the Adler
58e0: 33 32 20 76 61 6c 75 65 0a 20 20 20 6f 66 20 74 32 value. of t
58f0: 68 65 20 64 69 63 74 69 6f 6e 61 72 79 3b 20 74 he dictionary; t
5900: 68 65 20 64 65 63 6f 6d 70 72 65 73 73 6f 72 20 he decompressor
5910: 6d 61 79 20 6c 61 74 65 72 20 75 73 65 20 74 68 may later use th
5920: 69 73 20 76 61 6c 75 65 20 74 6f 20 64 65 74 65 is value to dete
5930: 72 6d 69 6e 65 0a 20 20 20 77 68 69 63 68 20 64 rmine. which d
5940: 69 63 74 69 6f 6e 61 72 79 20 68 61 73 20 62 65 ictionary has be
5950: 65 6e 20 75 73 65 64 20 62 79 20 74 68 65 20 63 en used by the c
5960: 6f 6d 70 72 65 73 73 6f 72 2e 20 28 54 68 65 20 ompressor. (The
5970: 41 64 6c 65 72 33 32 20 76 61 6c 75 65 0a 20 20 Adler32 value.
5980: 20 61 70 70 6c 69 65 73 20 74 6f 20 74 68 65 20 applies to the
5990: 77 68 6f 6c 65 20 64 69 63 74 69 6f 6e 61 72 79 whole dictionary
59a0: 20 65 76 65 6e 20 69 66 20 6f 6e 6c 79 20 61 20 even if only a
59b0: 73 75 62 73 65 74 20 6f 66 20 74 68 65 20 64 69 subset of the di
59c0: 63 74 69 6f 6e 61 72 79 20 69 73 0a 20 20 20 61 ctionary is. a
59d0: 63 74 75 61 6c 6c 79 20 75 73 65 64 20 62 79 20 ctually used by
59e0: 74 68 65 20 63 6f 6d 70 72 65 73 73 6f 72 2e 29 the compressor.)
59f0: 0a 0a 20 20 20 20 20 64 65 66 6c 61 74 65 53 65 .. deflateSe
5a00: 74 44 69 63 74 69 6f 6e 61 72 79 20 72 65 74 75 tDictionary retu
5a10: 72 6e 73 20 5a 5f 4f 4b 20 69 66 20 73 75 63 63 rns Z_OK if succ
5a20: 65 73 73 2c 20 6f 72 20 5a 5f 53 54 52 45 41 4d ess, or Z_STREAM
5a30: 5f 45 52 52 4f 52 20 69 66 20 61 0a 20 20 20 70 _ERROR if a. p
5a40: 61 72 61 6d 65 74 65 72 20 69 73 20 69 6e 76 61 arameter is inva
5a50: 6c 69 64 20 28 73 75 63 68 20 61 73 20 4e 55 4c lid (such as NUL
5a60: 4c 20 64 69 63 74 69 6f 6e 61 72 79 29 20 6f 72 L dictionary) or
5a70: 20 74 68 65 20 73 74 72 65 61 6d 20 73 74 61 74 the stream stat
5a80: 65 20 69 73 0a 20 20 20 69 6e 63 6f 6e 73 69 73 e is. inconsis
5a90: 74 65 6e 74 20 28 66 6f 72 20 65 78 61 6d 70 6c tent (for exampl
5aa0: 65 20 69 66 20 64 65 66 6c 61 74 65 20 68 61 73 e if deflate has
5ab0: 20 61 6c 72 65 61 64 79 20 62 65 65 6e 20 63 61 already been ca
5ac0: 6c 6c 65 64 20 66 6f 72 20 74 68 69 73 20 73 74 lled for this st
5ad0: 72 65 61 6d 0a 20 20 20 6f 72 20 69 66 20 74 68 ream. or if th
5ae0: 65 20 63 6f 6d 70 72 65 73 73 69 6f 6e 20 6d 65 e compression me
5af0: 74 68 6f 64 20 69 73 20 62 73 6f 72 74 29 2e 20 thod is bsort).
5b00: 64 65 66 6c 61 74 65 53 65 74 44 69 63 74 69 6f deflateSetDictio
5b10: 6e 61 72 79 20 64 6f 65 73 20 6e 6f 74 0a 20 20 nary does not.
5b20: 20 70 65 72 66 6f 72 6d 20 61 6e 79 20 63 6f 6d perform any com
5b30: 70 72 65 73 73 69 6f 6e 3a 20 74 68 69 73 20 77 pression: this w
5b40: 69 6c 6c 20 62 65 20 64 6f 6e 65 20 62 79 20 64 ill be done by d
5b50: 65 66 6c 61 74 65 28 29 2e 0a 2a 2f 0a 0a 5a 45 eflate()..*/..ZE
5b60: 58 54 45 52 4e 20 69 6e 74 20 5a 45 58 50 4f 52 XTERN int ZEXPOR
5b70: 54 20 64 65 66 6c 61 74 65 43 6f 70 79 20 4f 46 T deflateCopy OF
5b80: 28 28 7a 5f 73 74 72 65 61 6d 70 20 64 65 73 74 ((z_streamp dest
5b90: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ,.
5ba0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5bb0: 20 20 20 20 20 20 7a 5f 73 74 72 65 61 6d 70 20 z_streamp
5bc0: 73 6f 75 72 63 65 29 29 3b 0a 2f 2a 0a 20 20 20 source));./*.
5bd0: 20 20 53 65 74 73 20 74 68 65 20 64 65 73 74 69 Sets the desti
5be0: 6e 61 74 69 6f 6e 20 73 74 72 65 61 6d 20 61 73 nation stream as
5bf0: 20 61 20 63 6f 6d 70 6c 65 74 65 20 63 6f 70 79 a complete copy
5c00: 20 6f 66 20 74 68 65 20 73 6f 75 72 63 65 20 73 of the source s
5c10: 74 72 65 61 6d 2e 0a 0a 20 20 20 20 20 54 68 69 tream... Thi
5c20: 73 20 66 75 6e 63 74 69 6f 6e 20 63 61 6e 20 62 s function can b
5c30: 65 20 75 73 65 66 75 6c 20 77 68 65 6e 20 73 65 e useful when se
5c40: 76 65 72 61 6c 20 63 6f 6d 70 72 65 73 73 69 6f veral compressio
5c50: 6e 20 73 74 72 61 74 65 67 69 65 73 20 77 69 6c n strategies wil
5c60: 6c 20 62 65 0a 20 20 20 74 72 69 65 64 2c 20 66 l be. tried, f
5c70: 6f 72 20 65 78 61 6d 70 6c 65 20 77 68 65 6e 20 or example when
5c80: 74 68 65 72 65 20 61 72 65 20 73 65 76 65 72 61 there are severa
5c90: 6c 20 77 61 79 73 20 6f 66 20 70 72 65 2d 70 72 l ways of pre-pr
5ca0: 6f 63 65 73 73 69 6e 67 20 74 68 65 20 69 6e 70 ocessing the inp
5cb0: 75 74 0a 20 20 20 64 61 74 61 20 77 69 74 68 20 ut. data with
5cc0: 61 20 66 69 6c 74 65 72 2e 20 54 68 65 20 73 74 a filter. The st
5cd0: 72 65 61 6d 73 20 74 68 61 74 20 77 69 6c 6c 20 reams that will
5ce0: 62 65 20 64 69 73 63 61 72 64 65 64 20 73 68 6f be discarded sho
5cf0: 75 6c 64 20 74 68 65 6e 20 62 65 20 66 72 65 65 uld then be free
5d00: 64 0a 20 20 20 62 79 20 63 61 6c 6c 69 6e 67 20 d. by calling
5d10: 64 65 66 6c 61 74 65 45 6e 64 2e 20 20 4e 6f 74 deflateEnd. Not
5d20: 65 20 74 68 61 74 20 64 65 66 6c 61 74 65 43 6f e that deflateCo
5d30: 70 79 20 64 75 70 6c 69 63 61 74 65 73 20 74 68 py duplicates th
5d40: 65 20 69 6e 74 65 72 6e 61 6c 0a 20 20 20 63 6f e internal. co
5d50: 6d 70 72 65 73 73 69 6f 6e 20 73 74 61 74 65 20 mpression state
5d60: 77 68 69 63 68 20 63 61 6e 20 62 65 20 71 75 69 which can be qui
5d70: 74 65 20 6c 61 72 67 65 2c 20 73 6f 20 74 68 69 te large, so thi
5d80: 73 20 73 74 72 61 74 65 67 79 20 69 73 20 73 6c s strategy is sl
5d90: 6f 77 20 61 6e 64 0a 20 20 20 63 61 6e 20 63 6f ow and. can co
5da0: 6e 73 75 6d 65 20 6c 6f 74 73 20 6f 66 20 6d 65 nsume lots of me
5db0: 6d 6f 72 79 2e 0a 0a 20 20 20 20 20 64 65 66 6c mory... defl
5dc0: 61 74 65 43 6f 70 79 20 72 65 74 75 72 6e 73 20 ateCopy returns
5dd0: 5a 5f 4f 4b 20 69 66 20 73 75 63 63 65 73 73 2c Z_OK if success,
5de0: 20 5a 5f 4d 45 4d 5f 45 52 52 4f 52 20 69 66 20 Z_MEM_ERROR if
5df0: 74 68 65 72 65 20 77 61 73 20 6e 6f 74 0a 20 20 there was not.
5e00: 20 65 6e 6f 75 67 68 20 6d 65 6d 6f 72 79 2c 20 enough memory,
5e10: 5a 5f 53 54 52 45 41 4d 5f 45 52 52 4f 52 20 69 Z_STREAM_ERROR i
5e20: 66 20 74 68 65 20 73 6f 75 72 63 65 20 73 74 72 f the source str
5e30: 65 61 6d 20 73 74 61 74 65 20 77 61 73 20 69 6e eam state was in
5e40: 63 6f 6e 73 69 73 74 65 6e 74 0a 20 20 20 28 73 consistent. (s
5e50: 75 63 68 20 61 73 20 7a 61 6c 6c 6f 63 20 62 65 uch as zalloc be
5e60: 69 6e 67 20 4e 55 4c 4c 29 2e 20 6d 73 67 20 69 ing NULL). msg i
5e70: 73 20 6c 65 66 74 20 75 6e 63 68 61 6e 67 65 64 s left unchanged
5e80: 20 69 6e 20 62 6f 74 68 20 73 6f 75 72 63 65 20 in both source
5e90: 61 6e 64 0a 20 20 20 64 65 73 74 69 6e 61 74 69 and. destinati
5ea0: 6f 6e 2e 0a 2a 2f 0a 0a 5a 45 58 54 45 52 4e 20 on..*/..ZEXTERN
5eb0: 69 6e 74 20 5a 45 58 50 4f 52 54 20 64 65 66 6c int ZEXPORT defl
5ec0: 61 74 65 52 65 73 65 74 20 4f 46 28 28 7a 5f 73 ateReset OF((z_s
5ed0: 74 72 65 61 6d 70 20 73 74 72 6d 29 29 3b 0a 2f treamp strm));./
5ee0: 2a 0a 20 20 20 20 20 54 68 69 73 20 66 75 6e 63 *. This func
5ef0: 74 69 6f 6e 20 69 73 20 65 71 75 69 76 61 6c 65 tion is equivale
5f00: 6e 74 20 74 6f 20 64 65 66 6c 61 74 65 45 6e 64 nt to deflateEnd
5f10: 20 66 6f 6c 6c 6f 77 65 64 20 62 79 20 64 65 66 followed by def
5f20: 6c 61 74 65 49 6e 69 74 2c 0a 20 20 20 62 75 74 lateInit,. but
5f30: 20 64 6f 65 73 20 6e 6f 74 20 66 72 65 65 20 61 does not free a
5f40: 6e 64 20 72 65 61 6c 6c 6f 63 61 74 65 20 61 6c nd reallocate al
5f50: 6c 20 74 68 65 20 69 6e 74 65 72 6e 61 6c 20 63 l the internal c
5f60: 6f 6d 70 72 65 73 73 69 6f 6e 20 73 74 61 74 65 ompression state
5f70: 2e 0a 20 20 20 54 68 65 20 73 74 72 65 61 6d 20 .. The stream
5f80: 77 69 6c 6c 20 6b 65 65 70 20 74 68 65 20 73 61 will keep the sa
5f90: 6d 65 20 63 6f 6d 70 72 65 73 73 69 6f 6e 20 6c me compression l
5fa0: 65 76 65 6c 20 61 6e 64 20 61 6e 79 20 6f 74 68 evel and any oth
5fb0: 65 72 20 61 74 74 72 69 62 75 74 65 73 0a 20 20 er attributes.
5fc0: 20 74 68 61 74 20 6d 61 79 20 68 61 76 65 20 62 that may have b
5fd0: 65 65 6e 20 73 65 74 20 62 79 20 64 65 66 6c 61 een set by defla
5fe0: 74 65 49 6e 69 74 32 2e 0a 0a 20 20 20 20 20 20 teInit2...
5ff0: 64 65 66 6c 61 74 65 52 65 73 65 74 20 72 65 74 deflateReset ret
6000: 75 72 6e 73 20 5a 5f 4f 4b 20 69 66 20 73 75 63 urns Z_OK if suc
6010: 63 65 73 73 2c 20 6f 72 20 5a 5f 53 54 52 45 41 cess, or Z_STREA
6020: 4d 5f 45 52 52 4f 52 20 69 66 20 74 68 65 20 73 M_ERROR if the s
6030: 6f 75 72 63 65 0a 20 20 20 73 74 72 65 61 6d 20 ource. stream
6040: 73 74 61 74 65 20 77 61 73 20 69 6e 63 6f 6e 73 state was incons
6050: 69 73 74 65 6e 74 20 28 73 75 63 68 20 61 73 20 istent (such as
6060: 7a 61 6c 6c 6f 63 20 6f 72 20 73 74 61 74 65 20 zalloc or state
6070: 62 65 69 6e 67 20 4e 55 4c 4c 29 2e 0a 2a 2f 0a being NULL)..*/.
6080: 0a 5a 45 58 54 45 52 4e 20 69 6e 74 20 5a 45 58 .ZEXTERN int ZEX
6090: 50 4f 52 54 20 64 65 66 6c 61 74 65 50 61 72 61 PORT deflatePara
60a0: 6d 73 20 4f 46 28 28 7a 5f 73 74 72 65 61 6d 70 ms OF((z_streamp
60b0: 20 73 74 72 6d 2c 0a 09 09 09 09 20 20 20 20 20 strm,.....
60c0: 20 69 6e 74 20 6c 65 76 65 6c 2c 0a 09 09 09 09 int level,.....
60d0: 20 20 20 20 20 20 69 6e 74 20 73 74 72 61 74 65 int strate
60e0: 67 79 29 29 3b 0a 2f 2a 0a 20 20 20 20 20 44 79 gy));./*. Dy
60f0: 6e 61 6d 69 63 61 6c 6c 79 20 75 70 64 61 74 65 namically update
6100: 20 74 68 65 20 63 6f 6d 70 72 65 73 73 69 6f 6e the compression
6110: 20 6c 65 76 65 6c 20 61 6e 64 20 63 6f 6d 70 72 level and compr
6120: 65 73 73 69 6f 6e 20 73 74 72 61 74 65 67 79 2e ession strategy.
6130: 20 20 54 68 65 0a 20 20 20 69 6e 74 65 72 70 72 The. interpr
6140: 65 74 61 74 69 6f 6e 20 6f 66 20 6c 65 76 65 6c etation of level
6150: 20 61 6e 64 20 73 74 72 61 74 65 67 79 20 69 73 and strategy is
6160: 20 61 73 20 69 6e 20 64 65 66 6c 61 74 65 49 6e as in deflateIn
6170: 69 74 32 2e 20 20 54 68 69 73 20 63 61 6e 20 62 it2. This can b
6180: 65 0a 20 20 20 75 73 65 64 20 74 6f 20 73 77 69 e. used to swi
6190: 74 63 68 20 62 65 74 77 65 65 6e 20 63 6f 6d 70 tch between comp
61a0: 72 65 73 73 69 6f 6e 20 61 6e 64 20 73 74 72 61 ression and stra
61b0: 69 67 68 74 20 63 6f 70 79 20 6f 66 20 74 68 65 ight copy of the
61c0: 20 69 6e 70 75 74 20 64 61 74 61 2c 20 6f 72 0a input data, or.
61d0: 20 20 20 74 6f 20 73 77 69 74 63 68 20 74 6f 20 to switch to
61e0: 61 20 64 69 66 66 65 72 65 6e 74 20 6b 69 6e 64 a different kind
61f0: 20 6f 66 20 69 6e 70 75 74 20 64 61 74 61 20 72 of input data r
6200: 65 71 75 69 72 69 6e 67 20 61 20 64 69 66 66 65 equiring a diffe
6210: 72 65 6e 74 0a 20 20 20 73 74 72 61 74 65 67 79 rent. strategy
6220: 2e 20 49 66 20 74 68 65 20 63 6f 6d 70 72 65 73 . If the compres
6230: 73 69 6f 6e 20 6c 65 76 65 6c 20 69 73 20 63 68 sion level is ch
6240: 61 6e 67 65 64 2c 20 74 68 65 20 69 6e 70 75 74 anged, the input
6250: 20 61 76 61 69 6c 61 62 6c 65 20 73 6f 20 66 61 available so fa
6260: 72 0a 20 20 20 69 73 20 63 6f 6d 70 72 65 73 73 r. is compress
6270: 65 64 20 77 69 74 68 20 74 68 65 20 6f 6c 64 20 ed with the old
6280: 6c 65 76 65 6c 20 28 61 6e 64 20 6d 61 79 20 62 level (and may b
6290: 65 20 66 6c 75 73 68 65 64 29 3b 20 74 68 65 20 e flushed); the
62a0: 6e 65 77 20 6c 65 76 65 6c 20 77 69 6c 6c 0a 20 new level will.
62b0: 20 20 74 61 6b 65 20 65 66 66 65 63 74 20 6f 6e take effect on
62c0: 6c 79 20 61 74 20 74 68 65 20 6e 65 78 74 20 63 ly at the next c
62d0: 61 6c 6c 20 6f 66 20 64 65 66 6c 61 74 65 28 29 all of deflate()
62e0: 2e 0a 0a 20 20 20 20 20 42 65 66 6f 72 65 20 74 ... Before t
62f0: 68 65 20 63 61 6c 6c 20 6f 66 20 64 65 66 6c 61 he call of defla
6300: 74 65 50 61 72 61 6d 73 2c 20 74 68 65 20 73 74 teParams, the st
6310: 72 65 61 6d 20 73 74 61 74 65 20 6d 75 73 74 20 ream state must
6320: 62 65 20 73 65 74 20 61 73 20 66 6f 72 0a 20 20 be set as for.
6330: 20 61 20 63 61 6c 6c 20 6f 66 20 64 65 66 6c 61 a call of defla
6340: 74 65 28 29 2c 20 73 69 6e 63 65 20 74 68 65 20 te(), since the
6350: 63 75 72 72 65 6e 74 6c 79 20 61 76 61 69 6c 61 currently availa
6360: 62 6c 65 20 69 6e 70 75 74 20 6d 61 79 20 68 61 ble input may ha
6370: 76 65 20 74 6f 0a 20 20 20 62 65 20 63 6f 6d 70 ve to. be comp
6380: 72 65 73 73 65 64 20 61 6e 64 20 66 6c 75 73 68 ressed and flush
6390: 65 64 2e 20 49 6e 20 70 61 72 74 69 63 75 6c 61 ed. In particula
63a0: 72 2c 20 73 74 72 6d 2d 3e 61 76 61 69 6c 5f 6f r, strm->avail_o
63b0: 75 74 20 6d 75 73 74 20 62 65 20 6e 6f 6e 2d 7a ut must be non-z
63c0: 65 72 6f 2e 0a 0a 20 20 20 20 20 64 65 66 6c 61 ero... defla
63d0: 74 65 50 61 72 61 6d 73 20 72 65 74 75 72 6e 73 teParams returns
63e0: 20 5a 5f 4f 4b 20 69 66 20 73 75 63 63 65 73 73 Z_OK if success
63f0: 2c 20 5a 5f 53 54 52 45 41 4d 5f 45 52 52 4f 52 , Z_STREAM_ERROR
6400: 20 69 66 20 74 68 65 20 73 6f 75 72 63 65 0a 20 if the source.
6410: 20 20 73 74 72 65 61 6d 20 73 74 61 74 65 20 77 stream state w
6420: 61 73 20 69 6e 63 6f 6e 73 69 73 74 65 6e 74 20 as inconsistent
6430: 6f 72 20 69 66 20 61 20 70 61 72 61 6d 65 74 65 or if a paramete
6440: 72 20 77 61 73 20 69 6e 76 61 6c 69 64 2c 20 5a r was invalid, Z
6450: 5f 42 55 46 5f 45 52 52 4f 52 0a 20 20 20 69 66 _BUF_ERROR. if
6460: 20 73 74 72 6d 2d 3e 61 76 61 69 6c 5f 6f 75 74 strm->avail_out
6470: 20 77 61 73 20 7a 65 72 6f 2e 0a 2a 2f 0a 0d 0a was zero..*/...
6480: 23 65 6e 64 69 66 20 2f 2a 20 4b 49 5f 47 5a 5f #endif /* KI_GZ_
6490: 4e 4f 5f 43 4f 4d 50 52 45 53 53 49 4f 4e 20 2a NO_COMPRESSION *
64a0: 2f 0d 0a 0d 0a 2f 2a 20 20 20 0a 5a 45 58 54 45 /..../* .ZEXTE
64b0: 52 4e 20 69 6e 74 20 5a 45 58 50 4f 52 54 20 69 RN int ZEXPORT i
64c0: 6e 66 6c 61 74 65 49 6e 69 74 32 20 4f 46 28 28 nflateInit2 OF((
64d0: 7a 5f 73 74 72 65 61 6d 70 20 73 74 72 6d 2c 0a z_streamp strm,.
64e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
64f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
6500: 20 20 20 20 20 69 6e 74 20 20 77 69 6e 64 6f 77 int window
6510: 42 69 74 73 29 29 3b 0a 0a 20 20 20 20 20 54 68 Bits));.. Th
6520: 69 73 20 69 73 20 61 6e 6f 74 68 65 72 20 76 65 is is another ve
6530: 72 73 69 6f 6e 20 6f 66 20 69 6e 66 6c 61 74 65 rsion of inflate
6540: 49 6e 69 74 20 77 69 74 68 20 61 6e 20 65 78 74 Init with an ext
6550: 72 61 20 70 61 72 61 6d 65 74 65 72 2e 20 54 68 ra parameter. Th
6560: 65 0a 20 20 20 66 69 65 6c 64 73 20 6e 65 78 74 e. fields next
6570: 5f 69 6e 2c 20 61 76 61 69 6c 5f 69 6e 2c 20 7a _in, avail_in, z
6580: 61 6c 6c 6f 63 2c 20 7a 66 72 65 65 20 61 6e 64 alloc, zfree and
6590: 20 6f 70 61 71 75 65 20 6d 75 73 74 20 62 65 20 opaque must be
65a0: 69 6e 69 74 69 61 6c 69 7a 65 64 0a 20 20 20 62 initialized. b
65b0: 65 66 6f 72 65 20 62 79 20 74 68 65 20 63 61 6c efore by the cal
65c0: 6c 65 72 2e 0a 0a 20 20 20 20 20 54 68 65 20 77 ler... The w
65d0: 69 6e 64 6f 77 42 69 74 73 20 70 61 72 61 6d 65 indowBits parame
65e0: 74 65 72 20 69 73 20 74 68 65 20 62 61 73 65 20 ter is the base
65f0: 74 77 6f 20 6c 6f 67 61 72 69 74 68 6d 20 6f 66 two logarithm of
6600: 20 74 68 65 20 6d 61 78 69 6d 75 6d 20 77 69 6e the maximum win
6610: 64 6f 77 0a 20 20 20 73 69 7a 65 20 28 74 68 65 dow. size (the
6620: 20 73 69 7a 65 20 6f 66 20 74 68 65 20 68 69 73 size of the his
6630: 74 6f 72 79 20 62 75 66 66 65 72 29 2e 20 20 49 tory buffer). I
6640: 74 20 73 68 6f 75 6c 64 20 62 65 20 69 6e 20 74 t should be in t
6650: 68 65 20 72 61 6e 67 65 20 38 2e 2e 31 35 20 66 he range 8..15 f
6660: 6f 72 0a 20 20 20 74 68 69 73 20 76 65 72 73 69 or. this versi
6670: 6f 6e 20 6f 66 20 74 68 65 20 6c 69 62 72 61 72 on of the librar
6680: 79 2e 20 54 68 65 20 64 65 66 61 75 6c 74 20 76 y. The default v
6690: 61 6c 75 65 20 69 73 20 31 35 20 69 66 20 69 6e alue is 15 if in
66a0: 66 6c 61 74 65 49 6e 69 74 20 69 73 20 75 73 65 flateInit is use
66b0: 64 0a 20 20 20 69 6e 73 74 65 61 64 2e 20 49 66 d. instead. If
66c0: 20 61 20 63 6f 6d 70 72 65 73 73 65 64 20 73 74 a compressed st
66d0: 72 65 61 6d 20 77 69 74 68 20 61 20 6c 61 72 67 ream with a larg
66e0: 65 72 20 77 69 6e 64 6f 77 20 73 69 7a 65 20 69 er window size i
66f0: 73 20 67 69 76 65 6e 20 61 73 0a 20 20 20 69 6e s given as. in
6700: 70 75 74 2c 20 69 6e 66 6c 61 74 65 28 29 20 77 put, inflate() w
6710: 69 6c 6c 20 72 65 74 75 72 6e 20 77 69 74 68 20 ill return with
6720: 74 68 65 20 65 72 72 6f 72 20 63 6f 64 65 20 5a the error code Z
6730: 5f 44 41 54 41 5f 45 52 52 4f 52 20 69 6e 73 74 _DATA_ERROR inst
6740: 65 61 64 20 6f 66 0a 20 20 20 74 72 79 69 6e 67 ead of. trying
6750: 20 74 6f 20 61 6c 6c 6f 63 61 74 65 20 61 20 6c to allocate a l
6760: 61 72 67 65 72 20 77 69 6e 64 6f 77 2e 0a 0a 20 arger window...
6770: 20 20 20 20 20 69 6e 66 6c 61 74 65 49 6e 69 74 inflateInit
6780: 32 20 72 65 74 75 72 6e 73 20 5a 5f 4f 4b 20 69 2 returns Z_OK i
6790: 66 20 73 75 63 63 65 73 73 2c 20 5a 5f 4d 45 4d f success, Z_MEM
67a0: 5f 45 52 52 4f 52 20 69 66 20 74 68 65 72 65 20 _ERROR if there
67b0: 77 61 73 20 6e 6f 74 20 65 6e 6f 75 67 68 0a 20 was not enough.
67c0: 20 20 6d 65 6d 6f 72 79 2c 20 5a 5f 53 54 52 45 memory, Z_STRE
67d0: 41 4d 5f 45 52 52 4f 52 20 69 66 20 61 20 70 61 AM_ERROR if a pa
67e0: 72 61 6d 65 74 65 72 20 69 73 20 69 6e 76 61 6c rameter is inval
67f0: 69 64 20 28 73 75 63 68 20 61 73 20 61 20 6e 65 id (such as a ne
6800: 67 61 74 69 76 65 0a 20 20 20 6d 65 6d 4c 65 76 gative. memLev
6810: 65 6c 29 2e 20 6d 73 67 20 69 73 20 73 65 74 20 el). msg is set
6820: 74 6f 20 6e 75 6c 6c 20 69 66 20 74 68 65 72 65 to null if there
6830: 20 69 73 20 6e 6f 20 65 72 72 6f 72 20 6d 65 73 is no error mes
6840: 73 61 67 65 2e 20 20 69 6e 66 6c 61 74 65 49 6e sage. inflateIn
6850: 69 74 32 0a 20 20 20 64 6f 65 73 20 6e 6f 74 20 it2. does not
6860: 70 65 72 66 6f 72 6d 20 61 6e 79 20 64 65 63 6f perform any deco
6870: 6d 70 72 65 73 73 69 6f 6e 20 61 70 61 72 74 20 mpression apart
6880: 66 72 6f 6d 20 72 65 61 64 69 6e 67 20 74 68 65 from reading the
6890: 20 7a 6c 69 62 20 68 65 61 64 65 72 20 69 66 0a zlib header if.
68a0: 20 20 20 70 72 65 73 65 6e 74 3a 20 74 68 69 73 present: this
68b0: 20 77 69 6c 6c 20 62 65 20 64 6f 6e 65 20 62 79 will be done by
68c0: 20 69 6e 66 6c 61 74 65 28 29 2e 20 28 53 6f 20 inflate(). (So
68d0: 6e 65 78 74 5f 69 6e 20 61 6e 64 20 61 76 61 69 next_in and avai
68e0: 6c 5f 69 6e 20 6d 61 79 20 62 65 0a 20 20 20 6d l_in may be. m
68f0: 6f 64 69 66 69 65 64 2c 20 62 75 74 20 6e 65 78 odified, but nex
6900: 74 5f 6f 75 74 20 61 6e 64 20 61 76 61 69 6c 5f t_out and avail_
6910: 6f 75 74 20 61 72 65 20 75 6e 63 68 61 6e 67 65 out are unchange
6920: 64 2e 29 0a 2a 2f 0a 0a 5a 45 58 54 45 52 4e 20 d.).*/..ZEXTERN
6930: 69 6e 74 20 5a 45 58 50 4f 52 54 20 69 6e 66 6c int ZEXPORT infl
6940: 61 74 65 53 65 74 44 69 63 74 69 6f 6e 61 72 79 ateSetDictionary
6950: 20 4f 46 28 28 7a 5f 73 74 72 65 61 6d 70 20 73 OF((z_streamp s
6960: 74 72 6d 2c 0a 20 20 20 20 20 20 20 20 20 20 20 trm,.
6970: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
6980: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
6990: 20 20 63 6f 6e 73 74 20 42 79 74 65 66 20 2a 64 const Bytef *d
69a0: 69 63 74 69 6f 6e 61 72 79 2c 0a 20 20 20 20 20 ictionary,.
69b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
69c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
69d0: 20 20 20 20 20 20 20 20 75 49 6e 74 20 20 64 69 uInt di
69e0: 63 74 4c 65 6e 67 74 68 29 29 3b 0a 2f 2a 0a 20 ctLength));./*.
69f0: 20 20 20 20 49 6e 69 74 69 61 6c 69 7a 65 73 20 Initializes
6a00: 74 68 65 20 64 65 63 6f 6d 70 72 65 73 73 69 6f the decompressio
6a10: 6e 20 64 69 63 74 69 6f 6e 61 72 79 20 66 72 6f n dictionary fro
6a20: 6d 20 74 68 65 20 67 69 76 65 6e 20 75 6e 63 6f m the given unco
6a30: 6d 70 72 65 73 73 65 64 20 62 79 74 65 0a 20 20 mpressed byte.
6a40: 20 73 65 71 75 65 6e 63 65 2e 20 54 68 69 73 20 sequence. This
6a50: 66 75 6e 63 74 69 6f 6e 20 6d 75 73 74 20 62 65 function must be
6a60: 20 63 61 6c 6c 65 64 20 69 6d 6d 65 64 69 61 74 called immediat
6a70: 65 6c 79 20 61 66 74 65 72 20 61 20 63 61 6c 6c ely after a call
6a80: 20 6f 66 20 69 6e 66 6c 61 74 65 0a 20 20 20 69 of inflate. i
6a90: 66 20 74 68 69 73 20 63 61 6c 6c 20 72 65 74 75 f this call retu
6aa0: 72 6e 65 64 20 5a 5f 4e 45 45 44 5f 44 49 43 54 rned Z_NEED_DICT
6ab0: 2e 20 54 68 65 20 64 69 63 74 69 6f 6e 61 72 79 . The dictionary
6ac0: 20 63 68 6f 73 65 6e 20 62 79 20 74 68 65 20 63 chosen by the c
6ad0: 6f 6d 70 72 65 73 73 6f 72 0a 20 20 20 63 61 6e ompressor. can
6ae0: 20 62 65 20 64 65 74 65 72 6d 69 6e 65 64 20 66 be determined f
6af0: 72 6f 6d 20 74 68 65 20 41 64 6c 65 72 33 32 20 rom the Adler32
6b00: 76 61 6c 75 65 20 72 65 74 75 72 6e 65 64 20 62 value returned b
6b10: 79 20 74 68 69 73 20 63 61 6c 6c 20 6f 66 0a 20 y this call of.
6b20: 20 20 69 6e 66 6c 61 74 65 2e 20 54 68 65 20 63 inflate. The c
6b30: 6f 6d 70 72 65 73 73 6f 72 20 61 6e 64 20 64 65 ompressor and de
6b40: 63 6f 6d 70 72 65 73 73 6f 72 20 6d 75 73 74 20 compressor must
6b50: 75 73 65 20 65 78 61 63 74 6c 79 20 74 68 65 20 use exactly the
6b60: 73 61 6d 65 0a 20 20 20 64 69 63 74 69 6f 6e 61 same. dictiona
6b70: 72 79 20 28 73 65 65 20 64 65 66 6c 61 74 65 53 ry (see deflateS
6b80: 65 74 44 69 63 74 69 6f 6e 61 72 79 29 2e 0a 0a etDictionary)...
6b90: 20 20 20 20 20 69 6e 66 6c 61 74 65 53 65 74 44 inflateSetD
6ba0: 69 63 74 69 6f 6e 61 72 79 20 72 65 74 75 72 6e ictionary return
6bb0: 73 20 5a 5f 4f 4b 20 69 66 20 73 75 63 63 65 73 s Z_OK if succes
6bc0: 73 2c 20 5a 5f 53 54 52 45 41 4d 5f 45 52 52 4f s, Z_STREAM_ERRO
6bd0: 52 20 69 66 20 61 0a 20 20 20 70 61 72 61 6d 65 R if a. parame
6be0: 74 65 72 20 69 73 20 69 6e 76 61 6c 69 64 20 28 ter is invalid (
6bf0: 73 75 63 68 20 61 73 20 4e 55 4c 4c 20 64 69 63 such as NULL dic
6c00: 74 69 6f 6e 61 72 79 29 20 6f 72 20 74 68 65 20 tionary) or the
6c10: 73 74 72 65 61 6d 20 73 74 61 74 65 20 69 73 0a stream state is.
6c20: 20 20 20 69 6e 63 6f 6e 73 69 73 74 65 6e 74 2c inconsistent,
6c30: 20 5a 5f 44 41 54 41 5f 45 52 52 4f 52 20 69 66 Z_DATA_ERROR if
6c40: 20 74 68 65 20 67 69 76 65 6e 20 64 69 63 74 69 the given dicti
6c50: 6f 6e 61 72 79 20 64 6f 65 73 6e 27 74 20 6d 61 onary doesn't ma
6c60: 74 63 68 20 74 68 65 0a 20 20 20 65 78 70 65 63 tch the. expec
6c70: 74 65 64 20 6f 6e 65 20 28 69 6e 63 6f 72 72 65 ted one (incorre
6c80: 63 74 20 41 64 6c 65 72 33 32 20 76 61 6c 75 65 ct Adler32 value
6c90: 29 2e 20 69 6e 66 6c 61 74 65 53 65 74 44 69 63 ). inflateSetDic
6ca0: 74 69 6f 6e 61 72 79 20 64 6f 65 73 20 6e 6f 74 tionary does not
6cb0: 0a 20 20 20 70 65 72 66 6f 72 6d 20 61 6e 79 20 . perform any
6cc0: 64 65 63 6f 6d 70 72 65 73 73 69 6f 6e 3a 20 74 decompression: t
6cd0: 68 69 73 20 77 69 6c 6c 20 62 65 20 64 6f 6e 65 his will be done
6ce0: 20 62 79 20 73 75 62 73 65 71 75 65 6e 74 20 63 by subsequent c
6cf0: 61 6c 6c 73 20 6f 66 0a 20 20 20 69 6e 66 6c 61 alls of. infla
6d00: 74 65 28 29 2e 0a 2a 2f 0a 0a 5a 45 58 54 45 52 te()..*/..ZEXTER
6d10: 4e 20 69 6e 74 20 5a 45 58 50 4f 52 54 20 69 6e N int ZEXPORT in
6d20: 66 6c 61 74 65 53 79 6e 63 20 4f 46 28 28 7a 5f flateSync OF((z_
6d30: 73 74 72 65 61 6d 70 20 73 74 72 6d 29 29 3b 0a streamp strm));.
6d40: 2f 2a 20 0a 20 20 20 20 53 6b 69 70 73 20 69 6e /* . Skips in
6d50: 76 61 6c 69 64 20 63 6f 6d 70 72 65 73 73 65 64 valid compressed
6d60: 20 64 61 74 61 20 75 6e 74 69 6c 20 61 20 66 75 data until a fu
6d70: 6c 6c 20 66 6c 75 73 68 20 70 6f 69 6e 74 20 28 ll flush point (
6d80: 73 65 65 20 61 62 6f 76 65 20 74 68 65 0a 20 20 see above the.
6d90: 64 65 73 63 72 69 70 74 69 6f 6e 20 6f 66 20 64 description of d
6da0: 65 66 6c 61 74 65 20 77 69 74 68 20 5a 5f 46 55 eflate with Z_FU
6db0: 4c 4c 5f 46 4c 55 53 48 29 20 63 61 6e 20 62 65 LL_FLUSH) can be
6dc0: 20 66 6f 75 6e 64 2c 20 6f 72 20 75 6e 74 69 6c found, or until
6dd0: 20 61 6c 6c 0a 20 20 61 76 61 69 6c 61 62 6c 65 all. available
6de0: 20 69 6e 70 75 74 20 69 73 20 73 6b 69 70 70 65 input is skippe
6df0: 64 2e 20 4e 6f 20 6f 75 74 70 75 74 20 69 73 20 d. No output is
6e00: 70 72 6f 76 69 64 65 64 2e 0a 0a 20 20 20 20 69 provided... i
6e10: 6e 66 6c 61 74 65 53 79 6e 63 20 72 65 74 75 72 nflateSync retur
6e20: 6e 73 20 5a 5f 4f 4b 20 69 66 20 61 20 66 75 6c ns Z_OK if a ful
6e30: 6c 20 66 6c 75 73 68 20 70 6f 69 6e 74 20 68 61 l flush point ha
6e40: 73 20 62 65 65 6e 20 66 6f 75 6e 64 2c 20 5a 5f s been found, Z_
6e50: 42 55 46 5f 45 52 52 4f 52 0a 20 20 69 66 20 6e BUF_ERROR. if n
6e60: 6f 20 6d 6f 72 65 20 69 6e 70 75 74 20 77 61 73 o more input was
6e70: 20 70 72 6f 76 69 64 65 64 2c 20 5a 5f 44 41 54 provided, Z_DAT
6e80: 41 5f 45 52 52 4f 52 20 69 66 20 6e 6f 20 66 6c A_ERROR if no fl
6e90: 75 73 68 20 70 6f 69 6e 74 20 68 61 73 20 62 65 ush point has be
6ea0: 65 6e 20 66 6f 75 6e 64 2c 0a 20 20 6f 72 20 5a en found,. or Z
6eb0: 5f 53 54 52 45 41 4d 5f 45 52 52 4f 52 20 69 66 _STREAM_ERROR if
6ec0: 20 74 68 65 20 73 74 72 65 61 6d 20 73 74 72 75 the stream stru
6ed0: 63 74 75 72 65 20 77 61 73 20 69 6e 63 6f 6e 73 cture was incons
6ee0: 69 73 74 65 6e 74 2e 20 49 6e 20 74 68 65 20 73 istent. In the s
6ef0: 75 63 63 65 73 73 0a 20 20 63 61 73 65 2c 20 74 uccess. case, t
6f00: 68 65 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 6d he application m
6f10: 61 79 20 73 61 76 65 20 74 68 65 20 63 75 72 72 ay save the curr
6f20: 65 6e 74 20 63 75 72 72 65 6e 74 20 76 61 6c 75 ent current valu
6f30: 65 20 6f 66 20 74 6f 74 61 6c 5f 69 6e 20 77 68 e of total_in wh
6f40: 69 63 68 0a 20 20 69 6e 64 69 63 61 74 65 73 20 ich. indicates
6f50: 77 68 65 72 65 20 76 61 6c 69 64 20 63 6f 6d 70 where valid comp
6f60: 72 65 73 73 65 64 20 64 61 74 61 20 77 61 73 20 ressed data was
6f70: 66 6f 75 6e 64 2e 20 49 6e 20 74 68 65 20 65 72 found. In the er
6f80: 72 6f 72 20 63 61 73 65 2c 20 74 68 65 0a 20 20 ror case, the.
6f90: 61 70 70 6c 69 63 61 74 69 6f 6e 20 6d 61 79 20 application may
6fa0: 72 65 70 65 61 74 65 64 6c 79 20 63 61 6c 6c 20 repeatedly call
6fb0: 69 6e 66 6c 61 74 65 53 79 6e 63 2c 20 70 72 6f inflateSync, pro
6fc0: 76 69 64 69 6e 67 20 6d 6f 72 65 20 69 6e 70 75 viding more inpu
6fd0: 74 20 65 61 63 68 20 74 69 6d 65 2c 0a 20 20 75 t each time,. u
6fe0: 6e 74 69 6c 20 73 75 63 63 65 73 73 20 6f 72 20 ntil success or
6ff0: 65 6e 64 20 6f 66 20 74 68 65 20 69 6e 70 75 74 end of the input
7000: 20 64 61 74 61 2e 0a 2a 2f 0a 0a 5a 45 58 54 45 data..*/..ZEXTE
7010: 52 4e 20 69 6e 74 20 5a 45 58 50 4f 52 54 20 69 RN int ZEXPORT i
7020: 6e 66 6c 61 74 65 52 65 73 65 74 20 4f 46 28 28 nflateReset OF((
7030: 7a 5f 73 74 72 65 61 6d 70 20 73 74 72 6d 29 29 z_streamp strm))
7040: 3b 0a 2f 2a 0a 20 20 20 20 20 54 68 69 73 20 66 ;./*. This f
7050: 75 6e 63 74 69 6f 6e 20 69 73 20 65 71 75 69 76 unction is equiv
7060: 61 6c 65 6e 74 20 74 6f 20 69 6e 66 6c 61 74 65 alent to inflate
7070: 45 6e 64 20 66 6f 6c 6c 6f 77 65 64 20 62 79 20 End followed by
7080: 69 6e 66 6c 61 74 65 49 6e 69 74 2c 0a 20 20 20 inflateInit,.
7090: 62 75 74 20 64 6f 65 73 20 6e 6f 74 20 66 72 65 but does not fre
70a0: 65 20 61 6e 64 20 72 65 61 6c 6c 6f 63 61 74 65 e and reallocate
70b0: 20 61 6c 6c 20 74 68 65 20 69 6e 74 65 72 6e 61 all the interna
70c0: 6c 20 64 65 63 6f 6d 70 72 65 73 73 69 6f 6e 20 l decompression
70d0: 73 74 61 74 65 2e 0a 20 20 20 54 68 65 20 73 74 state.. The st
70e0: 72 65 61 6d 20 77 69 6c 6c 20 6b 65 65 70 20 61 ream will keep a
70f0: 74 74 72 69 62 75 74 65 73 20 74 68 61 74 20 6d ttributes that m
7100: 61 79 20 68 61 76 65 20 62 65 65 6e 20 73 65 74 ay have been set
7110: 20 62 79 20 69 6e 66 6c 61 74 65 49 6e 69 74 32 by inflateInit2
7120: 2e 0a 0a 20 20 20 20 20 20 69 6e 66 6c 61 74 65 ... inflate
7130: 52 65 73 65 74 20 72 65 74 75 72 6e 73 20 5a 5f Reset returns Z_
7140: 4f 4b 20 69 66 20 73 75 63 63 65 73 73 2c 20 6f OK if success, o
7150: 72 20 5a 5f 53 54 52 45 41 4d 5f 45 52 52 4f 52 r Z_STREAM_ERROR
7160: 20 69 66 20 74 68 65 20 73 6f 75 72 63 65 0a 20 if the source.
7170: 20 20 73 74 72 65 61 6d 20 73 74 61 74 65 20 77 stream state w
7180: 61 73 20 69 6e 63 6f 6e 73 69 73 74 65 6e 74 20 as inconsistent
7190: 28 73 75 63 68 20 61 73 20 7a 61 6c 6c 6f 63 20 (such as zalloc
71a0: 6f 72 20 73 74 61 74 65 20 62 65 69 6e 67 20 4e or state being N
71b0: 55 4c 4c 29 2e 0a 2a 2f 0a 0a 0a 20 20 20 20 20 ULL)..*/...
71c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
71d0: 20 20 20 2f 2a 20 75 74 69 6c 69 74 79 20 66 75 /* utility fu
71e0: 6e 63 74 69 6f 6e 73 20 2a 2f 0a 0a 2f 2a 0a 20 nctions */../*.
71f0: 20 20 20 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e The followin
7200: 67 20 75 74 69 6c 69 74 79 20 66 75 6e 63 74 69 g utility functi
7210: 6f 6e 73 20 61 72 65 20 69 6d 70 6c 65 6d 65 6e ons are implemen
7220: 74 65 64 20 6f 6e 20 74 6f 70 20 6f 66 20 74 68 ted on top of th
7230: 65 0a 20 20 20 62 61 73 69 63 20 73 74 72 65 61 e. basic strea
7240: 6d 2d 6f 72 69 65 6e 74 65 64 20 66 75 6e 63 74 m-oriented funct
7250: 69 6f 6e 73 2e 20 54 6f 20 73 69 6d 70 6c 69 66 ions. To simplif
7260: 79 20 74 68 65 20 69 6e 74 65 72 66 61 63 65 2c y the interface,
7270: 20 73 6f 6d 65 0a 20 20 20 64 65 66 61 75 6c 74 some. default
7280: 20 6f 70 74 69 6f 6e 73 20 61 72 65 20 61 73 73 options are ass
7290: 75 6d 65 64 20 28 63 6f 6d 70 72 65 73 73 69 6f umed (compressio
72a0: 6e 20 6c 65 76 65 6c 20 61 6e 64 20 6d 65 6d 6f n level and memo
72b0: 72 79 20 75 73 61 67 65 2c 0a 20 20 20 73 74 61 ry usage,. sta
72c0: 6e 64 61 72 64 20 6d 65 6d 6f 72 79 20 61 6c 6c ndard memory all
72d0: 6f 63 61 74 69 6f 6e 20 66 75 6e 63 74 69 6f 6e ocation function
72e0: 73 29 2e 20 54 68 65 20 73 6f 75 72 63 65 20 63 s). The source c
72f0: 6f 64 65 20 6f 66 20 74 68 65 73 65 0a 20 20 20 ode of these.
7300: 75 74 69 6c 69 74 79 20 66 75 6e 63 74 69 6f 6e utility function
7310: 73 20 63 61 6e 20 65 61 73 69 6c 79 20 62 65 20 s can easily be
7320: 6d 6f 64 69 66 69 65 64 20 69 66 20 79 6f 75 20 modified if you
7330: 6e 65 65 64 20 73 70 65 63 69 61 6c 20 6f 70 74 need special opt
7340: 69 6f 6e 73 2e 0a 2a 2f 0a 0a 23 69 66 6e 64 65 ions..*/..#ifnde
7350: 66 20 4b 49 5f 47 5a 5f 4e 4f 5f 43 4f 4d 50 52 f KI_GZ_NO_COMPR
7360: 45 53 53 49 4f 4e 0d 0a 0d 0a 5a 45 58 54 45 52 ESSION....ZEXTER
7370: 4e 20 69 6e 74 20 5a 45 58 50 4f 52 54 20 63 6f N int ZEXPORT co
7380: 6d 70 72 65 73 73 20 4f 46 28 28 42 79 74 65 66 mpress OF((Bytef
7390: 20 2a 64 65 73 74 2c 20 20 20 75 4c 6f 6e 67 66 *dest, uLongf
73a0: 20 2a 64 65 73 74 4c 65 6e 2c 0a 20 20 20 20 20 *destLen,.
73b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
73c0: 20 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e 73 cons
73d0: 74 20 42 79 74 65 66 20 2a 73 6f 75 72 63 65 2c t Bytef *source,
73e0: 20 75 4c 6f 6e 67 20 73 6f 75 72 63 65 4c 65 6e uLong sourceLen
73f0: 29 29 3b 0a 2f 2a 0a 20 20 20 20 20 43 6f 6d 70 ));./*. Comp
7400: 72 65 73 73 65 73 20 74 68 65 20 73 6f 75 72 63 resses the sourc
7410: 65 20 62 75 66 66 65 72 20 69 6e 74 6f 20 74 68 e buffer into th
7420: 65 20 64 65 73 74 69 6e 61 74 69 6f 6e 20 62 75 e destination bu
7430: 66 66 65 72 2e 20 20 73 6f 75 72 63 65 4c 65 6e ffer. sourceLen
7440: 20 69 73 0a 20 20 20 74 68 65 20 62 79 74 65 20 is. the byte
7450: 6c 65 6e 67 74 68 20 6f 66 20 74 68 65 20 73 6f length of the so
7460: 75 72 63 65 20 62 75 66 66 65 72 2e 20 55 70 6f urce buffer. Upo
7470: 6e 20 65 6e 74 72 79 2c 20 64 65 73 74 4c 65 6e n entry, destLen
7480: 20 69 73 20 74 68 65 20 74 6f 74 61 6c 0a 20 20 is the total.
7490: 20 73 69 7a 65 20 6f 66 20 74 68 65 20 64 65 73 size of the des
74a0: 74 69 6e 61 74 69 6f 6e 20 62 75 66 66 65 72 2c tination buffer,
74b0: 20 77 68 69 63 68 20 6d 75 73 74 20 62 65 20 61 which must be a
74c0: 74 20 6c 65 61 73 74 20 30 2e 31 25 20 6c 61 72 t least 0.1% lar
74d0: 67 65 72 20 74 68 61 6e 0a 20 20 20 73 6f 75 72 ger than. sour
74e0: 63 65 4c 65 6e 20 70 6c 75 73 20 31 32 20 62 79 ceLen plus 12 by
74f0: 74 65 73 2e 20 55 70 6f 6e 20 65 78 69 74 2c 20 tes. Upon exit,
7500: 64 65 73 74 4c 65 6e 20 69 73 20 74 68 65 20 61 destLen is the a
7510: 63 74 75 61 6c 20 73 69 7a 65 20 6f 66 20 74 68 ctual size of th
7520: 65 0a 20 20 20 63 6f 6d 70 72 65 73 73 65 64 20 e. compressed
7530: 62 75 66 66 65 72 2e 0a 20 20 20 20 20 54 68 69 buffer.. Thi
7540: 73 20 66 75 6e 63 74 69 6f 6e 20 63 61 6e 20 62 s function can b
7550: 65 20 75 73 65 64 20 74 6f 20 63 6f 6d 70 72 65 e used to compre
7560: 73 73 20 61 20 77 68 6f 6c 65 20 66 69 6c 65 20 ss a whole file
7570: 61 74 20 6f 6e 63 65 20 69 66 20 74 68 65 0a 20 at once if the.
7580: 20 20 69 6e 70 75 74 20 66 69 6c 65 20 69 73 20 input file is
7590: 6d 6d 61 70 27 65 64 2e 0a 20 20 20 20 20 63 6f mmap'ed.. co
75a0: 6d 70 72 65 73 73 20 72 65 74 75 72 6e 73 20 5a mpress returns Z
75b0: 5f 4f 4b 20 69 66 20 73 75 63 63 65 73 73 2c 20 _OK if success,
75c0: 5a 5f 4d 45 4d 5f 45 52 52 4f 52 20 69 66 20 74 Z_MEM_ERROR if t
75d0: 68 65 72 65 20 77 61 73 20 6e 6f 74 0a 20 20 20 here was not.
75e0: 65 6e 6f 75 67 68 20 6d 65 6d 6f 72 79 2c 20 5a enough memory, Z
75f0: 5f 42 55 46 5f 45 52 52 4f 52 20 69 66 20 74 68 _BUF_ERROR if th
7600: 65 72 65 20 77 61 73 20 6e 6f 74 20 65 6e 6f 75 ere was not enou
7610: 67 68 20 72 6f 6f 6d 20 69 6e 20 74 68 65 20 6f gh room in the o
7620: 75 74 70 75 74 0a 20 20 20 62 75 66 66 65 72 2e utput. buffer.
7630: 0a 2a 2f 0a 0a 5a 45 58 54 45 52 4e 20 69 6e 74 .*/..ZEXTERN int
7640: 20 5a 45 58 50 4f 52 54 20 63 6f 6d 70 72 65 73 ZEXPORT compres
7650: 73 32 20 4f 46 28 28 42 79 74 65 66 20 2a 64 65 s2 OF((Bytef *de
7660: 73 74 2c 20 20 20 75 4c 6f 6e 67 66 20 2a 64 65 st, uLongf *de
7670: 73 74 4c 65 6e 2c 0a 20 20 20 20 20 20 20 20 20 stLen,.
7680: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
7690: 20 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 42 const B
76a0: 79 74 65 66 20 2a 73 6f 75 72 63 65 2c 20 75 4c ytef *source, uL
76b0: 6f 6e 67 20 73 6f 75 72 63 65 4c 65 6e 2c 0a 20 ong sourceLen,.
76c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
76d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
76e0: 20 69 6e 74 20 6c 65 76 65 6c 29 29 3b 0a 2f 2a int level));./*
76f0: 0a 20 20 20 20 20 43 6f 6d 70 72 65 73 73 65 73 . Compresses
7700: 20 74 68 65 20 73 6f 75 72 63 65 20 62 75 66 66 the source buff
7710: 65 72 20 69 6e 74 6f 20 74 68 65 20 64 65 73 74 er into the dest
7720: 69 6e 61 74 69 6f 6e 20 62 75 66 66 65 72 2e 20 ination buffer.
7730: 54 68 65 20 6c 65 76 65 6c 0a 20 20 20 70 61 72 The level. par
7740: 61 6d 65 74 65 72 20 68 61 73 20 74 68 65 20 73 ameter has the s
7750: 61 6d 65 20 6d 65 61 6e 69 6e 67 20 61 73 20 69 ame meaning as i
7760: 6e 20 64 65 66 6c 61 74 65 49 6e 69 74 2e 20 20 n deflateInit.
7770: 73 6f 75 72 63 65 4c 65 6e 20 69 73 20 74 68 65 sourceLen is the
7780: 20 62 79 74 65 0a 20 20 20 6c 65 6e 67 74 68 20 byte. length
7790: 6f 66 20 74 68 65 20 73 6f 75 72 63 65 20 62 75 of the source bu
77a0: 66 66 65 72 2e 20 55 70 6f 6e 20 65 6e 74 72 79 ffer. Upon entry
77b0: 2c 20 64 65 73 74 4c 65 6e 20 69 73 20 74 68 65 , destLen is the
77c0: 20 74 6f 74 61 6c 20 73 69 7a 65 20 6f 66 20 74 total size of t
77d0: 68 65 0a 20 20 20 64 65 73 74 69 6e 61 74 69 6f he. destinatio
77e0: 6e 20 62 75 66 66 65 72 2c 20 77 68 69 63 68 20 n buffer, which
77f0: 6d 75 73 74 20 62 65 20 61 74 20 6c 65 61 73 74 must be at least
7800: 20 30 2e 31 25 20 6c 61 72 67 65 72 20 74 68 61 0.1% larger tha
7810: 6e 20 73 6f 75 72 63 65 4c 65 6e 20 70 6c 75 73 n sourceLen plus
7820: 0a 20 20 20 31 32 20 62 79 74 65 73 2e 20 55 70 . 12 bytes. Up
7830: 6f 6e 20 65 78 69 74 2c 20 64 65 73 74 4c 65 6e on exit, destLen
7840: 20 69 73 20 74 68 65 20 61 63 74 75 61 6c 20 73 is the actual s
7850: 69 7a 65 20 6f 66 20 74 68 65 20 63 6f 6d 70 72 ize of the compr
7860: 65 73 73 65 64 20 62 75 66 66 65 72 2e 0a 0a 20 essed buffer...
7870: 20 20 20 20 63 6f 6d 70 72 65 73 73 32 20 72 65 compress2 re
7880: 74 75 72 6e 73 20 5a 5f 4f 4b 20 69 66 20 73 75 turns Z_OK if su
7890: 63 63 65 73 73 2c 20 5a 5f 4d 45 4d 5f 45 52 52 ccess, Z_MEM_ERR
78a0: 4f 52 20 69 66 20 74 68 65 72 65 20 77 61 73 20 OR if there was
78b0: 6e 6f 74 20 65 6e 6f 75 67 68 0a 20 20 20 6d 65 not enough. me
78c0: 6d 6f 72 79 2c 20 5a 5f 42 55 46 5f 45 52 52 4f mory, Z_BUF_ERRO
78d0: 52 20 69 66 20 74 68 65 72 65 20 77 61 73 20 6e R if there was n
78e0: 6f 74 20 65 6e 6f 75 67 68 20 72 6f 6f 6d 20 69 ot enough room i
78f0: 6e 20 74 68 65 20 6f 75 74 70 75 74 20 62 75 66 n the output buf
7900: 66 65 72 2c 0a 20 20 20 5a 5f 53 54 52 45 41 4d fer,. Z_STREAM
7910: 5f 45 52 52 4f 52 20 69 66 20 74 68 65 20 6c 65 _ERROR if the le
7920: 76 65 6c 20 70 61 72 61 6d 65 74 65 72 20 69 73 vel parameter is
7930: 20 69 6e 76 61 6c 69 64 2e 0a 2a 2f 0a 0d 0a 23 invalid..*/...#
7940: 65 6e 64 69 66 20 2f 2a 20 4b 49 5f 47 5a 5f 4e endif /* KI_GZ_N
7950: 4f 5f 43 4f 4d 50 52 45 53 53 49 4f 4e 20 2a 2f O_COMPRESSION */
7960: 0d 0a 0a 5a 45 58 54 45 52 4e 20 69 6e 74 20 5a ...ZEXTERN int Z
7970: 45 58 50 4f 52 54 20 75 6e 63 6f 6d 70 72 65 73 EXPORT uncompres
7980: 73 20 4f 46 28 28 42 79 74 65 66 20 2a 64 65 73 s OF((Bytef *des
7990: 74 2c 20 20 20 75 4c 6f 6e 67 66 20 2a 64 65 73 t, uLongf *des
79a0: 74 4c 65 6e 2c 0a 20 20 20 20 20 20 20 20 20 20 tLen,.
79b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
79c0: 20 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 42 const B
79d0: 79 74 65 66 20 2a 73 6f 75 72 63 65 2c 20 75 4c ytef *source, uL
79e0: 6f 6e 67 20 73 6f 75 72 63 65 4c 65 6e 29 29 3b ong sourceLen));
79f0: 0a 2f 2a 0a 20 20 20 20 20 44 65 63 6f 6d 70 72 ./*. Decompr
7a00: 65 73 73 65 73 20 74 68 65 20 73 6f 75 72 63 65 esses the source
7a10: 20 62 75 66 66 65 72 20 69 6e 74 6f 20 74 68 65 buffer into the
7a20: 20 64 65 73 74 69 6e 61 74 69 6f 6e 20 62 75 66 destination buf
7a30: 66 65 72 2e 20 20 73 6f 75 72 63 65 4c 65 6e 20 fer. sourceLen
7a40: 69 73 0a 20 20 20 74 68 65 20 62 79 74 65 20 6c is. the byte l
7a50: 65 6e 67 74 68 20 6f 66 20 74 68 65 20 73 6f 75 ength of the sou
7a60: 72 63 65 20 62 75 66 66 65 72 2e 20 55 70 6f 6e rce buffer. Upon
7a70: 20 65 6e 74 72 79 2c 20 64 65 73 74 4c 65 6e 20 entry, destLen
7a80: 69 73 20 74 68 65 20 74 6f 74 61 6c 0a 20 20 20 is the total.
7a90: 73 69 7a 65 20 6f 66 20 74 68 65 20 64 65 73 74 size of the dest
7aa0: 69 6e 61 74 69 6f 6e 20 62 75 66 66 65 72 2c 20 ination buffer,
7ab0: 77 68 69 63 68 20 6d 75 73 74 20 62 65 20 6c 61 which must be la
7ac0: 72 67 65 20 65 6e 6f 75 67 68 20 74 6f 20 68 6f rge enough to ho
7ad0: 6c 64 20 74 68 65 0a 20 20 20 65 6e 74 69 72 65 ld the. entire
7ae0: 20 75 6e 63 6f 6d 70 72 65 73 73 65 64 20 64 61 uncompressed da
7af0: 74 61 2e 20 28 54 68 65 20 73 69 7a 65 20 6f 66 ta. (The size of
7b00: 20 74 68 65 20 75 6e 63 6f 6d 70 72 65 73 73 65 the uncompresse
7b10: 64 20 64 61 74 61 20 6d 75 73 74 20 68 61 76 65 d data must have
7b20: 0a 20 20 20 62 65 65 6e 20 73 61 76 65 64 20 70 . been saved p
7b30: 72 65 76 69 6f 75 73 6c 79 20 62 79 20 74 68 65 reviously by the
7b40: 20 63 6f 6d 70 72 65 73 73 6f 72 20 61 6e 64 20 compressor and
7b50: 74 72 61 6e 73 6d 69 74 74 65 64 20 74 6f 20 74 transmitted to t
7b60: 68 65 20 64 65 63 6f 6d 70 72 65 73 73 6f 72 0a he decompressor.
7b70: 20 20 20 62 79 20 73 6f 6d 65 20 6d 65 63 68 61 by some mecha
7b80: 6e 69 73 6d 20 6f 75 74 73 69 64 65 20 74 68 65 nism outside the
7b90: 20 73 63 6f 70 65 20 6f 66 20 74 68 69 73 20 63 scope of this c
7ba0: 6f 6d 70 72 65 73 73 69 6f 6e 20 6c 69 62 72 61 ompression libra
7bb0: 72 79 2e 29 0a 20 20 20 55 70 6f 6e 20 65 78 69 ry.). Upon exi
7bc0: 74 2c 20 64 65 73 74 4c 65 6e 20 69 73 20 74 68 t, destLen is th
7bd0: 65 20 61 63 74 75 61 6c 20 73 69 7a 65 20 6f 66 e actual size of
7be0: 20 74 68 65 20 63 6f 6d 70 72 65 73 73 65 64 20 the compressed
7bf0: 62 75 66 66 65 72 2e 0a 20 20 20 20 20 54 68 69 buffer.. Thi
7c00: 73 20 66 75 6e 63 74 69 6f 6e 20 63 61 6e 20 62 s function can b
7c10: 65 20 75 73 65 64 20 74 6f 20 64 65 63 6f 6d 70 e used to decomp
7c20: 72 65 73 73 20 61 20 77 68 6f 6c 65 20 66 69 6c ress a whole fil
7c30: 65 20 61 74 20 6f 6e 63 65 20 69 66 20 74 68 65 e at once if the
7c40: 0a 20 20 20 69 6e 70 75 74 20 66 69 6c 65 20 69 . input file i
7c50: 73 20 6d 6d 61 70 27 65 64 2e 0a 0a 20 20 20 20 s mmap'ed...
7c60: 20 75 6e 63 6f 6d 70 72 65 73 73 20 72 65 74 75 uncompress retu
7c70: 72 6e 73 20 5a 5f 4f 4b 20 69 66 20 73 75 63 63 rns Z_OK if succ
7c80: 65 73 73 2c 20 5a 5f 4d 45 4d 5f 45 52 52 4f 52 ess, Z_MEM_ERROR
7c90: 20 69 66 20 74 68 65 72 65 20 77 61 73 20 6e 6f if there was no
7ca0: 74 0a 20 20 20 65 6e 6f 75 67 68 20 6d 65 6d 6f t. enough memo
7cb0: 72 79 2c 20 5a 5f 42 55 46 5f 45 52 52 4f 52 20 ry, Z_BUF_ERROR
7cc0: 69 66 20 74 68 65 72 65 20 77 61 73 20 6e 6f 74 if there was not
7cd0: 20 65 6e 6f 75 67 68 20 72 6f 6f 6d 20 69 6e 20 enough room in
7ce0: 74 68 65 20 6f 75 74 70 75 74 0a 20 20 20 62 75 the output. bu
7cf0: 66 66 65 72 2c 20 6f 72 20 5a 5f 44 41 54 41 5f ffer, or Z_DATA_
7d00: 45 52 52 4f 52 20 69 66 20 74 68 65 20 69 6e 70 ERROR if the inp
7d10: 75 74 20 64 61 74 61 20 77 61 73 20 63 6f 72 72 ut data was corr
7d20: 75 70 74 65 64 2e 0a 2a 2f 0a 0a 0a 74 79 70 65 upted..*/...type
7d30: 64 65 66 20 76 6f 69 64 70 20 67 7a 46 69 6c 65 def voidp gzFile
7d40: 3b 0a 0a 5a 45 58 54 45 52 4e 20 67 7a 46 69 6c ;..ZEXTERN gzFil
7d50: 65 20 5a 45 58 50 4f 52 54 20 67 7a 6f 70 65 6e e ZEXPORT gzopen
7d60: 20 20 4f 46 28 28 63 6f 6e 73 74 20 63 68 61 72 OF((const char
7d70: 20 2a 70 61 74 68 2c 20 63 6f 6e 73 74 20 63 68 *path, const ch
7d80: 61 72 20 2a 6d 6f 64 65 29 29 3b 0a 2f 2a 0a 20 ar *mode));./*.
7d90: 20 20 20 20 4f 70 65 6e 73 20 61 20 67 7a 69 70 Opens a gzip
7da0: 20 28 2e 67 7a 29 20 66 69 6c 65 20 66 6f 72 20 (.gz) file for
7db0: 72 65 61 64 69 6e 67 20 6f 72 20 77 72 69 74 69 reading or writi
7dc0: 6e 67 2e 20 54 68 65 20 6d 6f 64 65 20 70 61 72 ng. The mode par
7dd0: 61 6d 65 74 65 72 0a 20 20 20 69 73 20 61 73 20 ameter. is as
7de0: 69 6e 20 66 6f 70 65 6e 20 28 22 72 62 22 20 6f in fopen ("rb" o
7df0: 72 20 22 77 62 22 29 20 62 75 74 20 63 61 6e 20 r "wb") but can
7e00: 61 6c 73 6f 20 69 6e 63 6c 75 64 65 20 61 20 63 also include a c
7e10: 6f 6d 70 72 65 73 73 69 6f 6e 20 6c 65 76 65 6c ompression level
7e20: 0a 20 20 20 28 22 77 62 39 22 29 20 6f 72 20 61 . ("wb9") or a
7e30: 20 73 74 72 61 74 65 67 79 3a 20 27 66 27 20 66 strategy: 'f' f
7e40: 6f 72 20 66 69 6c 74 65 72 65 64 20 64 61 74 61 or filtered data
7e50: 20 61 73 20 69 6e 20 22 77 62 36 66 22 2c 20 27 as in "wb6f", '
7e60: 68 27 20 66 6f 72 0a 20 20 20 48 75 66 66 6d 61 h' for. Huffma
7e70: 6e 20 6f 6e 6c 79 20 63 6f 6d 70 72 65 73 73 69 n only compressi
7e80: 6f 6e 20 61 73 20 69 6e 20 22 77 62 31 68 22 2e on as in "wb1h".
7e90: 20 28 53 65 65 20 74 68 65 20 64 65 73 63 72 69 (See the descri
7ea0: 70 74 69 6f 6e 0a 20 20 20 6f 66 20 64 65 66 6c ption. of defl
7eb0: 61 74 65 49 6e 69 74 32 20 66 6f 72 20 6d 6f 72 ateInit2 for mor
7ec0: 65 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 e information ab
7ed0: 6f 75 74 20 74 68 65 20 73 74 72 61 74 65 67 79 out the strategy
7ee0: 20 70 61 72 61 6d 65 74 65 72 2e 29 0a 0a 20 20 parameter.)..
7ef0: 20 20 20 67 7a 6f 70 65 6e 20 63 61 6e 20 62 65 gzopen can be
7f00: 20 75 73 65 64 20 74 6f 20 72 65 61 64 20 61 20 used to read a
7f10: 66 69 6c 65 20 77 68 69 63 68 20 69 73 20 6e 6f file which is no
7f20: 74 20 69 6e 20 67 7a 69 70 20 66 6f 72 6d 61 74 t in gzip format
7f30: 3b 20 69 6e 20 74 68 69 73 0a 20 20 20 63 61 73 ; in this. cas
7f40: 65 20 67 7a 72 65 61 64 20 77 69 6c 6c 20 64 69 e gzread will di
7f50: 72 65 63 74 6c 79 20 72 65 61 64 20 66 72 6f 6d rectly read from
7f60: 20 74 68 65 20 66 69 6c 65 20 77 69 74 68 6f 75 the file withou
7f70: 74 20 64 65 63 6f 6d 70 72 65 73 73 69 6f 6e 2e t decompression.
7f80: 0a 0a 20 20 20 20 20 67 7a 6f 70 65 6e 20 72 65 .. gzopen re
7f90: 74 75 72 6e 73 20 4e 55 4c 4c 20 69 66 20 74 68 turns NULL if th
7fa0: 65 20 66 69 6c 65 20 63 6f 75 6c 64 20 6e 6f 74 e file could not
7fb0: 20 62 65 20 6f 70 65 6e 65 64 20 6f 72 20 69 66 be opened or if
7fc0: 20 74 68 65 72 65 20 77 61 73 0a 20 20 20 69 6e there was. in
7fd0: 73 75 66 66 69 63 69 65 6e 74 20 6d 65 6d 6f 72 sufficient memor
7fe0: 79 20 74 6f 20 61 6c 6c 6f 63 61 74 65 20 74 68 y to allocate th
7ff0: 65 20 28 64 65 29 63 6f 6d 70 72 65 73 73 69 6f e (de)compressio
8000: 6e 20 73 74 61 74 65 3b 20 65 72 72 6e 6f 0a 20 n state; errno.
8010: 20 20 63 61 6e 20 62 65 20 63 68 65 63 6b 65 64 can be checked
8020: 20 74 6f 20 64 69 73 74 69 6e 67 75 69 73 68 20 to distinguish
8030: 74 68 65 20 74 77 6f 20 63 61 73 65 73 20 28 69 the two cases (i
8040: 66 20 65 72 72 6e 6f 20 69 73 20 7a 65 72 6f 2c f errno is zero,
8050: 20 74 68 65 0a 20 20 20 7a 6c 69 62 20 65 72 72 the. zlib err
8060: 6f 72 20 69 73 20 5a 5f 4d 45 4d 5f 45 52 52 4f or is Z_MEM_ERRO
8070: 52 29 2e 20 20 2a 2f 0a 0a 5a 45 58 54 45 52 4e R). */..ZEXTERN
8080: 20 67 7a 46 69 6c 65 20 5a 45 58 50 4f 52 54 20 gzFile ZEXPORT
8090: 67 7a 64 6f 70 65 6e 20 20 4f 46 28 28 69 6e 74 gzdopen OF((int
80a0: 20 66 64 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 fd, const char
80b0: 2a 6d 6f 64 65 29 29 3b 0a 2f 2a 0a 20 20 20 20 *mode));./*.
80c0: 20 67 7a 64 6f 70 65 6e 28 29 20 61 73 73 6f 63 gzdopen() assoc
80d0: 69 61 74 65 73 20 61 20 67 7a 46 69 6c 65 20 77 iates a gzFile w
80e0: 69 74 68 20 74 68 65 20 66 69 6c 65 20 64 65 73 ith the file des
80f0: 63 72 69 70 74 6f 72 20 66 64 2e 20 20 46 69 6c criptor fd. Fil
8100: 65 0a 20 20 20 64 65 73 63 72 69 70 74 6f 72 73 e. descriptors
8110: 20 61 72 65 20 6f 62 74 61 69 6e 65 64 20 66 72 are obtained fr
8120: 6f 6d 20 63 61 6c 6c 73 20 6c 69 6b 65 20 6f 70 om calls like op
8130: 65 6e 2c 20 64 75 70 2c 20 63 72 65 61 74 2c 20 en, dup, creat,
8140: 70 69 70 65 20 6f 72 0a 20 20 20 66 69 6c 65 6e pipe or. filen
8150: 6f 20 28 69 6e 20 74 68 65 20 66 69 6c 65 20 68 o (in the file h
8160: 61 73 20 62 65 65 6e 20 70 72 65 76 69 6f 75 73 as been previous
8170: 6c 79 20 6f 70 65 6e 65 64 20 77 69 74 68 20 66 ly opened with f
8180: 6f 70 65 6e 29 2e 0a 20 20 20 54 68 65 20 6d 6f open).. The mo
8190: 64 65 20 70 61 72 61 6d 65 74 65 72 20 69 73 20 de parameter is
81a0: 61 73 20 69 6e 20 67 7a 6f 70 65 6e 2e 0a 20 20 as in gzopen..
81b0: 20 20 20 54 68 65 20 6e 65 78 74 20 63 61 6c 6c The next call
81c0: 20 6f 66 20 67 7a 63 6c 6f 73 65 20 6f 6e 20 74 of gzclose on t
81d0: 68 65 20 72 65 74 75 72 6e 65 64 20 67 7a 46 69 he returned gzFi
81e0: 6c 65 20 77 69 6c 6c 20 61 6c 73 6f 20 63 6c 6f le will also clo
81f0: 73 65 20 74 68 65 0a 20 20 20 66 69 6c 65 20 64 se the. file d
8200: 65 73 63 72 69 70 74 6f 72 20 66 64 2c 20 6a 75 escriptor fd, ju
8210: 73 74 20 6c 69 6b 65 20 66 63 6c 6f 73 65 28 66 st like fclose(f
8220: 64 6f 70 65 6e 28 66 64 29 2c 20 6d 6f 64 65 29 dopen(fd), mode)
8230: 20 63 6c 6f 73 65 73 20 74 68 65 20 66 69 6c 65 closes the file
8240: 0a 20 20 20 64 65 73 63 72 69 70 74 6f 72 20 66 . descriptor f
8250: 64 2e 20 49 66 20 79 6f 75 20 77 61 6e 74 20 74 d. If you want t
8260: 6f 20 6b 65 65 70 20 66 64 20 6f 70 65 6e 2c 20 o keep fd open,
8270: 75 73 65 20 67 7a 64 6f 70 65 6e 28 64 75 70 28 use gzdopen(dup(
8280: 66 64 29 2c 20 6d 6f 64 65 29 2e 0a 20 20 20 20 fd), mode)..
8290: 20 67 7a 64 6f 70 65 6e 20 72 65 74 75 72 6e 73 gzdopen returns
82a0: 20 4e 55 4c 4c 20 69 66 20 74 68 65 72 65 20 77 NULL if there w
82b0: 61 73 20 69 6e 73 75 66 66 69 63 69 65 6e 74 20 as insufficient
82c0: 6d 65 6d 6f 72 79 20 74 6f 20 61 6c 6c 6f 63 61 memory to alloca
82d0: 74 65 0a 20 20 20 74 68 65 20 28 64 65 29 63 6f te. the (de)co
82e0: 6d 70 72 65 73 73 69 6f 6e 20 73 74 61 74 65 2e mpression state.
82f0: 0a 2a 2f 0a 0a 5a 45 58 54 45 52 4e 20 69 6e 74 .*/..ZEXTERN int
8300: 20 5a 45 58 50 4f 52 54 20 67 7a 73 65 74 70 61 ZEXPORT gzsetpa
8310: 72 61 6d 73 20 4f 46 28 28 67 7a 46 69 6c 65 20 rams OF((gzFile
8320: 66 69 6c 65 2c 20 69 6e 74 20 6c 65 76 65 6c 2c file, int level,
8330: 20 69 6e 74 20 73 74 72 61 74 65 67 79 29 29 3b int strategy));
8340: 0a 2f 2a 0a 20 20 20 20 20 44 79 6e 61 6d 69 63 ./*. Dynamic
8350: 61 6c 6c 79 20 75 70 64 61 74 65 20 74 68 65 20 ally update the
8360: 63 6f 6d 70 72 65 73 73 69 6f 6e 20 6c 65 76 65 compression leve
8370: 6c 20 6f 72 20 73 74 72 61 74 65 67 79 2e 20 53 l or strategy. S
8380: 65 65 20 74 68 65 20 64 65 73 63 72 69 70 74 69 ee the descripti
8390: 6f 6e 0a 20 20 20 6f 66 20 64 65 66 6c 61 74 65 on. of deflate
83a0: 49 6e 69 74 32 20 66 6f 72 20 74 68 65 20 6d 65 Init2 for the me
83b0: 61 6e 69 6e 67 20 6f 66 20 74 68 65 73 65 20 70 aning of these p
83c0: 61 72 61 6d 65 74 65 72 73 2e 0a 20 20 20 20 20 arameters..
83d0: 67 7a 73 65 74 70 61 72 61 6d 73 20 72 65 74 75 gzsetparams retu
83e0: 72 6e 73 20 5a 5f 4f 4b 20 69 66 20 73 75 63 63 rns Z_OK if succ
83f0: 65 73 73 2c 20 6f 72 20 5a 5f 53 54 52 45 41 4d ess, or Z_STREAM
8400: 5f 45 52 52 4f 52 20 69 66 20 74 68 65 20 66 69 _ERROR if the fi
8410: 6c 65 20 77 61 73 20 6e 6f 74 0a 20 20 20 6f 70 le was not. op
8420: 65 6e 65 64 20 66 6f 72 20 77 72 69 74 69 6e 67 ened for writing
8430: 2e 0a 2a 2f 0a 0a 5a 45 58 54 45 52 4e 20 69 6e ..*/..ZEXTERN in
8440: 74 20 5a 45 58 50 4f 52 54 20 20 20 20 67 7a 72 t ZEXPORT gzr
8450: 65 61 64 20 20 4f 46 28 28 67 7a 46 69 6c 65 20 ead OF((gzFile
8460: 66 69 6c 65 2c 20 76 6f 69 64 70 20 62 75 66 2c file, voidp buf,
8470: 20 75 6e 73 69 67 6e 65 64 20 6c 65 6e 29 29 3b unsigned len));
8480: 0a 2f 2a 0a 20 20 20 20 20 52 65 61 64 73 20 74 ./*. Reads t
8490: 68 65 20 67 69 76 65 6e 20 6e 75 6d 62 65 72 20 he given number
84a0: 6f 66 20 75 6e 63 6f 6d 70 72 65 73 73 65 64 20 of uncompressed
84b0: 62 79 74 65 73 20 66 72 6f 6d 20 74 68 65 20 63 bytes from the c
84c0: 6f 6d 70 72 65 73 73 65 64 20 66 69 6c 65 2e 0a ompressed file..
84d0: 20 20 20 49 66 20 74 68 65 20 69 6e 70 75 74 20 If the input
84e0: 66 69 6c 65 20 77 61 73 20 6e 6f 74 20 69 6e 20 file was not in
84f0: 67 7a 69 70 20 66 6f 72 6d 61 74 2c 20 67 7a 72 gzip format, gzr
8500: 65 61 64 20 63 6f 70 69 65 73 20 74 68 65 20 67 ead copies the g
8510: 69 76 65 6e 20 6e 75 6d 62 65 72 0a 20 20 20 6f iven number. o
8520: 66 20 62 79 74 65 73 20 69 6e 74 6f 20 74 68 65 f bytes into the
8530: 20 62 75 66 66 65 72 2e 0a 20 20 20 20 20 67 7a buffer.. gz
8540: 72 65 61 64 20 72 65 74 75 72 6e 73 20 74 68 65 read returns the
8550: 20 6e 75 6d 62 65 72 20 6f 66 20 75 6e 63 6f 6d number of uncom
8560: 70 72 65 73 73 65 64 20 62 79 74 65 73 20 61 63 pressed bytes ac
8570: 74 75 61 6c 6c 79 20 72 65 61 64 20 28 30 20 66 tually read (0 f
8580: 6f 72 0a 20 20 20 65 6e 64 20 6f 66 20 66 69 6c or. end of fil
8590: 65 2c 20 2d 31 20 66 6f 72 20 65 72 72 6f 72 29 e, -1 for error)
85a0: 2e 20 2a 2f 0a 0a 23 69 66 6e 64 65 66 20 4b 49 . */..#ifndef KI
85b0: 5f 47 5a 5f 4e 4f 5f 43 4f 4d 50 52 45 53 53 49 _GZ_NO_COMPRESSI
85c0: 4f 4e 0d 0a 0d 0a 5a 45 58 54 45 52 4e 20 69 6e ON....ZEXTERN in
85d0: 74 20 5a 45 58 50 4f 52 54 20 20 20 20 67 7a 77 t ZEXPORT gzw
85e0: 72 69 74 65 20 4f 46 28 28 67 7a 46 69 6c 65 20 rite OF((gzFile
85f0: 66 69 6c 65 2c 20 0a 09 09 09 09 20 20 20 63 6f file, ..... co
8600: 6e 73 74 20 76 6f 69 64 70 20 62 75 66 2c 20 75 nst voidp buf, u
8610: 6e 73 69 67 6e 65 64 20 6c 65 6e 29 29 3b 0a 2f nsigned len));./
8620: 2a 0a 20 20 20 20 20 57 72 69 74 65 73 20 74 68 *. Writes th
8630: 65 20 67 69 76 65 6e 20 6e 75 6d 62 65 72 20 6f e given number o
8640: 66 20 75 6e 63 6f 6d 70 72 65 73 73 65 64 20 62 f uncompressed b
8650: 79 74 65 73 20 69 6e 74 6f 20 74 68 65 20 63 6f ytes into the co
8660: 6d 70 72 65 73 73 65 64 20 66 69 6c 65 2e 0a 20 mpressed file..
8670: 20 20 67 7a 77 72 69 74 65 20 72 65 74 75 72 6e gzwrite return
8680: 73 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 s the number of
8690: 75 6e 63 6f 6d 70 72 65 73 73 65 64 20 62 79 74 uncompressed byt
86a0: 65 73 20 61 63 74 75 61 6c 6c 79 20 77 72 69 74 es actually writ
86b0: 74 65 6e 0a 20 20 20 28 30 20 69 6e 20 63 61 73 ten. (0 in cas
86c0: 65 20 6f 66 20 65 72 72 6f 72 29 2e 0a 2a 2f 0a e of error)..*/.
86d0: 0a 5a 45 58 54 45 52 4e 20 69 6e 74 20 5a 45 58 .ZEXTERN int ZEX
86e0: 50 4f 52 54 56 41 20 20 20 67 7a 70 72 69 6e 74 PORTVA gzprint
86f0: 66 20 4f 46 28 28 67 7a 46 69 6c 65 20 66 69 6c f OF((gzFile fil
8700: 65 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 e, const char *f
8710: 6f 72 6d 61 74 2c 20 2e 2e 2e 29 29 3b 0a 2f 2a ormat, ...));./*
8720: 0a 20 20 20 20 20 43 6f 6e 76 65 72 74 73 2c 20 . Converts,
8730: 66 6f 72 6d 61 74 73 2c 20 61 6e 64 20 77 72 69 formats, and wri
8740: 74 65 73 20 74 68 65 20 61 72 67 73 20 74 6f 20 tes the args to
8750: 74 68 65 20 63 6f 6d 70 72 65 73 73 65 64 20 66 the compressed f
8760: 69 6c 65 20 75 6e 64 65 72 0a 20 20 20 63 6f 6e ile under. con
8770: 74 72 6f 6c 20 6f 66 20 74 68 65 20 66 6f 72 6d trol of the form
8780: 61 74 20 73 74 72 69 6e 67 2c 20 61 73 20 69 6e at string, as in
8790: 20 66 70 72 69 6e 74 66 2e 20 67 7a 70 72 69 6e fprintf. gzprin
87a0: 74 66 20 72 65 74 75 72 6e 73 20 74 68 65 20 6e tf returns the n
87b0: 75 6d 62 65 72 20 6f 66 0a 20 20 20 75 6e 63 6f umber of. unco
87c0: 6d 70 72 65 73 73 65 64 20 62 79 74 65 73 20 61 mpressed bytes a
87d0: 63 74 75 61 6c 6c 79 20 77 72 69 74 74 65 6e 20 ctually written
87e0: 28 30 20 69 6e 20 63 61 73 65 20 6f 66 20 65 72 (0 in case of er
87f0: 72 6f 72 29 2e 0a 2a 2f 0a 0a 5a 45 58 54 45 52 ror)..*/..ZEXTER
8800: 4e 20 69 6e 74 20 5a 45 58 50 4f 52 54 20 67 7a N int ZEXPORT gz
8810: 70 75 74 73 20 4f 46 28 28 67 7a 46 69 6c 65 20 puts OF((gzFile
8820: 66 69 6c 65 2c 20 63 6f 6e 73 74 20 63 68 61 72 file, const char
8830: 20 2a 73 29 29 3b 0a 2f 2a 0a 20 20 20 20 20 20 *s));./*.
8840: 57 72 69 74 65 73 20 74 68 65 20 67 69 76 65 6e Writes the given
8850: 20 6e 75 6c 6c 2d 74 65 72 6d 69 6e 61 74 65 64 null-terminated
8860: 20 73 74 72 69 6e 67 20 74 6f 20 74 68 65 20 63 string to the c
8870: 6f 6d 70 72 65 73 73 65 64 20 66 69 6c 65 2c 20 ompressed file,
8880: 65 78 63 6c 75 64 69 6e 67 0a 20 20 20 74 68 65 excluding. the
8890: 20 74 65 72 6d 69 6e 61 74 69 6e 67 20 6e 75 6c terminating nul
88a0: 6c 20 63 68 61 72 61 63 74 65 72 2e 0a 20 20 20 l character..
88b0: 20 20 20 67 7a 70 75 74 73 20 72 65 74 75 72 6e gzputs return
88c0: 73 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 s the number of
88d0: 63 68 61 72 61 63 74 65 72 73 20 77 72 69 74 74 characters writt
88e0: 65 6e 2c 20 6f 72 20 2d 31 20 69 6e 20 63 61 73 en, or -1 in cas
88f0: 65 20 6f 66 20 65 72 72 6f 72 2e 0a 2a 2f 0a 0a e of error..*/..
8900: 23 65 6e 64 69 66 20 2f 2a 20 4b 49 5f 47 5a 5f #endif /* KI_GZ_
8910: 4e 4f 5f 43 4f 4d 50 52 45 53 53 49 4f 4e 20 2a NO_COMPRESSION *
8920: 2f 0d 0a 0d 0a 5a 45 58 54 45 52 4e 20 63 68 61 /....ZEXTERN cha
8930: 72 20 2a 20 5a 45 58 50 4f 52 54 20 67 7a 67 65 r * ZEXPORT gzge
8940: 74 73 20 4f 46 28 28 67 7a 46 69 6c 65 20 66 69 ts OF((gzFile fi
8950: 6c 65 2c 20 63 68 61 72 20 2a 62 75 66 2c 20 69 le, char *buf, i
8960: 6e 74 20 6c 65 6e 29 29 3b 0a 2f 2a 0a 20 20 20 nt len));./*.
8970: 20 20 20 52 65 61 64 73 20 62 79 74 65 73 20 66 Reads bytes f
8980: 72 6f 6d 20 74 68 65 20 63 6f 6d 70 72 65 73 73 rom the compress
8990: 65 64 20 66 69 6c 65 20 75 6e 74 69 6c 20 6c 65 ed file until le
89a0: 6e 2d 31 20 63 68 61 72 61 63 74 65 72 73 20 61 n-1 characters a
89b0: 72 65 20 72 65 61 64 2c 20 6f 72 0a 20 20 20 61 re read, or. a
89c0: 20 6e 65 77 6c 69 6e 65 20 63 68 61 72 61 63 74 newline charact
89d0: 65 72 20 69 73 20 72 65 61 64 20 61 6e 64 20 74 er is read and t
89e0: 72 61 6e 73 66 65 72 72 65 64 20 74 6f 20 62 75 ransferred to bu
89f0: 66 2c 20 6f 72 20 61 6e 20 65 6e 64 2d 6f 66 2d f, or an end-of-
8a00: 66 69 6c 65 0a 20 20 20 63 6f 6e 64 69 74 69 6f file. conditio
8a10: 6e 20 69 73 20 65 6e 63 6f 75 6e 74 65 72 65 64 n is encountered
8a20: 2e 20 20 54 68 65 20 73 74 72 69 6e 67 20 69 73 . The string is
8a30: 20 74 68 65 6e 20 74 65 72 6d 69 6e 61 74 65 64 then terminated
8a40: 20 77 69 74 68 20 61 20 6e 75 6c 6c 0a 20 20 20 with a null.
8a50: 63 68 61 72 61 63 74 65 72 2e 0a 20 20 20 20 20 character..
8a60: 20 67 7a 67 65 74 73 20 72 65 74 75 72 6e 73 20 gzgets returns
8a70: 62 75 66 2c 20 6f 72 20 5a 5f 4e 55 4c 4c 20 69 buf, or Z_NULL i
8a80: 6e 20 63 61 73 65 20 6f 66 20 65 72 72 6f 72 2e n case of error.
8a90: 0a 2a 2f 0a 0a 23 69 66 64 65 66 20 4b 49 5f 47 .*/..#ifdef KI_G
8aa0: 5a 5f 4e 4f 5f 43 4f 4d 50 52 45 53 53 49 4f 4e Z_NO_COMPRESSION
8ab0: 0d 0a 0d 0a 5a 45 58 54 45 52 4e 20 69 6e 74 20 ....ZEXTERN int
8ac0: 5a 45 58 50 4f 52 54 20 20 20 20 67 7a 70 75 74 ZEXPORT gzput
8ad0: 63 20 4f 46 28 28 67 7a 46 69 6c 65 20 66 69 6c c OF((gzFile fil
8ae0: 65 2c 20 69 6e 74 20 63 29 29 3b 0a 2f 2a 0a 20 e, int c));./*.
8af0: 20 20 20 20 20 57 72 69 74 65 73 20 63 2c 20 63 Writes c, c
8b00: 6f 6e 76 65 72 74 65 64 20 74 6f 20 61 6e 20 75 onverted to an u
8b10: 6e 73 69 67 6e 65 64 20 63 68 61 72 2c 20 69 6e nsigned char, in
8b20: 74 6f 20 74 68 65 20 63 6f 6d 70 72 65 73 73 65 to the compresse
8b30: 64 20 66 69 6c 65 2e 0a 20 20 20 67 7a 70 75 74 d file.. gzput
8b40: 63 20 72 65 74 75 72 6e 73 20 74 68 65 20 76 61 c returns the va
8b50: 6c 75 65 20 74 68 61 74 20 77 61 73 20 77 72 69 lue that was wri
8b60: 74 74 65 6e 2c 20 6f 72 20 2d 31 20 69 6e 20 63 tten, or -1 in c
8b70: 61 73 65 20 6f 66 20 65 72 72 6f 72 2e 0a 2a 2f ase of error..*/
8b80: 0a 0a 23 65 6e 64 69 66 20 2f 2a 20 4b 49 5f 47 ..#endif /* KI_G
8b90: 5a 5f 4e 4f 5f 43 4f 4d 50 52 45 53 53 49 4f 4e Z_NO_COMPRESSION
8ba0: 20 2a 2f 0d 0a 0d 0a 5a 45 58 54 45 52 4e 20 69 */....ZEXTERN i
8bb0: 6e 74 20 5a 45 58 50 4f 52 54 20 20 20 20 67 7a nt ZEXPORT gz
8bc0: 67 65 74 63 20 4f 46 28 28 67 7a 46 69 6c 65 20 getc OF((gzFile
8bd0: 66 69 6c 65 29 29 3b 0a 2f 2a 0a 20 20 20 20 20 file));./*.
8be0: 20 52 65 61 64 73 20 6f 6e 65 20 62 79 74 65 20 Reads one byte
8bf0: 66 72 6f 6d 20 74 68 65 20 63 6f 6d 70 72 65 73 from the compres
8c00: 73 65 64 20 66 69 6c 65 2e 20 67 7a 67 65 74 63 sed file. gzgetc
8c10: 20 72 65 74 75 72 6e 73 20 74 68 69 73 20 62 79 returns this by
8c20: 74 65 0a 20 20 20 6f 72 20 2d 31 20 69 6e 20 63 te. or -1 in c
8c30: 61 73 65 20 6f 66 20 65 6e 64 20 6f 66 20 66 69 ase of end of fi
8c40: 6c 65 20 6f 72 20 65 72 72 6f 72 2e 0a 2a 2f 0a le or error..*/.
8c50: 0a 23 69 66 6e 64 65 66 20 4b 49 5f 47 5a 5f 4e .#ifndef KI_GZ_N
8c60: 4f 5f 43 4f 4d 50 52 45 53 53 49 4f 4e 0d 0a 5a O_COMPRESSION..Z
8c70: 45 58 54 45 52 4e 20 69 6e 74 20 5a 45 58 50 4f EXTERN int ZEXPO
8c80: 52 54 20 20 20 20 67 7a 66 6c 75 73 68 20 4f 46 RT gzflush OF
8c90: 28 28 67 7a 46 69 6c 65 20 66 69 6c 65 2c 20 69 ((gzFile file, i
8ca0: 6e 74 20 66 6c 75 73 68 29 29 3b 0a 2f 2a 0a 20 nt flush));./*.
8cb0: 20 20 20 20 46 6c 75 73 68 65 73 20 61 6c 6c 20 Flushes all
8cc0: 70 65 6e 64 69 6e 67 20 6f 75 74 70 75 74 20 69 pending output i
8cd0: 6e 74 6f 20 74 68 65 20 63 6f 6d 70 72 65 73 73 nto the compress
8ce0: 65 64 20 66 69 6c 65 2e 20 54 68 65 20 70 61 72 ed file. The par
8cf0: 61 6d 65 74 65 72 0a 20 20 20 66 6c 75 73 68 20 ameter. flush
8d00: 69 73 20 61 73 20 69 6e 20 74 68 65 20 64 65 66 is as in the def
8d10: 6c 61 74 65 28 29 20 66 75 6e 63 74 69 6f 6e 2e late() function.
8d20: 20 54 68 65 20 72 65 74 75 72 6e 20 76 61 6c 75 The return valu
8d30: 65 20 69 73 20 74 68 65 20 7a 6c 69 62 0a 20 20 e is the zlib.
8d40: 20 65 72 72 6f 72 20 6e 75 6d 62 65 72 20 28 73 error number (s
8d50: 65 65 20 66 75 6e 63 74 69 6f 6e 20 67 7a 65 72 ee function gzer
8d60: 72 6f 72 20 62 65 6c 6f 77 29 2e 20 67 7a 66 6c ror below). gzfl
8d70: 75 73 68 20 72 65 74 75 72 6e 73 20 5a 5f 4f 4b ush returns Z_OK
8d80: 20 69 66 0a 20 20 20 74 68 65 20 66 6c 75 73 68 if. the flush
8d90: 20 70 61 72 61 6d 65 74 65 72 20 69 73 20 5a 5f parameter is Z_
8da0: 46 49 4e 49 53 48 20 61 6e 64 20 61 6c 6c 20 6f FINISH and all o
8db0: 75 74 70 75 74 20 63 6f 75 6c 64 20 62 65 20 66 utput could be f
8dc0: 6c 75 73 68 65 64 2e 0a 20 20 20 20 20 67 7a 66 lushed.. gzf
8dd0: 6c 75 73 68 20 73 68 6f 75 6c 64 20 62 65 20 63 lush should be c
8de0: 61 6c 6c 65 64 20 6f 6e 6c 79 20 77 68 65 6e 20 alled only when
8df0: 73 74 72 69 63 74 6c 79 20 6e 65 63 65 73 73 61 strictly necessa
8e00: 72 79 20 62 65 63 61 75 73 65 20 69 74 20 63 61 ry because it ca
8e10: 6e 0a 20 20 20 64 65 67 72 61 64 65 20 63 6f 6d n. degrade com
8e20: 70 72 65 73 73 69 6f 6e 2e 0a 2a 2f 0a 23 65 6e pression..*/.#en
8e30: 64 69 66 20 2f 2a 20 4b 49 5f 47 5a 5f 4e 4f 5f dif /* KI_GZ_NO_
8e40: 43 4f 4d 50 52 45 53 53 49 4f 4e 20 2a 2f 0d 0a COMPRESSION */..
8e50: 0a 5a 45 58 54 45 52 4e 20 7a 5f 6f 66 66 5f 74 .ZEXTERN z_off_t
8e60: 20 5a 45 58 50 4f 52 54 20 20 20 20 67 7a 73 65 ZEXPORT gzse
8e70: 65 6b 20 4f 46 28 28 67 7a 46 69 6c 65 20 66 69 ek OF((gzFile fi
8e80: 6c 65 2c 0a 09 09 09 09 20 20 20 20 20 20 7a 5f le,..... z_
8e90: 6f 66 66 5f 74 20 6f 66 66 73 65 74 2c 20 69 6e off_t offset, in
8ea0: 74 20 77 68 65 6e 63 65 29 29 3b 0a 2f 2a 20 0a t whence));./* .
8eb0: 20 20 20 20 20 20 53 65 74 73 20 74 68 65 20 73 Sets the s
8ec0: 74 61 72 74 69 6e 67 20 70 6f 73 69 74 69 6f 6e tarting position
8ed0: 20 66 6f 72 20 74 68 65 20 6e 65 78 74 20 67 7a for the next gz
8ee0: 72 65 61 64 20 6f 72 20 67 7a 77 72 69 74 65 20 read or gzwrite
8ef0: 6f 6e 20 74 68 65 0a 20 20 20 67 69 76 65 6e 20 on the. given
8f00: 63 6f 6d 70 72 65 73 73 65 64 20 66 69 6c 65 2e compressed file.
8f10: 20 54 68 65 20 6f 66 66 73 65 74 20 72 65 70 72 The offset repr
8f20: 65 73 65 6e 74 73 20 61 20 6e 75 6d 62 65 72 20 esents a number
8f30: 6f 66 20 62 79 74 65 73 20 69 6e 20 74 68 65 0a of bytes in the.
8f40: 20 20 20 75 6e 63 6f 6d 70 72 65 73 73 65 64 20 uncompressed
8f50: 64 61 74 61 20 73 74 72 65 61 6d 2e 20 54 68 65 data stream. The
8f60: 20 77 68 65 6e 63 65 20 70 61 72 61 6d 65 74 65 whence paramete
8f70: 72 20 69 73 20 64 65 66 69 6e 65 64 20 61 73 20 r is defined as
8f80: 69 6e 20 6c 73 65 65 6b 28 32 29 3b 0a 20 20 20 in lseek(2);.
8f90: 74 68 65 20 76 61 6c 75 65 20 53 45 45 4b 5f 45 the value SEEK_E
8fa0: 4e 44 20 69 73 20 6e 6f 74 20 73 75 70 70 6f 72 ND is not suppor
8fb0: 74 65 64 2e 0a 20 20 20 20 20 49 66 20 74 68 65 ted.. If the
8fc0: 20 66 69 6c 65 20 69 73 20 6f 70 65 6e 65 64 20 file is opened
8fd0: 66 6f 72 20 72 65 61 64 69 6e 67 2c 20 74 68 69 for reading, thi
8fe0: 73 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 65 6d s function is em
8ff0: 75 6c 61 74 65 64 20 62 75 74 20 63 61 6e 20 62 ulated but can b
9000: 65 0a 20 20 20 65 78 74 72 65 6d 65 6c 79 20 73 e. extremely s
9010: 6c 6f 77 2e 20 49 66 20 74 68 65 20 66 69 6c 65 low. If the file
9020: 20 69 73 20 6f 70 65 6e 65 64 20 66 6f 72 20 77 is opened for w
9030: 72 69 74 69 6e 67 2c 20 6f 6e 6c 79 20 66 6f 72 riting, only for
9040: 77 61 72 64 20 73 65 65 6b 73 20 61 72 65 0a 20 ward seeks are.
9050: 20 20 73 75 70 70 6f 72 74 65 64 3b 20 67 7a 73 supported; gzs
9060: 65 65 6b 20 74 68 65 6e 20 63 6f 6d 70 72 65 73 eek then compres
9070: 73 65 73 20 61 20 73 65 71 75 65 6e 63 65 20 6f ses a sequence o
9080: 66 20 7a 65 72 6f 65 73 20 75 70 20 74 6f 20 74 f zeroes up to t
9090: 68 65 20 6e 65 77 0a 20 20 20 73 74 61 72 74 69 he new. starti
90a0: 6e 67 20 70 6f 73 69 74 69 6f 6e 2e 0a 0a 20 20 ng position...
90b0: 20 20 20 20 67 7a 73 65 65 6b 20 72 65 74 75 72 gzseek retur
90c0: 6e 73 20 74 68 65 20 72 65 73 75 6c 74 69 6e 67 ns the resulting
90d0: 20 6f 66 66 73 65 74 20 6c 6f 63 61 74 69 6f 6e offset location
90e0: 20 61 73 20 6d 65 61 73 75 72 65 64 20 69 6e 20 as measured in
90f0: 62 79 74 65 73 20 66 72 6f 6d 0a 20 20 20 74 68 bytes from. th
9100: 65 20 62 65 67 69 6e 6e 69 6e 67 20 6f 66 20 74 e beginning of t
9110: 68 65 20 75 6e 63 6f 6d 70 72 65 73 73 65 64 20 he uncompressed
9120: 73 74 72 65 61 6d 2c 20 6f 72 20 2d 31 20 69 6e stream, or -1 in
9130: 20 63 61 73 65 20 6f 66 20 65 72 72 6f 72 2c 20 case of error,
9140: 69 6e 0a 20 20 20 70 61 72 74 69 63 75 6c 61 72 in. particular
9150: 20 69 66 20 74 68 65 20 66 69 6c 65 20 69 73 20 if the file is
9160: 6f 70 65 6e 65 64 20 66 6f 72 20 77 72 69 74 69 opened for writi
9170: 6e 67 20 61 6e 64 20 74 68 65 20 6e 65 77 20 73 ng and the new s
9180: 74 61 72 74 69 6e 67 20 70 6f 73 69 74 69 6f 6e tarting position
9190: 0a 20 20 20 77 6f 75 6c 64 20 62 65 20 62 65 66 . would be bef
91a0: 6f 72 65 20 74 68 65 20 63 75 72 72 65 6e 74 20 ore the current
91b0: 70 6f 73 69 74 69 6f 6e 2e 0a 2a 2f 0a 0a 5a 45 position..*/..ZE
91c0: 58 54 45 52 4e 20 69 6e 74 20 5a 45 58 50 4f 52 XTERN int ZEXPOR
91d0: 54 20 20 20 20 67 7a 72 65 77 69 6e 64 20 4f 46 T gzrewind OF
91e0: 28 28 67 7a 46 69 6c 65 20 66 69 6c 65 29 29 3b ((gzFile file));
91f0: 0a 2f 2a 0a 20 20 20 20 20 52 65 77 69 6e 64 73 ./*. Rewinds
9200: 20 74 68 65 20 67 69 76 65 6e 20 66 69 6c 65 2e the given file.
9210: 20 54 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 69 This function i
9220: 73 20 73 75 70 70 6f 72 74 65 64 20 6f 6e 6c 79 s supported only
9230: 20 66 6f 72 20 72 65 61 64 69 6e 67 2e 0a 0a 20 for reading...
9240: 20 20 67 7a 72 65 77 69 6e 64 28 66 69 6c 65 29 gzrewind(file)
9250: 20 69 73 20 65 71 75 69 76 61 6c 65 6e 74 20 74 is equivalent t
9260: 6f 20 28 69 6e 74 29 67 7a 73 65 65 6b 28 66 69 o (int)gzseek(fi
9270: 6c 65 2c 20 30 4c 2c 20 53 45 45 4b 5f 53 45 54 le, 0L, SEEK_SET
9280: 29 0a 2a 2f 0a 0a 5a 45 58 54 45 52 4e 20 7a 5f ).*/..ZEXTERN z_
9290: 6f 66 66 5f 74 20 5a 45 58 50 4f 52 54 20 20 20 off_t ZEXPORT
92a0: 20 67 7a 74 65 6c 6c 20 4f 46 28 28 67 7a 46 69 gztell OF((gzFi
92b0: 6c 65 20 66 69 6c 65 29 29 3b 0a 2f 2a 0a 20 20 le file));./*.
92c0: 20 20 20 52 65 74 75 72 6e 73 20 74 68 65 20 73 Returns the s
92d0: 74 61 72 74 69 6e 67 20 70 6f 73 69 74 69 6f 6e tarting position
92e0: 20 66 6f 72 20 74 68 65 20 6e 65 78 74 20 67 7a for the next gz
92f0: 72 65 61 64 20 6f 72 20 67 7a 77 72 69 74 65 20 read or gzwrite
9300: 6f 6e 20 74 68 65 0a 20 20 20 67 69 76 65 6e 20 on the. given
9310: 63 6f 6d 70 72 65 73 73 65 64 20 66 69 6c 65 2e compressed file.
9320: 20 54 68 69 73 20 70 6f 73 69 74 69 6f 6e 20 72 This position r
9330: 65 70 72 65 73 65 6e 74 73 20 61 20 6e 75 6d 62 epresents a numb
9340: 65 72 20 6f 66 20 62 79 74 65 73 20 69 6e 20 74 er of bytes in t
9350: 68 65 0a 20 20 20 75 6e 63 6f 6d 70 72 65 73 73 he. uncompress
9360: 65 64 20 64 61 74 61 20 73 74 72 65 61 6d 2e 0a ed data stream..
9370: 0a 20 20 20 67 7a 74 65 6c 6c 28 66 69 6c 65 29 . gztell(file)
9380: 20 69 73 20 65 71 75 69 76 61 6c 65 6e 74 20 74 is equivalent t
9390: 6f 20 67 7a 73 65 65 6b 28 66 69 6c 65 2c 20 30 o gzseek(file, 0
93a0: 4c 2c 20 53 45 45 4b 5f 43 55 52 29 0a 2a 2f 0a L, SEEK_CUR).*/.
93b0: 0a 5a 45 58 54 45 52 4e 20 69 6e 74 20 5a 45 58 .ZEXTERN int ZEX
93c0: 50 4f 52 54 20 67 7a 65 6f 66 20 4f 46 28 28 67 PORT gzeof OF((g
93d0: 7a 46 69 6c 65 20 66 69 6c 65 29 29 3b 0a 2f 2a zFile file));./*
93e0: 0a 20 20 20 20 20 52 65 74 75 72 6e 73 20 31 20 . Returns 1
93f0: 77 68 65 6e 20 45 4f 46 20 68 61 73 20 70 72 65 when EOF has pre
9400: 76 69 6f 75 73 6c 79 20 62 65 65 6e 20 64 65 74 viously been det
9410: 65 63 74 65 64 20 72 65 61 64 69 6e 67 20 74 68 ected reading th
9420: 65 20 67 69 76 65 6e 0a 20 20 20 69 6e 70 75 74 e given. input
9430: 20 73 74 72 65 61 6d 2c 20 6f 74 68 65 72 77 69 stream, otherwi
9440: 73 65 20 7a 65 72 6f 2e 0a 2a 2f 0a 0a 5a 45 58 se zero..*/..ZEX
9450: 54 45 52 4e 20 69 6e 74 20 5a 45 58 50 4f 52 54 TERN int ZEXPORT
9460: 20 20 20 20 67 7a 63 6c 6f 73 65 20 4f 46 28 28 gzclose OF((
9470: 67 7a 46 69 6c 65 20 66 69 6c 65 29 29 3b 0a 2f gzFile file));./
9480: 2a 0a 20 20 20 20 20 46 6c 75 73 68 65 73 20 61 *. Flushes a
9490: 6c 6c 20 70 65 6e 64 69 6e 67 20 6f 75 74 70 75 ll pending outpu
94a0: 74 20 69 66 20 6e 65 63 65 73 73 61 72 79 2c 20 t if necessary,
94b0: 63 6c 6f 73 65 73 20 74 68 65 20 63 6f 6d 70 72 closes the compr
94c0: 65 73 73 65 64 20 66 69 6c 65 0a 20 20 20 61 6e essed file. an
94d0: 64 20 64 65 61 6c 6c 6f 63 61 74 65 73 20 61 6c d deallocates al
94e0: 6c 20 74 68 65 20 28 64 65 29 63 6f 6d 70 72 65 l the (de)compre
94f0: 73 73 69 6f 6e 20 73 74 61 74 65 2e 20 54 68 65 ssion state. The
9500: 20 72 65 74 75 72 6e 20 76 61 6c 75 65 20 69 73 return value is
9510: 20 74 68 65 20 7a 6c 69 62 0a 20 20 20 65 72 72 the zlib. err
9520: 6f 72 20 6e 75 6d 62 65 72 20 28 73 65 65 20 66 or number (see f
9530: 75 6e 63 74 69 6f 6e 20 67 7a 65 72 72 6f 72 20 unction gzerror
9540: 62 65 6c 6f 77 29 2e 0a 2a 2f 0a 0a 5a 45 58 54 below)..*/..ZEXT
9550: 45 52 4e 20 63 6f 6e 73 74 20 63 68 61 72 20 2a ERN const char *
9560: 20 5a 45 58 50 4f 52 54 20 67 7a 65 72 72 6f 72 ZEXPORT gzerror
9570: 20 4f 46 28 28 67 7a 46 69 6c 65 20 66 69 6c 65 OF((gzFile file
9580: 2c 20 69 6e 74 20 2a 65 72 72 6e 75 6d 29 29 3b , int *errnum));
9590: 0a 2f 2a 0a 20 20 20 20 20 52 65 74 75 72 6e 73 ./*. Returns
95a0: 20 74 68 65 20 65 72 72 6f 72 20 6d 65 73 73 61 the error messa
95b0: 67 65 20 66 6f 72 20 74 68 65 20 6c 61 73 74 20 ge for the last
95c0: 65 72 72 6f 72 20 77 68 69 63 68 20 6f 63 63 75 error which occu
95d0: 72 72 65 64 20 6f 6e 20 74 68 65 0a 20 20 20 67 rred on the. g
95e0: 69 76 65 6e 20 63 6f 6d 70 72 65 73 73 65 64 20 iven compressed
95f0: 66 69 6c 65 2e 20 65 72 72 6e 75 6d 20 69 73 20 file. errnum is
9600: 73 65 74 20 74 6f 20 7a 6c 69 62 20 65 72 72 6f set to zlib erro
9610: 72 20 6e 75 6d 62 65 72 2e 20 49 66 20 61 6e 0a r number. If an.
9620: 20 20 20 65 72 72 6f 72 20 6f 63 63 75 72 72 65 error occurre
9630: 64 20 69 6e 20 74 68 65 20 66 69 6c 65 20 73 79 d in the file sy
9640: 73 74 65 6d 20 61 6e 64 20 6e 6f 74 20 69 6e 20 stem and not in
9650: 74 68 65 20 63 6f 6d 70 72 65 73 73 69 6f 6e 20 the compression
9660: 6c 69 62 72 61 72 79 2c 0a 20 20 20 65 72 72 6e library,. errn
9670: 75 6d 20 69 73 20 73 65 74 20 74 6f 20 5a 5f 45 um is set to Z_E
9680: 52 52 4e 4f 20 61 6e 64 20 74 68 65 20 61 70 70 RRNO and the app
9690: 6c 69 63 61 74 69 6f 6e 20 6d 61 79 20 63 6f 6e lication may con
96a0: 73 75 6c 74 20 65 72 72 6e 6f 0a 20 20 20 74 6f sult errno. to
96b0: 20 67 65 74 20 74 68 65 20 65 78 61 63 74 20 65 get the exact e
96c0: 72 72 6f 72 20 63 6f 64 65 2e 0a 2a 2f 0a 0a 20 rror code..*/..
96d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
96e0: 20 20 20 20 20 20 20 2f 2a 20 63 68 65 63 6b 73 /* checks
96f0: 75 6d 20 66 75 6e 63 74 69 6f 6e 73 20 2a 2f 0a um functions */.
9700: 0a 2f 2a 0a 20 20 20 20 20 54 68 65 73 65 20 66 ./*. These f
9710: 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 6e 6f 74 unctions are not
9720: 20 72 65 6c 61 74 65 64 20 74 6f 20 63 6f 6d 70 related to comp
9730: 72 65 73 73 69 6f 6e 20 62 75 74 20 61 72 65 20 ression but are
9740: 65 78 70 6f 72 74 65 64 0a 20 20 20 61 6e 79 77 exported. anyw
9750: 61 79 20 62 65 63 61 75 73 65 20 74 68 65 79 20 ay because they
9760: 6d 69 67 68 74 20 62 65 20 75 73 65 66 75 6c 20 might be useful
9770: 69 6e 20 61 70 70 6c 69 63 61 74 69 6f 6e 73 20 in applications
9780: 75 73 69 6e 67 20 74 68 65 0a 20 20 20 63 6f 6d using the. com
9790: 70 72 65 73 73 69 6f 6e 20 6c 69 62 72 61 72 79 pression library
97a0: 2e 0a 2a 2f 0a 0a 5a 45 58 54 45 52 4e 20 75 4c ..*/..ZEXTERN uL
97b0: 6f 6e 67 20 5a 45 58 50 4f 52 54 20 61 64 6c 65 ong ZEXPORT adle
97c0: 72 33 32 20 4f 46 28 28 75 4c 6f 6e 67 20 61 64 r32 OF((uLong ad
97d0: 6c 65 72 2c 20 63 6f 6e 73 74 20 42 79 74 65 66 ler, const Bytef
97e0: 20 2a 62 75 66 2c 20 75 49 6e 74 20 6c 65 6e 29 *buf, uInt len)
97f0: 29 3b 0a 0a 2f 2a 0a 20 20 20 20 20 55 70 64 61 );../*. Upda
9800: 74 65 20 61 20 72 75 6e 6e 69 6e 67 20 41 64 6c te a running Adl
9810: 65 72 2d 33 32 20 63 68 65 63 6b 73 75 6d 20 77 er-32 checksum w
9820: 69 74 68 20 74 68 65 20 62 79 74 65 73 20 62 75 ith the bytes bu
9830: 66 5b 30 2e 2e 6c 65 6e 2d 31 5d 20 61 6e 64 0a f[0..len-1] and.
9840: 20 20 20 72 65 74 75 72 6e 20 74 68 65 20 75 70 return the up
9850: 64 61 74 65 64 20 63 68 65 63 6b 73 75 6d 2e 20 dated checksum.
9860: 49 66 20 62 75 66 20 69 73 20 4e 55 4c 4c 2c 20 If buf is NULL,
9870: 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 72 65 this function re
9880: 74 75 72 6e 73 0a 20 20 20 74 68 65 20 72 65 71 turns. the req
9890: 75 69 72 65 64 20 69 6e 69 74 69 61 6c 20 76 61 uired initial va
98a0: 6c 75 65 20 66 6f 72 20 74 68 65 20 63 68 65 63 lue for the chec
98b0: 6b 73 75 6d 2e 0a 20 20 20 41 6e 20 41 64 6c 65 ksum.. An Adle
98c0: 72 2d 33 32 20 63 68 65 63 6b 73 75 6d 20 69 73 r-32 checksum is
98d0: 20 61 6c 6d 6f 73 74 20 61 73 20 72 65 6c 69 61 almost as relia
98e0: 62 6c 65 20 61 73 20 61 20 43 52 43 33 32 20 62 ble as a CRC32 b
98f0: 75 74 20 63 61 6e 20 62 65 20 63 6f 6d 70 75 74 ut can be comput
9900: 65 64 0a 20 20 20 6d 75 63 68 20 66 61 73 74 65 ed. much faste
9910: 72 2e 20 55 73 61 67 65 20 65 78 61 6d 70 6c 65 r. Usage example
9920: 3a 0a 0a 20 20 20 20 20 75 4c 6f 6e 67 20 61 64 :.. uLong ad
9930: 6c 65 72 20 3d 20 61 64 6c 65 72 33 32 28 30 4c ler = adler32(0L
9940: 2c 20 5a 5f 4e 55 4c 4c 2c 20 30 29 3b 0a 0a 20 , Z_NULL, 0);..
9950: 20 20 20 20 77 68 69 6c 65 20 28 72 65 61 64 5f while (read_
9960: 62 75 66 66 65 72 28 62 75 66 66 65 72 2c 20 6c buffer(buffer, l
9970: 65 6e 67 74 68 29 20 21 3d 20 45 4f 46 29 20 7b ength) != EOF) {
9980: 0a 20 20 20 20 20 20 20 61 64 6c 65 72 20 3d 20 . adler =
9990: 61 64 6c 65 72 33 32 28 61 64 6c 65 72 2c 20 62 adler32(adler, b
99a0: 75 66 66 65 72 2c 20 6c 65 6e 67 74 68 29 3b 0a uffer, length);.
99b0: 20 20 20 20 20 7d 0a 20 20 20 20 20 69 66 20 28 }. if (
99c0: 61 64 6c 65 72 20 21 3d 20 6f 72 69 67 69 6e 61 adler != origina
99d0: 6c 5f 61 64 6c 65 72 29 20 65 72 72 6f 72 28 29 l_adler) error()
99e0: 3b 0a 2a 2f 0a 0a 5a 45 58 54 45 52 4e 20 75 4c ;.*/..ZEXTERN uL
99f0: 6f 6e 67 20 5a 45 58 50 4f 52 54 20 63 72 63 33 ong ZEXPORT crc3
9a00: 32 20 20 20 4f 46 28 28 75 4c 6f 6e 67 20 63 72 2 OF((uLong cr
9a10: 63 2c 20 63 6f 6e 73 74 20 42 79 74 65 66 20 2a c, const Bytef *
9a20: 62 75 66 2c 20 75 49 6e 74 20 6c 65 6e 29 29 3b buf, uInt len));
9a30: 0a 2f 2a 0a 20 20 20 20 20 55 70 64 61 74 65 20 ./*. Update
9a40: 61 20 72 75 6e 6e 69 6e 67 20 63 72 63 20 77 69 a running crc wi
9a50: 74 68 20 74 68 65 20 62 79 74 65 73 20 62 75 66 th the bytes buf
9a60: 5b 30 2e 2e 6c 65 6e 2d 31 5d 20 61 6e 64 20 72 [0..len-1] and r
9a70: 65 74 75 72 6e 20 74 68 65 20 75 70 64 61 74 65 eturn the update
9a80: 64 0a 20 20 20 63 72 63 2e 20 49 66 20 62 75 66 d. crc. If buf
9a90: 20 69 73 20 4e 55 4c 4c 2c 20 74 68 69 73 20 66 is NULL, this f
9aa0: 75 6e 63 74 69 6f 6e 20 72 65 74 75 72 6e 73 20 unction returns
9ab0: 74 68 65 20 72 65 71 75 69 72 65 64 20 69 6e 69 the required ini
9ac0: 74 69 61 6c 20 76 61 6c 75 65 0a 20 20 20 66 6f tial value. fo
9ad0: 72 20 74 68 65 20 63 72 63 2e 20 50 72 65 2d 20 r the crc. Pre-
9ae0: 61 6e 64 20 70 6f 73 74 2d 63 6f 6e 64 69 74 69 and post-conditi
9af0: 6f 6e 69 6e 67 20 28 6f 6e 65 27 73 20 63 6f 6d oning (one's com
9b00: 70 6c 65 6d 65 6e 74 29 20 69 73 20 70 65 72 66 plement) is perf
9b10: 6f 72 6d 65 64 0a 20 20 20 77 69 74 68 69 6e 20 ormed. within
9b20: 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 73 6f this function so
9b30: 20 69 74 20 73 68 6f 75 6c 64 6e 27 74 20 62 65 it shouldn't be
9b40: 20 64 6f 6e 65 20 62 79 20 74 68 65 20 61 70 70 done by the app
9b50: 6c 69 63 61 74 69 6f 6e 2e 0a 20 20 20 55 73 61 lication.. Usa
9b60: 67 65 20 65 78 61 6d 70 6c 65 3a 0a 0a 20 20 20 ge example:..
9b70: 20 20 75 4c 6f 6e 67 20 63 72 63 20 3d 20 63 72 uLong crc = cr
9b80: 63 33 32 28 30 4c 2c 20 5a 5f 4e 55 4c 4c 2c 20 c32(0L, Z_NULL,
9b90: 30 29 3b 0a 0a 20 20 20 20 20 77 68 69 6c 65 20 0);.. while
9ba0: 28 72 65 61 64 5f 62 75 66 66 65 72 28 62 75 66 (read_buffer(buf
9bb0: 66 65 72 2c 20 6c 65 6e 67 74 68 29 20 21 3d 20 fer, length) !=
9bc0: 45 4f 46 29 20 7b 0a 20 20 20 20 20 20 20 63 72 EOF) {. cr
9bd0: 63 20 3d 20 63 72 63 33 32 28 63 72 63 2c 20 62 c = crc32(crc, b
9be0: 75 66 66 65 72 2c 20 6c 65 6e 67 74 68 29 3b 0a uffer, length);.
9bf0: 20 20 20 20 20 7d 0a 20 20 20 20 20 69 66 20 28 }. if (
9c00: 63 72 63 20 21 3d 20 6f 72 69 67 69 6e 61 6c 5f crc != original_
9c10: 63 72 63 29 20 65 72 72 6f 72 28 29 3b 0a 2a 2f crc) error();.*/
9c20: 0a 0a 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ...
9c30: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 76 61 /* va
9c40: 72 69 6f 75 73 20 68 61 63 6b 73 2c 20 64 6f 6e rious hacks, don
9c50: 27 74 20 6c 6f 6f 6b 20 3a 29 20 2a 2f 0a 0a 2f 't look :) */../
9c60: 2a 20 64 65 66 6c 61 74 65 49 6e 69 74 20 61 6e * deflateInit an
9c70: 64 20 69 6e 66 6c 61 74 65 49 6e 69 74 20 61 72 d inflateInit ar
9c80: 65 20 6d 61 63 72 6f 73 20 74 6f 20 61 6c 6c 6f e macros to allo
9c90: 77 20 63 68 65 63 6b 69 6e 67 20 74 68 65 20 7a w checking the z
9ca0: 6c 69 62 20 76 65 72 73 69 6f 6e 0a 20 2a 20 61 lib version. * a
9cb0: 6e 64 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 27 nd the compiler'
9cc0: 73 20 76 69 65 77 20 6f 66 20 7a 5f 73 74 72 65 s view of z_stre
9cd0: 61 6d 3a 0a 20 2a 2f 0a 23 69 66 6e 64 65 66 20 am:. */.#ifndef
9ce0: 4b 49 5f 47 5a 5f 4e 4f 5f 43 4f 4d 50 52 45 53 KI_GZ_NO_COMPRES
9cf0: 53 49 4f 4e 0d 0a 5a 45 58 54 45 52 4e 20 69 6e SION..ZEXTERN in
9d00: 74 20 5a 45 58 50 4f 52 54 20 64 65 66 6c 61 74 t ZEXPORT deflat
9d10: 65 49 6e 69 74 5f 20 4f 46 28 28 7a 5f 73 74 72 eInit_ OF((z_str
9d20: 65 61 6d 70 20 73 74 72 6d 2c 20 69 6e 74 20 6c eamp strm, int l
9d30: 65 76 65 6c 2c 0a 20 20 20 20 20 20 20 20 20 20 evel,.
9d40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9d50: 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e 73 74 const
9d60: 20 63 68 61 72 20 2a 76 65 72 73 69 6f 6e 2c 20 char *version,
9d70: 69 6e 74 20 73 74 72 65 61 6d 5f 73 69 7a 65 29 int stream_size)
9d80: 29 3b 0a 23 65 6e 64 69 66 20 2f 2a 20 4b 49 5f );.#endif /* KI_
9d90: 47 5a 5f 4e 4f 5f 43 4f 4d 50 52 45 53 53 49 4f GZ_NO_COMPRESSIO
9da0: 4e 20 2a 2f 0d 0a 5a 45 58 54 45 52 4e 20 69 6e N */..ZEXTERN in
9db0: 74 20 5a 45 58 50 4f 52 54 20 69 6e 66 6c 61 74 t ZEXPORT inflat
9dc0: 65 49 6e 69 74 5f 20 4f 46 28 28 7a 5f 73 74 72 eInit_ OF((z_str
9dd0: 65 61 6d 70 20 73 74 72 6d 2c 0a 20 20 20 20 20 eamp strm,.
9de0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9df0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9e00: 63 6f 6e 73 74 20 63 68 61 72 20 2a 76 65 72 73 const char *vers
9e10: 69 6f 6e 2c 20 69 6e 74 20 73 74 72 65 61 6d 5f ion, int stream_
9e20: 73 69 7a 65 29 29 3b 0a 23 69 66 6e 64 65 66 20 size));.#ifndef
9e30: 4b 49 5f 47 5a 5f 4e 4f 5f 43 4f 4d 50 52 45 53 KI_GZ_NO_COMPRES
9e40: 53 49 4f 4e 0d 0a 5a 45 58 54 45 52 4e 20 69 6e SION..ZEXTERN in
9e50: 74 20 5a 45 58 50 4f 52 54 20 64 65 66 6c 61 74 t ZEXPORT deflat
9e60: 65 49 6e 69 74 32 5f 20 4f 46 28 28 7a 5f 73 74 eInit2_ OF((z_st
9e70: 72 65 61 6d 70 20 73 74 72 6d 2c 20 69 6e 74 20 reamp strm, int
9e80: 20 6c 65 76 65 6c 2c 20 69 6e 74 20 20 6d 65 74 level, int met
9e90: 68 6f 64 2c 0a 20 20 20 20 20 20 20 20 20 20 20 hod,.
9ea0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9eb0: 20 20 20 20 20 20 20 20 20 20 20 69 6e 74 20 77 int w
9ec0: 69 6e 64 6f 77 42 69 74 73 2c 20 69 6e 74 20 6d indowBits, int m
9ed0: 65 6d 4c 65 76 65 6c 2c 0a 20 20 20 20 20 20 20 emLevel,.
9ee0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9ef0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
9f00: 6e 74 20 73 74 72 61 74 65 67 79 2c 20 63 6f 6e nt strategy, con
9f10: 73 74 20 63 68 61 72 20 2a 76 65 72 73 69 6f 6e st char *version
9f20: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ,.
9f30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9f40: 20 20 20 20 20 20 20 20 69 6e 74 20 73 74 72 65 int stre
9f50: 61 6d 5f 73 69 7a 65 29 29 3b 0a 23 65 6e 64 69 am_size));.#endi
9f60: 66 20 2f 2a 20 4b 49 5f 47 5a 5f 4e 4f 5f 43 4f f /* KI_GZ_NO_CO
9f70: 4d 50 52 45 53 53 49 4f 4e 20 2a 2f 0d 0a 5a 45 MPRESSION */..ZE
9f80: 58 54 45 52 4e 20 69 6e 74 20 5a 45 58 50 4f 52 XTERN int ZEXPOR
9f90: 54 20 69 6e 66 6c 61 74 65 49 6e 69 74 32 5f 20 T inflateInit2_
9fa0: 4f 46 28 28 7a 5f 73 74 72 65 61 6d 70 20 73 74 OF((z_streamp st
9fb0: 72 6d 2c 20 69 6e 74 20 20 77 69 6e 64 6f 77 42 rm, int windowB
9fc0: 69 74 73 2c 0a 20 20 20 20 20 20 20 20 20 20 20 its,.
9fd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9fe0: 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e 73 74 const
9ff0: 20 63 68 61 72 20 2a 76 65 72 73 69 6f 6e 2c 20 char *version,
a000: 69 6e 74 20 73 74 72 65 61 6d 5f 73 69 7a 65 29 int stream_size)
a010: 29 3b 0a 23 64 65 66 69 6e 65 20 64 65 66 6c 61 );.#define defla
a020: 74 65 49 6e 69 74 28 73 74 72 6d 2c 20 6c 65 76 teInit(strm, lev
a030: 65 6c 29 20 5c 0a 20 20 20 20 20 20 20 20 64 65 el) \. de
a040: 66 6c 61 74 65 49 6e 69 74 5f 28 28 73 74 72 6d flateInit_((strm
a050: 29 2c 20 28 6c 65 76 65 6c 29 2c 20 20 20 20 20 ), (level),
a060: 20 20 5a 4c 49 42 5f 56 45 52 53 49 4f 4e 2c 20 ZLIB_VERSION,
a070: 73 69 7a 65 6f 66 28 7a 5f 73 74 72 65 61 6d 29 sizeof(z_stream)
a080: 29 0a 23 64 65 66 69 6e 65 20 69 6e 66 6c 61 74 ).#define inflat
a090: 65 49 6e 69 74 28 73 74 72 6d 29 20 5c 0a 20 20 eInit(strm) \.
a0a0: 20 20 20 20 20 20 69 6e 66 6c 61 74 65 49 6e 69 inflateIni
a0b0: 74 5f 28 28 73 74 72 6d 29 2c 20 20 20 20 20 20 t_((strm),
a0c0: 20 20 20 20 20 20 20 20 20 20 5a 4c 49 42 5f 56 ZLIB_V
a0d0: 45 52 53 49 4f 4e 2c 20 73 69 7a 65 6f 66 28 7a ERSION, sizeof(z
a0e0: 5f 73 74 72 65 61 6d 29 29 0a 23 64 65 66 69 6e _stream)).#defin
a0f0: 65 20 64 65 66 6c 61 74 65 49 6e 69 74 32 28 73 e deflateInit2(s
a100: 74 72 6d 2c 20 6c 65 76 65 6c 2c 20 6d 65 74 68 trm, level, meth
a110: 6f 64 2c 20 77 69 6e 64 6f 77 42 69 74 73 2c 20 od, windowBits,
a120: 6d 65 6d 4c 65 76 65 6c 2c 20 73 74 72 61 74 65 memLevel, strate
a130: 67 79 29 20 5c 0a 20 20 20 20 20 20 20 20 64 65 gy) \. de
a140: 66 6c 61 74 65 49 6e 69 74 32 5f 28 28 73 74 72 flateInit2_((str
a150: 6d 29 2c 28 6c 65 76 65 6c 29 2c 28 6d 65 74 68 m),(level),(meth
a160: 6f 64 29 2c 28 77 69 6e 64 6f 77 42 69 74 73 29 od),(windowBits)
a170: 2c 28 6d 65 6d 4c 65 76 65 6c 29 2c 5c 0a 20 20 ,(memLevel),\.
a180: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a190: 20 20 20 20 28 73 74 72 61 74 65 67 79 29 2c 20 (strategy),
a1a0: 20 20 20 20 20 20 20 20 20 20 5a 4c 49 42 5f 56 ZLIB_V
a1b0: 45 52 53 49 4f 4e 2c 20 73 69 7a 65 6f 66 28 7a ERSION, sizeof(z
a1c0: 5f 73 74 72 65 61 6d 29 29 0a 23 64 65 66 69 6e _stream)).#defin
a1d0: 65 20 69 6e 66 6c 61 74 65 49 6e 69 74 32 28 73 e inflateInit2(s
a1e0: 74 72 6d 2c 20 77 69 6e 64 6f 77 42 69 74 73 29 trm, windowBits)
a1f0: 20 5c 0a 20 20 20 20 20 20 20 20 69 6e 66 6c 61 \. infla
a200: 74 65 49 6e 69 74 32 5f 28 28 73 74 72 6d 29 2c teInit2_((strm),
a210: 20 28 77 69 6e 64 6f 77 42 69 74 73 29 2c 20 5a (windowBits), Z
a220: 4c 49 42 5f 56 45 52 53 49 4f 4e 2c 20 73 69 7a LIB_VERSION, siz
a230: 65 6f 66 28 7a 5f 73 74 72 65 61 6d 29 29 0a 0a eof(z_stream))..
a240: 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 5f 5a .#if !defined(_Z
a250: 5f 55 54 49 4c 5f 48 29 20 26 26 20 21 64 65 66 _UTIL_H) && !def
a260: 69 6e 65 64 28 4e 4f 5f 44 55 4d 4d 59 5f 44 45 ined(NO_DUMMY_DE
a270: 43 4c 29 0a 20 20 20 20 73 74 72 75 63 74 20 69 CL). struct i
a280: 6e 74 65 72 6e 61 6c 5f 73 74 61 74 65 20 7b 69 nternal_state {i
a290: 6e 74 20 64 75 6d 6d 79 3b 7d 3b 20 2f 2a 20 68 nt dummy;}; /* h
a2a0: 61 63 6b 20 66 6f 72 20 62 75 67 67 79 20 63 6f ack for buggy co
a2b0: 6d 70 69 6c 65 72 73 20 2a 2f 0a 23 65 6e 64 69 mpilers */.#endi
a2c0: 66 0a 0a 5a 45 58 54 45 52 4e 20 63 6f 6e 73 74 f..ZEXTERN const
a2d0: 20 63 68 61 72 20 20 20 2a 20 5a 45 58 50 4f 52 char * ZEXPOR
a2e0: 54 20 7a 45 72 72 6f 72 20 20 20 20 20 20 20 20 T zError
a2f0: 20 20 20 4f 46 28 28 69 6e 74 20 65 72 72 29 29 OF((int err))
a300: 3b 0a 5a 45 58 54 45 52 4e 20 69 6e 74 20 20 20 ;.ZEXTERN int
a310: 20 20 20 20 20 20 20 20 20 5a 45 58 50 4f 52 54 ZEXPORT
a320: 20 69 6e 66 6c 61 74 65 53 79 6e 63 50 6f 69 6e inflateSyncPoin
a330: 74 20 4f 46 28 28 7a 5f 73 74 72 65 61 6d 70 20 t OF((z_streamp
a340: 7a 29 29 3b 0a 5a 45 58 54 45 52 4e 20 63 6f 6e z));.ZEXTERN con
a350: 73 74 20 75 4c 6f 6e 67 66 20 2a 20 5a 45 58 50 st uLongf * ZEXP
a360: 4f 52 54 20 67 65 74 5f 63 72 63 5f 74 61 62 6c ORT get_crc_tabl
a370: 65 20 20 20 20 4f 46 28 28 76 6f 69 64 29 29 3b e OF((void));
a380: 0a 0a 23 69 66 64 65 66 20 5f 5f 63 70 6c 75 73 ..#ifdef __cplus
a390: 70 6c 75 73 0a 7d 0a 23 65 6e 64 69 66 0a 0a 23 plus.}.#endif..#
a3a0: 65 6e 64 69 66 20 2f 2a 20 5f 5a 4c 49 42 5f 48 endif /* _ZLIB_H
a3b0: 20 2a 2f 0a */.