zlib.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /* zlib.h -- interface of the 'zlib' general purpose compression library
  2. Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
  3. This software is provided 'as-is', without any express or implied
  4. warranty. In no event will the authors be held liable for any damages
  5. arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it
  8. freely, subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not
  10. claim that you wrote the original software. If you use this software
  11. in a product, an acknowledgment in the product documentation would be
  12. appreciated but is not required.
  13. 2. Altered source versions must be plainly marked as such, and must not be
  14. misrepresented as being the original software.
  15. 3. This notice may not be removed or altered from any source distribution.
  16. Jean-loup Gailly Mark Adler
  17. jloup@gzip.org madler@alumni.caltech.edu
  18. The data format used by the zlib library is described by RFCs (Request for
  19. Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
  20. (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
  21. */
  22. #ifndef _ZLIB_H
  23. #define _ZLIB_H
  24. #include <linux/zconf.h>
  25. /* zlib deflate based on ZLIB_VERSION "1.1.3" */
  26. /* zlib inflate based on ZLIB_VERSION "1.2.3" */
  27. /*
  28. This is a modified version of zlib for use inside the Linux kernel.
  29. The main changes are to perform all memory allocation in advance.
  30. Inflation Changes:
  31. * Z_PACKET_FLUSH is added and used by ppp_deflate. Before returning
  32. this checks there is no more input data available and the next data
  33. is a STORED block. It also resets the mode to be read for the next
  34. data, all as per PPP requirements.
  35. * Addition of zlib_inflateIncomp which copies incompressible data into
  36. the history window and adjusts the accoutning without calling
  37. zlib_inflate itself to inflate the data.
  38. */
  39. /*
  40. The 'zlib' compression library provides in-memory compression and
  41. decompression functions, including integrity checks of the uncompressed
  42. data. This version of the library supports only one compression method
  43. (deflation) but other algorithms will be added later and will have the same
  44. stream interface.
  45. Compression can be done in a single step if the buffers are large
  46. enough (for example if an input file is mmap'ed), or can be done by
  47. repeated calls of the compression function. In the latter case, the
  48. application must provide more input and/or consume the output
  49. (providing more output space) before each call.
  50. The compressed data format used by default by the in-memory functions is
  51. the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
  52. around a deflate stream, which is itself documented in RFC 1951.
  53. The library also supports reading and writing files in gzip (.gz) format
  54. with an interface similar to that of stdio.
  55. The zlib format was designed to be compact and fast for use in memory
  56. and on communications channels. The gzip format was designed for single-
  57. file compression on file systems, has a larger header than zlib to maintain
  58. directory information, and uses a different, slower check method than zlib.
  59. The library does not install any signal handler. The decoder checks
  60. the consistency of the compressed data, so the library should never
  61. crash even in case of corrupted input.
  62. */
  63. struct internal_state;
  64. typedef struct z_stream_s {
  65. Byte *next_in; /* next input byte */
  66. uInt avail_in; /* number of bytes available at next_in */
  67. uLong total_in; /* total nb of input bytes read so far */
  68. Byte *next_out; /* next output byte should be put there */
  69. uInt avail_out; /* remaining free space at next_out */
  70. uLong total_out; /* total nb of bytes output so far */
  71. char *msg; /* last error message, NULL if no error */
  72. struct internal_state *state; /* not visible by applications */
  73. void *workspace; /* memory allocated for this stream */
  74. int data_type; /* best guess about the data type: ascii or binary */
  75. uLong adler; /* adler32 value of the uncompressed data */
  76. uLong reserved; /* reserved for future use */
  77. } z_stream;
  78. typedef z_stream *z_streamp;
  79. /*
  80. The application must update next_in and avail_in when avail_in has
  81. dropped to zero. It must update next_out and avail_out when avail_out
  82. has dropped to zero. The application must initialize zalloc, zfree and
  83. opaque before calling the init function. All other fields are set by the
  84. compression library and must not be updated by the application.
  85. The opaque value provided by the application will be passed as the first
  86. parameter for calls of zalloc and zfree. This can be useful for custom
  87. memory management. The compression library attaches no meaning to the
  88. opaque value.
  89. zalloc must return NULL if there is not enough memory for the object.
  90. If zlib is used in a multi-threaded application, zalloc and zfree must be
  91. thread safe.
  92. On 16-bit systems, the functions zalloc and zfree must be able to allocate
  93. exactly 65536 bytes, but will not be required to allocate more than this
  94. if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
  95. pointers returned by zalloc for objects of exactly 65536 bytes *must*
  96. have their offset normalized to zero. The default allocation function
  97. provided by this library ensures this (see zutil.c). To reduce memory
  98. requirements and avoid any allocation of 64K objects, at the expense of
  99. compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
  100. The fields total_in and total_out can be used for statistics or
  101. progress reports. After compression, total_in holds the total size of
  102. the uncompressed data and may be saved for use in the decompressor
  103. (particularly if the decompressor wants to decompress everything in
  104. a single step).
  105. */
  106. /* constants */
  107. #define Z_NO_FLUSH 0
  108. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  109. #define Z_PACKET_FLUSH 2
  110. #define Z_SYNC_FLUSH 3
  111. #define Z_FULL_FLUSH 4
  112. #define Z_FINISH 5
  113. #define Z_BLOCK 6 /* Only for inflate at present */
  114. /* Allowed flush values; see deflate() and inflate() below for details */
  115. #define Z_OK 0
  116. #define Z_STREAM_END 1
  117. #define Z_NEED_DICT 2
  118. #define Z_ERRNO (-1)
  119. #define Z_STREAM_ERROR (-2)
  120. #define Z_DATA_ERROR (-3)
  121. #define Z_MEM_ERROR (-4)
  122. #define Z_BUF_ERROR (-5)
  123. #define Z_VERSION_ERROR (-6)
  124. /* Return codes for the compression/decompression functions. Negative
  125. * values are errors, positive values are used for special but normal events.
  126. */
  127. #define Z_NO_COMPRESSION 0
  128. #define Z_BEST_SPEED 1
  129. #define Z_BEST_COMPRESSION 9
  130. #define Z_DEFAULT_COMPRESSION (-1)
  131. /* compression levels */
  132. #define Z_FILTERED 1
  133. #define Z_HUFFMAN_ONLY 2
  134. #define Z_DEFAULT_STRATEGY 0
  135. /* compression strategy; see deflateInit2() below for details */
  136. #define Z_BINARY 0
  137. #define Z_ASCII 1
  138. #define Z_UNKNOWN 2
  139. /* Possible values of the data_type field */
  140. #define Z_DEFLATED 8
  141. /* The deflate compression method (the only one supported in this version) */
  142. /* basic functions */
  143. extern int zlib_deflate_workspacesize (void);
  144. /*
  145. Returns the number of bytes that needs to be allocated for a per-
  146. stream workspace. A pointer to this number of bytes should be
  147. returned in stream->workspace before calling zlib_deflateInit().
  148. */
  149. /*
  150. extern int deflateInit (z_streamp strm, int level);
  151. Initializes the internal stream state for compression. The fields
  152. zalloc, zfree and opaque must be initialized before by the caller.
  153. If zalloc and zfree are set to NULL, deflateInit updates them to
  154. use default allocation functions.
  155. The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
  156. 1 gives best speed, 9 gives best compression, 0 gives no compression at
  157. all (the input data is simply copied a block at a time).
  158. Z_DEFAULT_COMPRESSION requests a default compromise between speed and
  159. compression (currently equivalent to level 6).
  160. deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
  161. enough memory, Z_STREAM_ERROR if level is not a valid compression level,
  162. Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
  163. with the version assumed by the caller (ZLIB_VERSION).
  164. msg is set to null if there is no error message. deflateInit does not
  165. perform any compression: this will be done by deflate().
  166. */
  167. extern int zlib_deflate (z_streamp strm, int flush);
  168. /*
  169. deflate compresses as much data as possible, and stops when the input
  170. buffer becomes empty or the output buffer becomes full. It may introduce some
  171. output latency (reading input without producing any output) except when
  172. forced to flush.
  173. The detailed semantics are as follows. deflate performs one or both of the
  174. following actions:
  175. - Compress more input starting at next_in and update next_in and avail_in
  176. accordingly. If not all input can be processed (because there is not
  177. enough room in the output buffer), next_in and avail_in are updated and
  178. processing will resume at this point for the next call of deflate().
  179. - Provide more output starting at next_out and update next_out and avail_out
  180. accordingly. This action is forced if the parameter flush is non zero.
  181. Forcing flush frequently degrades the compression ratio, so this parameter
  182. should be set only when necessary (in interactive applications).
  183. Some output may be provided even if flush is not set.
  184. Before the call of deflate(), the application should ensure that at least
  185. one of the actions is possible, by providing more input and/or consuming
  186. more output, and updating avail_in or avail_out accordingly; avail_out
  187. should never be zero before the call. The application can consume the
  188. compressed output when it wants, for example when the output buffer is full
  189. (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
  190. and with zero avail_out, it must be called again after making room in the
  191. output buffer because there might be more output pending.
  192. If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
  193. flushed to the output buffer and the output is aligned on a byte boundary, so
  194. that the decompressor can get all input data available so far. (In particular
  195. avail_in is zero after the call if enough output space has been provided
  196. before the call.) Flushing may degrade compression for some compression
  197. algorithms and so it should be used only when necessary.
  198. If flush is set to Z_FULL_FLUSH, all output is flushed as with
  199. Z_SYNC_FLUSH, and the compression state is reset so that decompression can
  200. restart from this point if previous compressed data has been damaged or if
  201. random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
  202. the compression.
  203. If deflate returns with avail_out == 0, this function must be called again
  204. with the same value of the flush parameter and more output space (updated
  205. avail_out), until the flush is complete (deflate returns with non-zero
  206. avail_out).
  207. If the parameter flush is set to Z_FINISH, pending input is processed,
  208. pending output is flushed and deflate returns with Z_STREAM_END if there
  209. was enough output space; if deflate returns with Z_OK, this function must be
  210. called again with Z_FINISH and more output space (updated avail_out) but no
  211. more input data, until it returns with Z_STREAM_END or an error. After
  212. deflate has returned Z_STREAM_END, the only possible operations on the
  213. stream are deflateReset or deflateEnd.
  214. Z_FINISH can be used immediately after deflateInit if all the compression
  215. is to be done in a single step. In this case, avail_out must be at least
  216. 0.1% larger than avail_in plus 12 bytes. If deflate does not return
  217. Z_STREAM_END, then it must be called again as described above.
  218. deflate() sets strm->adler to the adler32 checksum of all input read
  219. so far (that is, total_in bytes).
  220. deflate() may update data_type if it can make a good guess about
  221. the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
  222. binary. This field is only for information purposes and does not affect
  223. the compression algorithm in any manner.
  224. deflate() returns Z_OK if some progress has been made (more input
  225. processed or more output produced), Z_STREAM_END if all input has been
  226. consumed and all output has been produced (only when flush is set to
  227. Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
  228. if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
  229. (for example avail_in or avail_out was zero).
  230. */
  231. extern int zlib_deflateEnd (z_streamp strm);
  232. /*
  233. All dynamically allocated data structures for this stream are freed.
  234. This function discards any unprocessed input and does not flush any
  235. pending output.
  236. deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
  237. stream state was inconsistent, Z_DATA_ERROR if the stream was freed
  238. prematurely (some input or output was discarded). In the error case,
  239. msg may be set but then points to a static string (which must not be
  240. deallocated).
  241. */
  242. extern int zlib_inflate_workspacesize (void);
  243. /*
  244. Returns the number of bytes that needs to be allocated for a per-
  245. stream workspace. A pointer to this number of bytes should be
  246. returned in stream->workspace before calling zlib_inflateInit().
  247. */
  248. /*
  249. extern int zlib_inflateInit (z_streamp strm);
  250. Initializes the internal stream state for decompression. The fields
  251. next_in, avail_in, and workspace must be initialized before by
  252. the caller. If next_in is not NULL and avail_in is large enough (the exact
  253. value depends on the compression method), inflateInit determines the
  254. compression method from the zlib header and allocates all data structures
  255. accordingly; otherwise the allocation will be deferred to the first call of
  256. inflate. If zalloc and zfree are set to NULL, inflateInit updates them to
  257. use default allocation functions.
  258. inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
  259. memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
  260. version assumed by the caller. msg is set to null if there is no error
  261. message. inflateInit does not perform any decompression apart from reading
  262. the zlib header if present: this will be done by inflate(). (So next_in and
  263. avail_in may be modified, but next_out and avail_out are unchanged.)
  264. */
  265. extern int zlib_inflate (z_streamp strm, int flush);
  266. /*
  267. inflate decompresses as much data as possible, and stops when the input
  268. buffer becomes empty or the output buffer becomes full. It may introduce
  269. some output latency (reading input without producing any output) except when
  270. forced to flush.
  271. The detailed semantics are as follows. inflate performs one or both of the
  272. following actions:
  273. - Decompress more input starting at next_in and update next_in and avail_in
  274. accordingly. If not all input can be processed (because there is not
  275. enough room in the output buffer), next_in is updated and processing
  276. will resume at this point for the next call of inflate().
  277. - Provide more output starting at next_out and update next_out and avail_out
  278. accordingly. inflate() provides as much output as possible, until there
  279. is no more input data or no more space in the output buffer (see below
  280. about the flush parameter).
  281. Before the call of inflate(), the application should ensure that at least
  282. one of the actions is possible, by providing more input and/or consuming
  283. more output, and updating the next_* and avail_* values accordingly.
  284. The application can consume the uncompressed output when it wants, for
  285. example when the output buffer is full (avail_out == 0), or after each
  286. call of inflate(). If inflate returns Z_OK and with zero avail_out, it
  287. must be called again after making room in the output buffer because there
  288. might be more output pending.
  289. The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
  290. Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
  291. output as possible to the output buffer. Z_BLOCK requests that inflate() stop
  292. if and when it gets to the next deflate block boundary. When decoding the
  293. zlib or gzip format, this will cause inflate() to return immediately after
  294. the header and before the first block. When doing a raw inflate, inflate()
  295. will go ahead and process the first block, and will return when it gets to
  296. the end of that block, or when it runs out of data.
  297. The Z_BLOCK option assists in appending to or combining deflate streams.
  298. Also to assist in this, on return inflate() will set strm->data_type to the
  299. number of unused bits in the last byte taken from strm->next_in, plus 64
  300. if inflate() is currently decoding the last block in the deflate stream,
  301. plus 128 if inflate() returned immediately after decoding an end-of-block
  302. code or decoding the complete header up to just before the first byte of the
  303. deflate stream. The end-of-block will not be indicated until all of the
  304. uncompressed data from that block has been written to strm->next_out. The
  305. number of unused bits may in general be greater than seven, except when
  306. bit 7 of data_type is set, in which case the number of unused bits will be
  307. less than eight.
  308. inflate() should normally be called until it returns Z_STREAM_END or an
  309. error. However if all decompression is to be performed in a single step
  310. (a single call of inflate), the parameter flush should be set to
  311. Z_FINISH. In this case all pending input is processed and all pending
  312. output is flushed; avail_out must be large enough to hold all the
  313. uncompressed data. (The size of the uncompressed data may have been saved
  314. by the compressor for this purpose.) The next operation on this stream must
  315. be inflateEnd to deallocate the decompression state. The use of Z_FINISH
  316. is never required, but can be used to inform inflate that a faster approach
  317. may be used for the single inflate() call.
  318. In this implementation, inflate() always flushes as much output as
  319. possible to the output buffer, and always uses the faster approach on the
  320. first call. So the only effect of the flush parameter in this implementation
  321. is on the return value of inflate(), as noted below, or when it returns early
  322. because Z_BLOCK is used.
  323. If a preset dictionary is needed after this call (see inflateSetDictionary
  324. below), inflate sets strm->adler to the adler32 checksum of the dictionary
  325. chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
  326. strm->adler to the adler32 checksum of all output produced so far (that is,
  327. total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
  328. below. At the end of the stream, inflate() checks that its computed adler32
  329. checksum is equal to that saved by the compressor and returns Z_STREAM_END
  330. only if the checksum is correct.
  331. inflate() will decompress and check either zlib-wrapped or gzip-wrapped
  332. deflate data. The header type is detected automatically. Any information
  333. contained in the gzip header is not retained, so applications that need that
  334. information should instead use raw inflate, see inflateInit2() below, or
  335. inflateBack() and perform their own processing of the gzip header and
  336. trailer.
  337. inflate() returns Z_OK if some progress has been made (more input processed
  338. or more output produced), Z_STREAM_END if the end of the compressed data has
  339. been reached and all uncompressed output has been produced, Z_NEED_DICT if a
  340. preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
  341. corrupted (input stream not conforming to the zlib format or incorrect check
  342. value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
  343. if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
  344. Z_BUF_ERROR if no progress is possible or if there was not enough room in the
  345. output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
  346. inflate() can be called again with more input and more output space to
  347. continue decompressing. If Z_DATA_ERROR is returned, the application may then
  348. call inflateSync() to look for a good compression block if a partial recovery
  349. of the data is desired.
  350. */
  351. extern int zlib_inflateEnd (z_streamp strm);
  352. /*
  353. All dynamically allocated data structures for this stream are freed.
  354. This function discards any unprocessed input and does not flush any
  355. pending output.
  356. inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
  357. was inconsistent. In the error case, msg may be set but then points to a
  358. static string (which must not be deallocated).
  359. */
  360. /* Advanced functions */
  361. /*
  362. The following functions are needed only in some special applications.
  363. */
  364. /*
  365. extern int deflateInit2 (z_streamp strm,
  366. int level,
  367. int method,
  368. int windowBits,
  369. int memLevel,
  370. int strategy);
  371. This is another version of deflateInit with more compression options. The
  372. fields next_in, zalloc, zfree and opaque must be initialized before by
  373. the caller.
  374. The method parameter is the compression method. It must be Z_DEFLATED in
  375. this version of the library.
  376. The windowBits parameter is the base two logarithm of the window size
  377. (the size of the history buffer). It should be in the range 8..15 for this
  378. version of the library. Larger values of this parameter result in better
  379. compression at the expense of memory usage. The default value is 15 if
  380. deflateInit is used instead.
  381. The memLevel parameter specifies how much memory should be allocated
  382. for the internal compression state. memLevel=1 uses minimum memory but
  383. is slow and reduces compression ratio; memLevel=9 uses maximum memory
  384. for optimal speed. The default value is 8. See zconf.h for total memory
  385. usage as a function of windowBits and memLevel.
  386. The strategy parameter is used to tune the compression algorithm. Use the
  387. value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
  388. filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
  389. string match). Filtered data consists mostly of small values with a
  390. somewhat random distribution. In this case, the compression algorithm is
  391. tuned to compress them better. The effect of Z_FILTERED is to force more
  392. Huffman coding and less string matching; it is somewhat intermediate
  393. between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
  394. the compression ratio but not the correctness of the compressed output even
  395. if it is not set appropriately.
  396. deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
  397. memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
  398. method). msg is set to null if there is no error message. deflateInit2 does
  399. not perform any compression: this will be done by deflate().
  400. */
  401. #if 0
  402. extern int zlib_deflateSetDictionary (z_streamp strm,
  403. const Byte *dictionary,
  404. uInt dictLength);
  405. #endif
  406. /*
  407. Initializes the compression dictionary from the given byte sequence
  408. without producing any compressed output. This function must be called
  409. immediately after deflateInit, deflateInit2 or deflateReset, before any
  410. call of deflate. The compressor and decompressor must use exactly the same
  411. dictionary (see inflateSetDictionary).
  412. The dictionary should consist of strings (byte sequences) that are likely
  413. to be encountered later in the data to be compressed, with the most commonly
  414. used strings preferably put towards the end of the dictionary. Using a
  415. dictionary is most useful when the data to be compressed is short and can be
  416. predicted with good accuracy; the data can then be compressed better than
  417. with the default empty dictionary.
  418. Depending on the size of the compression data structures selected by
  419. deflateInit or deflateInit2, a part of the dictionary may in effect be
  420. discarded, for example if the dictionary is larger than the window size in
  421. deflate or deflate2. Thus the strings most likely to be useful should be
  422. put at the end of the dictionary, not at the front.
  423. Upon return of this function, strm->adler is set to the Adler32 value
  424. of the dictionary; the decompressor may later use this value to determine
  425. which dictionary has been used by the compressor. (The Adler32 value
  426. applies to the whole dictionary even if only a subset of the dictionary is
  427. actually used by the compressor.)
  428. deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
  429. parameter is invalid (such as NULL dictionary) or the stream state is
  430. inconsistent (for example if deflate has already been called for this stream
  431. or if the compression method is bsort). deflateSetDictionary does not
  432. perform any compression: this will be done by deflate().
  433. */
  434. #if 0
  435. extern int zlib_deflateCopy (z_streamp dest, z_streamp source);
  436. #endif
  437. /*
  438. Sets the destination stream as a complete copy of the source stream.
  439. This function can be useful when several compression strategies will be
  440. tried, for example when there are several ways of pre-processing the input
  441. data with a filter. The streams that will be discarded should then be freed
  442. by calling deflateEnd. Note that deflateCopy duplicates the internal
  443. compression state which can be quite large, so this strategy is slow and
  444. can consume lots of memory.
  445. deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
  446. enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
  447. (such as zalloc being NULL). msg is left unchanged in both source and
  448. destination.
  449. */
  450. extern int zlib_deflateReset (z_streamp strm);
  451. /*
  452. This function is equivalent to deflateEnd followed by deflateInit,
  453. but does not free and reallocate all the internal compression state.
  454. The stream will keep the same compression level and any other attributes
  455. that may have been set by deflateInit2.
  456. deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
  457. stream state was inconsistent (such as zalloc or state being NULL).
  458. */
  459. static inline unsigned long deflateBound(unsigned long s)
  460. {
  461. return s + ((s + 7) >> 3) + ((s + 63) >> 6) + 11;
  462. }
  463. #if 0
  464. extern int zlib_deflateParams (z_streamp strm, int level, int strategy);
  465. #endif
  466. /*
  467. Dynamically update the compression level and compression strategy. The
  468. interpretation of level and strategy is as in deflateInit2. This can be
  469. used to switch between compression and straight copy of the input data, or
  470. to switch to a different kind of input data requiring a different
  471. strategy. If the compression level is changed, the input available so far
  472. is compressed with the old level (and may be flushed); the new level will
  473. take effect only at the next call of deflate().
  474. Before the call of deflateParams, the stream state must be set as for
  475. a call of deflate(), since the currently available input may have to
  476. be compressed and flushed. In particular, strm->avail_out must be non-zero.
  477. deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
  478. stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
  479. if strm->avail_out was zero.
  480. */
  481. /*
  482. extern int inflateInit2 (z_streamp strm, int windowBits);
  483. This is another version of inflateInit with an extra parameter. The
  484. fields next_in, avail_in, zalloc, zfree and opaque must be initialized
  485. before by the caller.
  486. The windowBits parameter is the base two logarithm of the maximum window
  487. size (the size of the history buffer). It should be in the range 8..15 for
  488. this version of the library. The default value is 15 if inflateInit is used
  489. instead. windowBits must be greater than or equal to the windowBits value
  490. provided to deflateInit2() while compressing, or it must be equal to 15 if
  491. deflateInit2() was not used. If a compressed stream with a larger window
  492. size is given as input, inflate() will return with the error code
  493. Z_DATA_ERROR instead of trying to allocate a larger window.
  494. windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
  495. determines the window size. inflate() will then process raw deflate data,
  496. not looking for a zlib or gzip header, not generating a check value, and not
  497. looking for any check values for comparison at the end of the stream. This
  498. is for use with other formats that use the deflate compressed data format
  499. such as zip. Those formats provide their own check values. If a custom
  500. format is developed using the raw deflate format for compressed data, it is
  501. recommended that a check value such as an adler32 or a crc32 be applied to
  502. the uncompressed data as is done in the zlib, gzip, and zip formats. For
  503. most applications, the zlib format should be used as is. Note that comments
  504. above on the use in deflateInit2() applies to the magnitude of windowBits.
  505. windowBits can also be greater than 15 for optional gzip decoding. Add
  506. 32 to windowBits to enable zlib and gzip decoding with automatic header
  507. detection, or add 16 to decode only the gzip format (the zlib format will
  508. return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is
  509. a crc32 instead of an adler32.
  510. inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
  511. memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg
  512. is set to null if there is no error message. inflateInit2 does not perform
  513. any decompression apart from reading the zlib header if present: this will
  514. be done by inflate(). (So next_in and avail_in may be modified, but next_out
  515. and avail_out are unchanged.)
  516. */
  517. extern int zlib_inflateSetDictionary (z_streamp strm,
  518. const Byte *dictionary,
  519. uInt dictLength);
  520. /*
  521. Initializes the decompression dictionary from the given uncompressed byte
  522. sequence. This function must be called immediately after a call of inflate,
  523. if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
  524. can be determined from the adler32 value returned by that call of inflate.
  525. The compressor and decompressor must use exactly the same dictionary (see
  526. deflateSetDictionary). For raw inflate, this function can be called
  527. immediately after inflateInit2() or inflateReset() and before any call of
  528. inflate() to set the dictionary. The application must insure that the
  529. dictionary that was used for compression is provided.
  530. inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
  531. parameter is invalid (such as NULL dictionary) or the stream state is
  532. inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
  533. expected one (incorrect adler32 value). inflateSetDictionary does not
  534. perform any decompression: this will be done by subsequent calls of
  535. inflate().
  536. */
  537. #if 0
  538. extern int zlib_inflateSync (z_streamp strm);
  539. #endif
  540. /*
  541. Skips invalid compressed data until a full flush point (see above the
  542. description of deflate with Z_FULL_FLUSH) can be found, or until all
  543. available input is skipped. No output is provided.
  544. inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
  545. if no more input was provided, Z_DATA_ERROR if no flush point has been found,
  546. or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
  547. case, the application may save the current current value of total_in which
  548. indicates where valid compressed data was found. In the error case, the
  549. application may repeatedly call inflateSync, providing more input each time,
  550. until success or end of the input data.
  551. */
  552. extern int zlib_inflateReset (z_streamp strm);
  553. /*
  554. This function is equivalent to inflateEnd followed by inflateInit,
  555. but does not free and reallocate all the internal decompression state.
  556. The stream will keep attributes that may have been set by inflateInit2.
  557. inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
  558. stream state was inconsistent (such as zalloc or state being NULL).
  559. */
  560. extern int zlib_inflateIncomp (z_stream *strm);
  561. /*
  562. This function adds the data at next_in (avail_in bytes) to the output
  563. history without performing any output. There must be no pending output,
  564. and the decompressor must be expecting to see the start of a block.
  565. Calling this function is equivalent to decompressing a stored block
  566. containing the data at next_in (except that the data is not output).
  567. */
  568. #define zlib_deflateInit(strm, level) \
  569. zlib_deflateInit2((strm), (level), Z_DEFLATED, MAX_WBITS, \
  570. DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY)
  571. #define zlib_inflateInit(strm) \
  572. zlib_inflateInit2((strm), DEF_WBITS)
  573. extern int zlib_deflateInit2(z_streamp strm, int level, int method,
  574. int windowBits, int memLevel,
  575. int strategy);
  576. extern int zlib_inflateInit2(z_streamp strm, int windowBits);
  577. #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
  578. struct internal_state {int dummy;}; /* hack for buggy compilers */
  579. #endif
  580. #endif /* _ZLIB_H */