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