gzio_symb.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* zlib.h -- interface of the 'zlib' general purpose compression library
  2. version 1.2.3, July 18th, 2005
  3. Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. Jean-loup Gailly Mark Adler
  18. jloup@gzip.org madler@alumni.caltech.edu
  19. The data format used by the zlib library is described by RFCs (Request for
  20. Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
  21. (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
  22. */
  23. #ifndef GZIO_H
  24. #define GZIO_H
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /*
  29. The 'zlib' compression library provides in-memory compression and
  30. decompression functions, including integrity checks of the uncompressed
  31. data. This version of the library supports only one compression method
  32. (deflation) but other algorithms will be added later and will have the same
  33. stream interface.
  34. Compression can be done in a single step if the buffers are large
  35. enough (for example if an input file is mmap'ed), or can be done by
  36. repeated calls of the compression function. In the latter case, the
  37. application must provide more input and/or consume the output
  38. (providing more output space) before each call.
  39. The compressed data format used by default by the in-memory functions is
  40. the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
  41. around a deflate stream, which is itself documented in RFC 1951.
  42. The library also supports reading and writing files in gzip (.gz) format
  43. with an interface similar to that of stdio using the functions that start
  44. with "gz". The gzip format is different from the zlib format. gzip is a
  45. gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
  46. This library can optionally read and write gzip streams in memory as well.
  47. The zlib format was designed to be compact and fast for use in memory
  48. and on communications channels. The gzip format was designed for single-
  49. file compression on file systems, has a larger header than zlib to maintain
  50. directory information, and uses a different, slower check method than zlib.
  51. The library does not install any signal handler. The decoder checks
  52. the consistency of the compressed data, so the library should never
  53. crash even in case of corrupted input.
  54. */
  55. #ifdef STDC
  56. typedef void const *voidpc;
  57. #else
  58. typedef Byte const *voidpc;
  59. #endif
  60. /*
  61. gzip header information passed to and from zlib routines. See RFC 1952
  62. for more details on the meanings of these fields.
  63. */
  64. typedef struct gz_header_s {
  65. int text; /* true if compressed data believed to be text */
  66. uLong time; /* modification time */
  67. int xflags; /* extra flags (not used when writing a gzip file) */
  68. int os; /* operating system */
  69. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  70. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  71. uInt extra_max; /* space at extra (only when reading header) */
  72. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  73. uInt name_max; /* space at name (only when reading header) */
  74. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75. uInt comm_max; /* space at comment (only when reading header) */
  76. int hcrc; /* true if there was or will be a header crc */
  77. int done; /* true when done reading gzip header (not used
  78. when writing a gzip file) */
  79. } gz_header;
  80. typedef gz_header FAR *gz_headerp;
  81. /*
  82. The application must update next_in and avail_in when avail_in has
  83. dropped to zero. It must update next_out and avail_out when avail_out
  84. has dropped to zero. The application must initialize zalloc, zfree and
  85. opaque before calling the init function. All other fields are set by the
  86. compression library and must not be updated by the application.
  87. The opaque value provided by the application will be passed as the first
  88. parameter for calls of zalloc and zfree. This can be useful for custom
  89. memory management. The compression library attaches no meaning to the
  90. opaque value.
  91. zalloc must return Z_NULL if there is not enough memory for the object.
  92. If zlib is used in a multi-threaded application, zalloc and zfree must be
  93. thread safe.
  94. On 16-bit systems, the functions zalloc and zfree must be able to allocate
  95. exactly 65536 bytes, but will not be required to allocate more than this
  96. if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
  97. pointers returned by zalloc for objects of exactly 65536 bytes *must*
  98. have their offset normalized to zero. The default allocation function
  99. provided by this library ensures this (see zutil.c). To reduce memory
  100. requirements and avoid any allocation of 64K objects, at the expense of
  101. compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
  102. The fields total_in and total_out can be used for statistics or
  103. progress reports. After compression, total_in holds the total size of
  104. the uncompressed data and may be saved for use in the decompressor
  105. (particularly if the decompressor wants to decompress everything in
  106. a single step).
  107. */
  108. /* constants */
  109. #define Z_NO_FLUSH 0
  110. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  111. #define Z_SYNC_FLUSH 2
  112. #define Z_FULL_FLUSH 3
  113. #define Z_FINISH 4
  114. #define Z_BLOCK 5
  115. /* Allowed flush values; see deflate() and inflate() below for details */
  116. #define Z_OK 0
  117. #define Z_STREAM_END 1
  118. #define Z_NEED_DICT 2
  119. #define Z_ERRNO (-1)
  120. #define Z_STREAM_ERROR (-2)
  121. #define Z_DATA_ERROR (-3)
  122. #define Z_MEM_ERROR (-4)
  123. #define Z_BUF_ERROR (-5)
  124. #define Z_VERSION_ERROR (-6)
  125. /* Return codes for the compression/decompression functions. Negative
  126. * values are errors, positive values are used for special but normal events.
  127. */
  128. #define Z_NO_COMPRESSION 0
  129. #define Z_BEST_SPEED 1
  130. #define Z_BEST_COMPRESSION 9
  131. #define Z_DEFAULT_COMPRESSION (-1)
  132. /* compression levels */
  133. #define Z_FILTERED 1
  134. #define Z_HUFFMAN_ONLY 2
  135. #define Z_RLE 3
  136. #define Z_FIXED 4
  137. #define Z_DEFAULT_STRATEGY 0
  138. /* compression strategy; see deflateInit2() below for details */
  139. #define Z_BINARY 0
  140. #define Z_TEXT 1
  141. //#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  142. #define Z_UNKNOWN 2
  143. /* Possible values of the data_type field (though see inflate()) */
  144. #define Z_DEFLATED 8
  145. /* The deflate compression method (the only one supported in this version) */
  146. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  147. #define zlib_version zlibVersion()
  148. /* for compatibility with versions < 1.0.2 */
  149. typedef voidp gzFile;
  150. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  151. /*
  152. Opens a gzip (.gz) file for reading or writing. The mode parameter
  153. is as in fopen ("rb" or "wb") but can also include a compression level
  154. ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
  155. Huffman only compression as in "wb1h", or 'R' for run-length encoding
  156. as in "wb1R". (See the description of deflateInit2 for more information
  157. about the strategy parameter.)
  158. gzopen can be used to read a file which is not in gzip format; in this
  159. case gzread will directly read from the file without decompression.
  160. gzopen returns NULL if the file could not be opened or if there was
  161. insufficient memory to allocate the (de)compression state; errno
  162. can be checked to distinguish the two cases (if errno is zero, the
  163. zlib error is Z_MEM_ERROR). */
  164. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  165. /*
  166. Dynamically update the compression level or strategy. See the description
  167. of deflateInit2 for the meaning of these parameters.
  168. gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
  169. opened for writing.
  170. */
  171. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  172. /*
  173. Reads the given number of uncompressed bytes from the compressed file.
  174. If the input file was not in gzip format, gzread copies the given number
  175. of bytes into the buffer.
  176. gzread returns the number of uncompressed bytes actually read (0 for
  177. end of file, -1 for error). */
  178. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  179. voidpc buf, unsigned len));
  180. /*
  181. Writes the given number of uncompressed bytes into the compressed file.
  182. gzwrite returns the number of uncompressed bytes actually written
  183. (0 in case of error).
  184. */
  185. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  186. /*
  187. Flushes all pending output if necessary, closes the compressed file
  188. and deallocates all the (de)compression state. The return value is the zlib
  189. error number (see function gzerror below).
  190. */
  191. #ifdef __cplusplus
  192. } // extern "C"
  193. #endif
  194. #endif /* GZIO_H */