zlib.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*
  2. * This file is derived from zlib.h and zconf.h from the zlib-1.2.3
  3. * distribution by Jean-loup Gailly and Mark Adler, with some additions
  4. * by Paul Mackerras to aid in implementing Deflate compression and
  5. * decompression for PPP packets.
  6. */
  7. /*
  8. * ==FILEVERSION 960122==
  9. *
  10. * This marker is used by the Linux installation script to determine
  11. * whether an up-to-date version of this file is already installed.
  12. */
  13. /* zlib.h -- interface of the 'zlib' general purpose compression library
  14. version 1.2.3, July 18th, 2005
  15. Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
  16. This software is provided 'as-is', without any express or implied
  17. warranty. In no event will the authors be held liable for any damages
  18. arising from the use of this software.
  19. Permission is granted to anyone to use this software for any purpose,
  20. including commercial applications, and to alter it and redistribute it
  21. freely, subject to the following restrictions:
  22. 1. The origin of this software must not be misrepresented; you must not
  23. claim that you wrote the original software. If you use this software
  24. in a product, an acknowledgment in the product documentation would be
  25. appreciated but is not required.
  26. 2. Altered source versions must be plainly marked as such, and must not be
  27. misrepresented as being the original software.
  28. 3. This notice may not be removed or altered from any source distribution.
  29. Jean-loup Gailly Mark Adler
  30. jloup@gzip.org madler@alumni.caltech.edu
  31. The data format used by the zlib library is described by RFCs (Request for
  32. Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
  33. (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
  34. */
  35. #ifndef ZLIB_H
  36. #define ZLIB_H
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. #define ZLIB_VERSION "1.2.3"
  41. #define ZLIB_VERNUM 0x1230
  42. /* #include "zconf.h" */ /* included directly here */
  43. /* zconf.h -- configuration of the zlib compression library
  44. * Copyright (C) 1995-2005 Jean-loup Gailly.
  45. * For conditions of distribution and use, see copyright notice in zlib.h
  46. */
  47. /* Begin of new zconf.h */
  48. /*
  49. * If you *really* need a unique prefix for all types and library functions,
  50. * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
  51. */
  52. #ifdef Z_PREFIX
  53. # define deflateInit_ z_deflateInit_
  54. # define deflate z_deflate
  55. # define deflateEnd z_deflateEnd
  56. # define inflateInit_ z_inflateInit_
  57. # define inflate z_inflate
  58. # define inflateEnd z_inflateEnd
  59. # define deflateInit2_ z_deflateInit2_
  60. # define deflateSetDictionary z_deflateSetDictionary
  61. # define deflateCopy z_deflateCopy
  62. # define deflateReset z_deflateReset
  63. # define deflateParams z_deflateParams
  64. # define deflateBound z_deflateBound
  65. # define deflatePrime z_deflatePrime
  66. # define inflateInit2_ z_inflateInit2_
  67. # define inflateSetDictionary z_inflateSetDictionary
  68. # define inflateSync z_inflateSync
  69. # define inflateSyncPoint z_inflateSyncPoint
  70. # define inflateCopy z_inflateCopy
  71. # define inflateReset z_inflateReset
  72. # define inflateBack z_inflateBack
  73. # define inflateBackEnd z_inflateBackEnd
  74. # define compress z_compress
  75. # define compress2 z_compress2
  76. # define compressBound z_compressBound
  77. # define uncompress z_uncompress
  78. # define adler32 z_adler32
  79. # define crc32 z_crc32
  80. # define get_crc_table z_get_crc_table
  81. # define zError z_zError
  82. # define alloc_func z_alloc_func
  83. # define free_func z_free_func
  84. # define in_func z_in_func
  85. # define out_func z_out_func
  86. # define Byte z_Byte
  87. # define uInt z_uInt
  88. # define uLong z_uLong
  89. # define Bytef z_Bytef
  90. # define charf z_charf
  91. # define intf z_intf
  92. # define uIntf z_uIntf
  93. # define uLongf z_uLongf
  94. # define voidpf z_voidpf
  95. # define voidp z_voidp
  96. #endif
  97. #if defined(__MSDOS__) && !defined(MSDOS)
  98. # define MSDOS
  99. #endif
  100. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  101. # define OS2
  102. #endif
  103. #if defined(_WINDOWS) && !defined(WINDOWS)
  104. # define WINDOWS
  105. #endif
  106. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  107. # ifndef WIN32
  108. # define WIN32
  109. # endif
  110. #endif
  111. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  112. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  113. # ifndef SYS16BIT
  114. # define SYS16BIT
  115. # endif
  116. # endif
  117. #endif
  118. /*
  119. * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
  120. * than 64k bytes at a time (needed on systems with 16-bit int).
  121. */
  122. #ifdef SYS16BIT
  123. # define MAXSEG_64K
  124. #endif
  125. #ifdef MSDOS
  126. # define UNALIGNED_OK
  127. #endif
  128. #ifdef __STDC_VERSION__
  129. # ifndef STDC
  130. # define STDC
  131. # endif
  132. # if __STDC_VERSION__ >= 199901L
  133. # ifndef STDC99
  134. # define STDC99
  135. # endif
  136. # endif
  137. #endif
  138. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  139. # define STDC
  140. #endif
  141. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  142. # define STDC
  143. #endif
  144. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  145. # define STDC
  146. #endif
  147. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  148. # define STDC
  149. #endif
  150. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  151. # define STDC
  152. #endif
  153. #ifndef STDC
  154. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  155. # define const /* note: need a more gentle solution here */
  156. # endif
  157. #endif
  158. /* Some Mac compilers merge all .h files incorrectly: */
  159. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  160. # define NO_DUMMY_DECL
  161. #endif
  162. /* Maximum value for memLevel in deflateInit2 */
  163. #ifndef MAX_MEM_LEVEL
  164. # ifdef MAXSEG_64K
  165. # define MAX_MEM_LEVEL 8
  166. # else
  167. # define MAX_MEM_LEVEL 9
  168. # endif
  169. #endif
  170. /* Maximum value for windowBits in deflateInit2 and inflateInit2.
  171. * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
  172. * created by gzip. (Files created by minigzip can still be extracted by
  173. * gzip.)
  174. */
  175. #ifndef MAX_WBITS
  176. # define MAX_WBITS 15 /* 32K LZ77 window */
  177. #endif
  178. /* The memory requirements for deflate are (in bytes):
  179. (1 << (windowBits+2)) + (1 << (memLevel+9))
  180. that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
  181. plus a few kilobytes for small objects. For example, if you want to reduce
  182. the default memory requirements from 256K to 128K, compile with
  183. make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
  184. Of course this will generally degrade compression (there's no free lunch).
  185. The memory requirements for inflate are (in bytes) 1 << windowBits
  186. that is, 32K for windowBits=15 (default value) plus a few kilobytes
  187. for small objects.
  188. */
  189. /* Type declarations */
  190. #ifndef OF /* function prototypes */
  191. # ifdef STDC
  192. # define OF(args) args
  193. # else
  194. # define OF(args) ()
  195. # endif
  196. #endif
  197. /* The following definitions for FAR are needed only for MSDOS mixed
  198. * model programming (small or medium model with some far allocations).
  199. * This was tested only with MSC; for other MSDOS compilers you may have
  200. * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
  201. * just define FAR to be empty.
  202. */
  203. #ifdef SYS16BIT
  204. # if defined(M_I86SM) || defined(M_I86MM)
  205. /* MSC small or medium model */
  206. # define SMALL_MEDIUM
  207. # ifdef _MSC_VER
  208. # define FAR _far
  209. # else
  210. # define FAR far
  211. # endif
  212. # endif
  213. # if (defined(__SMALL__) || defined(__MEDIUM__))
  214. /* Turbo C small or medium model */
  215. # define SMALL_MEDIUM
  216. # ifdef __BORLANDC__
  217. # define FAR _far
  218. # else
  219. # define FAR far
  220. # endif
  221. # endif
  222. #endif
  223. #if defined(WINDOWS) || defined(WIN32)
  224. /* If building or using zlib as a DLL, define ZLIB_DLL.
  225. * This is not mandatory, but it offers a little performance increase.
  226. */
  227. # ifdef ZLIB_DLL
  228. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  229. # ifdef ZLIB_INTERNAL
  230. # define ZEXTERN extern __declspec(dllexport)
  231. # else
  232. # define ZEXTERN extern __declspec(dllimport)
  233. # endif
  234. # endif
  235. # endif /* ZLIB_DLL */
  236. /* If building or using zlib with the WINAPI/WINAPIV calling convention,
  237. * define ZLIB_WINAPI.
  238. * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
  239. */
  240. # ifdef ZLIB_WINAPI
  241. # ifdef FAR
  242. # undef FAR
  243. # endif
  244. # include <windows.h>
  245. /* No need for _export, use ZLIB.DEF instead. */
  246. /* For complete Windows compatibility, use WINAPI, not __stdcall. */
  247. # define ZEXPORT WINAPI
  248. # ifdef WIN32
  249. # define ZEXPORTVA WINAPIV
  250. # else
  251. # define ZEXPORTVA FAR CDECL
  252. # endif
  253. # endif
  254. #endif
  255. #if defined (__BEOS__)
  256. # ifdef ZLIB_DLL
  257. # ifdef ZLIB_INTERNAL
  258. # define ZEXPORT __declspec(dllexport)
  259. # define ZEXPORTVA __declspec(dllexport)
  260. # else
  261. # define ZEXPORT __declspec(dllimport)
  262. # define ZEXPORTVA __declspec(dllimport)
  263. # endif
  264. # endif
  265. #endif
  266. #ifndef ZEXTERN
  267. # define ZEXTERN extern
  268. #endif
  269. #ifndef ZEXPORT
  270. # define ZEXPORT
  271. #endif
  272. #ifndef ZEXPORTVA
  273. # define ZEXPORTVA
  274. #endif
  275. #ifndef FAR
  276. # define FAR
  277. #endif
  278. #if !defined(__MACTYPES__)
  279. typedef unsigned char Byte; /* 8 bits */
  280. #endif
  281. typedef unsigned int uInt; /* 16 bits or more */
  282. typedef unsigned long uLong; /* 32 bits or more */
  283. #ifdef SMALL_MEDIUM
  284. /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
  285. # define Bytef Byte FAR
  286. #else
  287. typedef Byte FAR Bytef;
  288. #endif
  289. typedef char FAR charf;
  290. typedef int FAR intf;
  291. typedef uInt FAR uIntf;
  292. typedef uLong FAR uLongf;
  293. #ifdef STDC
  294. typedef void const *voidpc;
  295. typedef void FAR *voidpf;
  296. typedef void *voidp;
  297. #else
  298. typedef Byte const *voidpc;
  299. typedef Byte FAR *voidpf;
  300. typedef Byte *voidp;
  301. #endif
  302. # ifdef VMS
  303. # include <unixio.h> /* for off_t */
  304. # endif
  305. # define z_off_t off_t
  306. #ifndef SEEK_SET
  307. # define SEEK_SET 0 /* Seek from beginning of file. */
  308. # define SEEK_CUR 1 /* Seek from current position. */
  309. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  310. #endif
  311. #ifndef z_off_t
  312. # define z_off_t long
  313. #endif
  314. #if defined(__OS400__)
  315. # define NO_vsnprintf
  316. #endif
  317. #if defined(__MVS__)
  318. # define NO_vsnprintf
  319. # ifdef FAR
  320. # undef FAR
  321. # endif
  322. #endif
  323. /* MVS linker does not support external names larger than 8 bytes */
  324. #if defined(__MVS__)
  325. # pragma map(deflateInit_,"DEIN")
  326. # pragma map(deflateInit2_,"DEIN2")
  327. # pragma map(deflateEnd,"DEEND")
  328. # pragma map(deflateBound,"DEBND")
  329. # pragma map(inflateInit_,"ININ")
  330. # pragma map(inflateInit2_,"ININ2")
  331. # pragma map(inflateEnd,"INEND")
  332. # pragma map(inflateSync,"INSY")
  333. # pragma map(inflateSetDictionary,"INSEDI")
  334. # pragma map(compressBound,"CMBND")
  335. # pragma map(inflate_table,"INTABL")
  336. # pragma map(inflate_fast,"INFA")
  337. # pragma map(inflate_copyright,"INCOPY")
  338. #endif
  339. /* End of new zconf.h */
  340. /*
  341. The 'zlib' compression library provides in-memory compression and
  342. decompression functions, including integrity checks of the uncompressed
  343. data. This version of the library supports only one compression method
  344. (deflation) but other algorithms will be added later and will have the same
  345. stream interface.
  346. Compression can be done in a single step if the buffers are large
  347. enough (for example if an input file is mmap'ed), or can be done by
  348. repeated calls of the compression function. In the latter case, the
  349. application must provide more input and/or consume the output
  350. (providing more output space) before each call.
  351. The compressed data format used by default by the in-memory functions is
  352. the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
  353. around a deflate stream, which is itself documented in RFC 1951.
  354. The library also supports reading and writing files in gzip (.gz) format
  355. with an interface similar to that of stdio using the functions that start
  356. with "gz". The gzip format is different from the zlib format. gzip is a
  357. gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
  358. This library can optionally read and write gzip streams in memory as well.
  359. The zlib format was designed to be compact and fast for use in memory
  360. and on communications channels. The gzip format was designed for single-
  361. file compression on file systems, has a larger header than zlib to maintain
  362. directory information, and uses a different, slower check method than zlib.
  363. The library does not install any signal handler. The decoder checks
  364. the consistency of the compressed data, so the library should never
  365. crash even in case of corrupted input.
  366. */
  367. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  368. typedef void (*free_func) OF((voidpf opaque, voidpf address, uInt size));
  369. typedef void (*cb_func) OF((Bytef *buf, uInt len));
  370. struct internal_state;
  371. typedef struct z_stream_s {
  372. Bytef *next_in; /* next input byte */
  373. uInt avail_in; /* number of bytes available at next_in */
  374. uLong total_in; /* total nb of input bytes read so far */
  375. Bytef *next_out; /* next output byte should be put there */
  376. uInt avail_out; /* remaining free space at next_out */
  377. uLong total_out; /* total nb of bytes output so far */
  378. char *msg; /* last error message, NULL if no error */
  379. struct internal_state FAR *state; /* not visible by applications */
  380. alloc_func zalloc; /* used to allocate the internal state */
  381. free_func zfree; /* used to free the internal state */
  382. voidpf opaque; /* private data object passed to zalloc and zfree */
  383. int data_type; /* best guess about the data type:
  384. binary or text */
  385. cb_func outcb; /* called regularly just before blocks of output */
  386. uLong adler; /* adler32 value of the uncompressed data */
  387. uLong reserved; /* reserved for future use */
  388. } z_stream;
  389. typedef z_stream FAR *z_streamp;
  390. /*
  391. gzip header information passed to and from zlib routines. See RFC 1952
  392. for more details on the meanings of these fields.
  393. */
  394. typedef struct gz_header_s {
  395. int text; /* true if compressed data believed to be text */
  396. uLong time; /* modification time */
  397. int xflags; /* extra flags (not used when writing a gzip file) */
  398. int os; /* operating system */
  399. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  400. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  401. uInt extra_max; /* space at extra (only when reading header) */
  402. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  403. uInt name_max; /* space at name (only when reading header) */
  404. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  405. uInt comm_max; /* space at comment (only when reading header) */
  406. int hcrc; /* true if there was or will be a header crc */
  407. int done; /* true when done reading gzip header (not used
  408. when writing a gzip file) */
  409. } gz_header;
  410. typedef gz_header FAR *gz_headerp;
  411. /* constants */
  412. #define Z_NO_FLUSH 0
  413. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  414. #define Z_SYNC_FLUSH 2
  415. #define Z_FULL_FLUSH 3
  416. #define Z_FINISH 4
  417. #define Z_BLOCK 5
  418. /* Allowed flush values; see deflate() and inflate() below for details */
  419. #define Z_OK 0
  420. #define Z_STREAM_END 1
  421. #define Z_NEED_DICT 2
  422. #define Z_ERRNO (-1)
  423. #define Z_STREAM_ERROR (-2)
  424. #define Z_DATA_ERROR (-3)
  425. #define Z_MEM_ERROR (-4)
  426. #define Z_BUF_ERROR (-5)
  427. #define Z_VERSION_ERROR (-6)
  428. /* Return codes for the compression/decompression functions. Negative
  429. * values are errors, positive values are used for special but normal events.
  430. */
  431. #define Z_NO_COMPRESSION 0
  432. #define Z_BEST_SPEED 1
  433. #define Z_BEST_COMPRESSION 9
  434. #define Z_DEFAULT_COMPRESSION (-1)
  435. /* compression levels */
  436. #define Z_FILTERED 1
  437. #define Z_HUFFMAN_ONLY 2
  438. #define Z_RLE 3
  439. #define Z_FIXED 4
  440. #define Z_DEFAULT_STRATEGY 0
  441. /* compression strategy; see deflateInit2() below for details */
  442. #define Z_BINARY 0
  443. #define Z_TEXT 1
  444. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  445. #define Z_UNKNOWN 2
  446. /* Possible values of the data_type field (though see inflate()) */
  447. #define Z_DEFLATED 8
  448. /* The deflate compression method (the only one supported in this version) */
  449. #define Z_NULL (void *)0 /* for initializing zalloc, zfree, opaque */
  450. /* basic functions */
  451. /* The application can compare zlibVersion and ZLIB_VERSION for consistency.
  452. If the first character differs, the library code actually used is
  453. not compatible with the zlib.h header file used by the application.
  454. This check is automatically made by deflateInit and inflateInit.
  455. */
  456. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  457. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  458. const char *version, int stream_size));
  459. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  460. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  461. int windowBits, int memLevel,
  462. int strategy, const char *version,
  463. int stream_size));
  464. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  465. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  466. const Bytef *dictionary,
  467. uInt dictLength));
  468. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  469. gz_headerp head));
  470. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  471. int bits,
  472. int value));
  473. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  474. int level,
  475. int strategy));
  476. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  477. int good_length,
  478. int max_lazy,
  479. int nice_length,
  480. int max_chain));
  481. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  482. uLong sourceLen));
  483. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  484. z_streamp source));
  485. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  486. const char *version, int stream_size));
  487. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  488. /*
  489. inflate decompresses as much data as possible, and stops when the input
  490. buffer becomes empty or the output buffer becomes full. It may introduce
  491. some output latency (reading input without producing any output) except when
  492. forced to flush.
  493. The detailed semantics are as follows. inflate performs one or both of the
  494. following actions:
  495. - Decompress more input starting at next_in and update next_in and avail_in
  496. accordingly. If not all input can be processed (because there is not
  497. enough room in the output buffer), next_in is updated and processing
  498. will resume at this point for the next call of inflate().
  499. - Provide more output starting at next_out and update next_out and avail_out
  500. accordingly. inflate() provides as much output as possible, until there
  501. is no more input data or no more space in the output buffer (see below
  502. about the flush parameter).
  503. Before the call of inflate(), the application should ensure that at least
  504. one of the actions is possible, by providing more input and/or consuming
  505. more output, and updating the next_* and avail_* values accordingly.
  506. The application can consume the uncompressed output when it wants, for
  507. example when the output buffer is full (avail_out == 0), or after each
  508. call of inflate(). If inflate returns Z_OK and with zero avail_out, it
  509. must be called again after making room in the output buffer because there
  510. might be more output pending.
  511. The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
  512. Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
  513. output as possible to the output buffer. Z_BLOCK requests that inflate() stop
  514. if and when it gets to the next deflate block boundary. When decoding the
  515. zlib or gzip format, this will cause inflate() to return immediately after
  516. the header and before the first block. When doing a raw inflate, inflate()
  517. will go ahead and process the first block, and will return when it gets to
  518. the end of that block, or when it runs out of data.
  519. The Z_BLOCK option assists in appending to or combining deflate streams.
  520. Also to assist in this, on return inflate() will set strm->data_type to the
  521. number of unused bits in the last byte taken from strm->next_in, plus 64
  522. if inflate() is currently decoding the last block in the deflate stream,
  523. plus 128 if inflate() returned immediately after decoding an end-of-block
  524. code or decoding the complete header up to just before the first byte of the
  525. deflate stream. The end-of-block will not be indicated until all of the
  526. uncompressed data from that block has been written to strm->next_out. The
  527. number of unused bits may in general be greater than seven, except when
  528. bit 7 of data_type is set, in which case the number of unused bits will be
  529. less than eight.
  530. inflate() should normally be called until it returns Z_STREAM_END or an
  531. error. However if all decompression is to be performed in a single step
  532. (a single call of inflate), the parameter flush should be set to
  533. Z_FINISH. In this case all pending input is processed and all pending
  534. output is flushed; avail_out must be large enough to hold all the
  535. uncompressed data. (The size of the uncompressed data may have been saved
  536. by the compressor for this purpose.) The next operation on this stream must
  537. be inflateEnd to deallocate the decompression state. The use of Z_FINISH
  538. is never required, but can be used to inform inflate that a faster approach
  539. may be used for the single inflate() call.
  540. In this implementation, inflate() always flushes as much output as
  541. possible to the output buffer, and always uses the faster approach on the
  542. first call. So the only effect of the flush parameter in this implementation
  543. is on the return value of inflate(), as noted below, or when it returns early
  544. because Z_BLOCK is used.
  545. If a preset dictionary is needed after this call (see inflateSetDictionary
  546. below), inflate sets strm->adler to the adler32 checksum of the dictionary
  547. chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
  548. strm->adler to the adler32 checksum of all output produced so far (that is,
  549. total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
  550. below. At the end of the stream, inflate() checks that its computed adler32
  551. checksum is equal to that saved by the compressor and returns Z_STREAM_END
  552. only if the checksum is correct.
  553. inflate() will decompress and check either zlib-wrapped or gzip-wrapped
  554. deflate data. The header type is detected automatically. Any information
  555. contained in the gzip header is not retained, so applications that need that
  556. information should instead use raw inflate, see inflateInit2() below, or
  557. inflateBack() and perform their own processing of the gzip header and
  558. trailer.
  559. inflate() returns Z_OK if some progress has been made (more input processed
  560. or more output produced), Z_STREAM_END if the end of the compressed data has
  561. been reached and all uncompressed output has been produced, Z_NEED_DICT if a
  562. preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
  563. corrupted (input stream not conforming to the zlib format or incorrect check
  564. value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
  565. if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
  566. Z_BUF_ERROR if no progress is possible or if there was not enough room in the
  567. output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
  568. inflate() can be called again with more input and more output space to
  569. continue decompressing. If Z_DATA_ERROR is returned, the application may then
  570. call inflateSync() to look for a good compression block if a partial recovery
  571. of the data is desired.
  572. */
  573. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  574. /*
  575. All dynamically allocated data structures for this stream are freed.
  576. This function discards any unprocessed input and does not flush any
  577. pending output.
  578. inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
  579. was inconsistent. In the error case, msg may be set but then points to a
  580. static string (which must not be deallocated).
  581. */
  582. /* Advanced functions */
  583. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  584. /* utility functions */
  585. /*
  586. The following utility functions are implemented on top of the
  587. basic stream-oriented functions. To simplify the interface, some
  588. default options are assumed (compression level and memory usage,
  589. standard memory allocation functions). The source code of these
  590. utility functions can easily be modified if you need special options.
  591. */
  592. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  593. /*
  594. Update a running Adler-32 checksum with the bytes buf[0..len-1] and
  595. return the updated checksum. If buf is NULL, this function returns
  596. the required initial value for the checksum.
  597. An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
  598. much faster. Usage example:
  599. uLong adler = adler32(0L, Z_NULL, 0);
  600. while (read_buffer(buffer, length) != EOF) {
  601. adler = adler32(adler, buffer, length);
  602. }
  603. if (adler != original_adler) error();
  604. */
  605. /*
  606. Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
  607. and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
  608. each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
  609. seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
  610. */
  611. ZEXTERN uInt ZEXPORT crc32 OF((uInt crc, const Bytef *buf, uInt len));
  612. /*
  613. Update a running CRC-32 with the bytes buf[0..len-1] and return the
  614. updated CRC-32. If buf is NULL, this function returns the required initial
  615. value for the for the crc. Pre- and post-conditioning (one's complement) is
  616. performed within this function so it shouldn't be done by the application.
  617. Usage example:
  618. uLong crc = crc32(0L, Z_NULL, 0);
  619. while (read_buffer(buffer, length) != EOF) {
  620. crc = crc32(crc, buffer, length);
  621. }
  622. if (crc != original_crc) error();
  623. */
  624. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  625. const char *version, int stream_size));
  626. #define inflateInit(strm) \
  627. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  628. #define inflateInit2(strm, windowBits) \
  629. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  630. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  631. struct internal_state {int dummy;}; /* hack for buggy compilers */
  632. #endif
  633. extern void *gzalloc(void *, unsigned, unsigned);
  634. extern void gzfree(void *, void *, unsigned);
  635. #ifdef __cplusplus
  636. }
  637. #endif
  638. #endif /* ZLIB_H */