diff options
Diffstat (limited to 'zlib.h')
-rw-r--r-- | zlib.h | 157 |
1 files changed, 135 insertions, 22 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* zlib.h -- interface of the 'zlib' general purpose compression library | 1 | /* zlib.h -- interface of the 'zlib' general purpose compression library |
2 | version 1.2.2, October 3rd, 2004 | 2 | version 1.2.2.1, October 31st, 2004 |
3 | 3 | ||
4 | Copyright (C) 1995-2004 Jean-loup Gailly and Mark Adler | 4 | Copyright (C) 1995-2004 Jean-loup Gailly and Mark Adler |
5 | 5 | ||
@@ -37,8 +37,8 @@ | |||
37 | extern "C" { | 37 | extern "C" { |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #define ZLIB_VERSION "1.2.2" | 40 | #define ZLIB_VERSION "1.2.2.1" |
41 | #define ZLIB_VERNUM 0x1220 | 41 | #define ZLIB_VERNUM 0x1221 |
42 | 42 | ||
43 | /* | 43 | /* |
44 | The 'zlib' compression library provides in-memory compression and | 44 | The 'zlib' compression library provides in-memory compression and |
@@ -95,7 +95,7 @@ typedef struct z_stream_s { | |||
95 | free_func zfree; /* used to free the internal state */ | 95 | free_func zfree; /* used to free the internal state */ |
96 | voidpf opaque; /* private data object passed to zalloc and zfree */ | 96 | voidpf opaque; /* private data object passed to zalloc and zfree */ |
97 | 97 | ||
98 | int data_type; /* best guess about the data type: ascii or binary */ | 98 | int data_type; /* best guess about the data type: binary or text */ |
99 | uLong adler; /* adler32 value of the uncompressed data */ | 99 | uLong adler; /* adler32 value of the uncompressed data */ |
100 | uLong reserved; /* reserved for future use */ | 100 | uLong reserved; /* reserved for future use */ |
101 | } z_stream; | 101 | } z_stream; |
@@ -103,6 +103,29 @@ typedef struct z_stream_s { | |||
103 | typedef z_stream FAR *z_streamp; | 103 | typedef z_stream FAR *z_streamp; |
104 | 104 | ||
105 | /* | 105 | /* |
106 | gzip header information passed to and from zlib routines. See RFC 1952 | ||
107 | for more details on the meanings of these fields. | ||
108 | */ | ||
109 | typedef struct gz_header_s { | ||
110 | int text; /* true if compressed data believed to be text */ | ||
111 | uLong time; /* modification time */ | ||
112 | int xflags; /* extra flags (not used when writing a gzip file) */ | ||
113 | int os; /* operating system */ | ||
114 | Bytef *extra; /* pointer to extra field or Z_NULL if none */ | ||
115 | uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ | ||
116 | uInt extra_max; /* space at extra (only when reading header) */ | ||
117 | Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ | ||
118 | uInt name_max; /* space at name (only when reading header) */ | ||
119 | Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ | ||
120 | uInt comm_max; /* space at comment (only when reading header) */ | ||
121 | int hcrc; /* true if there was or will be a header crc */ | ||
122 | int done; /* true when done reading gzip header (not used | ||
123 | when writing a gzip file) */ | ||
124 | } gz_header; | ||
125 | |||
126 | typedef gz_header FAR *gz_headerp; | ||
127 | |||
128 | /* | ||
106 | The application must update next_in and avail_in when avail_in has | 129 | The application must update next_in and avail_in when avail_in has |
107 | dropped to zero. It must update next_out and avail_out when avail_out | 130 | dropped to zero. It must update next_out and avail_out when avail_out |
108 | has dropped to zero. The application must initialize zalloc, zfree and | 131 | has dropped to zero. The application must initialize zalloc, zfree and |
@@ -170,7 +193,8 @@ typedef z_stream FAR *z_streamp; | |||
170 | /* compression strategy; see deflateInit2() below for details */ | 193 | /* compression strategy; see deflateInit2() below for details */ |
171 | 194 | ||
172 | #define Z_BINARY 0 | 195 | #define Z_BINARY 0 |
173 | #define Z_ASCII 1 | 196 | #define Z_TEXT 1 |
197 | #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ | ||
174 | #define Z_UNKNOWN 2 | 198 | #define Z_UNKNOWN 2 |
175 | /* Possible values of the data_type field (though see inflate()) */ | 199 | /* Possible values of the data_type field (though see inflate()) */ |
176 | 200 | ||
@@ -244,6 +268,10 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); | |||
244 | and with zero avail_out, it must be called again after making room in the | 268 | and with zero avail_out, it must be called again after making room in the |
245 | output buffer because there might be more output pending. | 269 | output buffer because there might be more output pending. |
246 | 270 | ||
271 | Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to | ||
272 | decide how much data to accumualte before producing output, in order to | ||
273 | maximize compression. | ||
274 | |||
247 | If the parameter flush is set to Z_SYNC_FLUSH, all pending output is | 275 | If the parameter flush is set to Z_SYNC_FLUSH, all pending output is |
248 | flushed to the output buffer and the output is aligned on a byte boundary, so | 276 | flushed to the output buffer and the output is aligned on a byte boundary, so |
249 | that the decompressor can get all input data available so far. (In particular | 277 | that the decompressor can get all input data available so far. (In particular |
@@ -255,7 +283,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); | |||
255 | Z_SYNC_FLUSH, and the compression state is reset so that decompression can | 283 | Z_SYNC_FLUSH, and the compression state is reset so that decompression can |
256 | restart from this point if previous compressed data has been damaged or if | 284 | restart from this point if previous compressed data has been damaged or if |
257 | random access is desired. Using Z_FULL_FLUSH too often can seriously degrade | 285 | random access is desired. Using Z_FULL_FLUSH too often can seriously degrade |
258 | the compression. | 286 | compression. |
259 | 287 | ||
260 | If deflate returns with avail_out == 0, this function must be called again | 288 | If deflate returns with avail_out == 0, this function must be called again |
261 | with the same value of the flush parameter and more output space (updated | 289 | with the same value of the flush parameter and more output space (updated |
@@ -280,8 +308,8 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); | |||
280 | deflate() sets strm->adler to the adler32 checksum of all input read | 308 | deflate() sets strm->adler to the adler32 checksum of all input read |
281 | so far (that is, total_in bytes). | 309 | so far (that is, total_in bytes). |
282 | 310 | ||
283 | deflate() may update data_type if it can make a good guess about | 311 | deflate() may update strm->data_type if it can make a good guess about |
284 | the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered | 312 | the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered |
285 | binary. This field is only for information purposes and does not affect | 313 | binary. This field is only for information purposes and does not affect |
286 | the compression algorithm in any manner. | 314 | the compression algorithm in any manner. |
287 | 315 | ||
@@ -616,6 +644,30 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, | |||
616 | stream state was inconsistent. | 644 | stream state was inconsistent. |
617 | */ | 645 | */ |
618 | 646 | ||
647 | ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, | ||
648 | gz_headerp head)); | ||
649 | /* | ||
650 | deflateSetHeader() provides gzip header information for when a gzip | ||
651 | stream is requested by deflateInit2(). deflateSetHeader() may be called | ||
652 | after deflateInit2() or deflateReset() and before the first call of | ||
653 | deflate(). The text, time, os, extra field, name, and comment information | ||
654 | in the provided gz_header structure are written to the gzip header (xflag is | ||
655 | ignored -- the extra flags are set according to the compression level). The | ||
656 | caller must assure that, if not Z_NULL, name and comment are terminated with | ||
657 | a zero byte, and that if extra is not Z_NULL, that extra_len bytes are | ||
658 | available there. If hcrc is true, a gzip header crc is included. Note that | ||
659 | the current versions of the command-line version of gzip (up through version | ||
660 | 1.3.x) do not support header crc's, and will report that it is a "multi-part | ||
661 | gzip file" and give up. | ||
662 | |||
663 | If deflateSetHeader is not used, the default gzip header has text false, | ||
664 | the time set to zero, and os set to 255, with no extra, name, or comment | ||
665 | fields. The gzip header is returned to the default state by deflateReset(). | ||
666 | |||
667 | deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source | ||
668 | stream state was inconsistent. | ||
669 | */ | ||
670 | |||
619 | /* | 671 | /* |
620 | ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, | 672 | ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, |
621 | int windowBits)); | 673 | int windowBits)); |
@@ -664,11 +716,14 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, | |||
664 | uInt dictLength)); | 716 | uInt dictLength)); |
665 | /* | 717 | /* |
666 | Initializes the decompression dictionary from the given uncompressed byte | 718 | Initializes the decompression dictionary from the given uncompressed byte |
667 | sequence. This function must be called immediately after a call of inflate | 719 | sequence. This function must be called immediately after a call of inflate, |
668 | if this call returned Z_NEED_DICT. The dictionary chosen by the compressor | 720 | if that call returned Z_NEED_DICT. The dictionary chosen by the compressor |
669 | can be determined from the adler32 value returned by this call of | 721 | can be determined from the adler32 value returned by that call of inflate. |
670 | inflate. The compressor and decompressor must use exactly the same | 722 | The compressor and decompressor must use exactly the same dictionary (see |
671 | dictionary (see deflateSetDictionary). | 723 | deflateSetDictionary). For raw inflate, this function can be called |
724 | immediately after inflateInit2() or inflateReset() and before any call of | ||
725 | inflate() to set the dictionary. The application must insure that the | ||
726 | dictionary that was used for compression is provided. | ||
672 | 727 | ||
673 | inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a | 728 | inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a |
674 | parameter is invalid (such as NULL dictionary) or the stream state is | 729 | parameter is invalid (such as NULL dictionary) or the stream state is |
@@ -719,8 +774,48 @@ ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); | |||
719 | stream state was inconsistent (such as zalloc or state being NULL). | 774 | stream state was inconsistent (such as zalloc or state being NULL). |
720 | */ | 775 | */ |
721 | 776 | ||
777 | ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, | ||
778 | gz_headerp head)); | ||
779 | /* | ||
780 | inflateGetHeader() requests that gzip header information be stored in the | ||
781 | provided gz_header structure. inflateGetHeader() may be called after | ||
782 | inflateInit2() or inflateReset(), and before the first call of inflate(). | ||
783 | As inflate() processes the gzip stream, head->done is zero until the header | ||
784 | is completed, at which time head->done is set to one. If a zlib stream is | ||
785 | being decoded, then head->done is set to -1 to indicate that there will be | ||
786 | no gzip header information forthcoming. Note that Z_BLOCK can be used to | ||
787 | force inflate() to return immediately after header processing is complete | ||
788 | and before any actual data is decompressed. | ||
789 | |||
790 | The text, time, xflags, and os fields are filled in with the gzip header | ||
791 | contents. hcrc is set to true if there is a header CRC. (The header CRC | ||
792 | was valid if done is set to one.) If extra is not Z_NULL, then extra_max | ||
793 | contains the maximum number of bytes to write to extra. Once done is true, | ||
794 | extra_len contains the actual extra field length, and extra contains the | ||
795 | extra field, or that field truncated if extra_max is less than extra_len. | ||
796 | If name is not Z_NULL, then up to name_max characters are written there, | ||
797 | terminated with a zero unless the length is greater than name_max. If | ||
798 | comment is not Z_NULL, then up to comm_max characters are written there, | ||
799 | terminated with a zero unless the length is greater than comm_max. When | ||
800 | any of extra, name, or comment are not Z_NULL and the respective field is | ||
801 | not present in the header, then that field is set to Z_NULL to signal its | ||
802 | absence. This allows the use of deflateSetHeader() with the returned | ||
803 | structure to duplicate the header. However if those fields are set to | ||
804 | allocated memory, then the application will need to save those pointers | ||
805 | elsewhere so that they can be eventually freed. | ||
806 | |||
807 | If inflateGetHeader is not used, then the header information is simply | ||
808 | discarded. The header is always checked for validity, including the header | ||
809 | CRC if present. inflateReset() will reset the process to discard the header | ||
810 | information. The application would need to call inflateGetHeader() again to | ||
811 | retrieve the header from the next gzip stream. | ||
812 | |||
813 | inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source | ||
814 | stream state was inconsistent. | ||
815 | */ | ||
816 | |||
722 | /* | 817 | /* |
723 | ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits, | 818 | ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, |
724 | unsigned char FAR *window)); | 819 | unsigned char FAR *window)); |
725 | 820 | ||
726 | Initialize the internal stream state for decompression using inflateBack() | 821 | Initialize the internal stream state for decompression using inflateBack() |
@@ -744,7 +839,7 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits, | |||
744 | typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); | 839 | typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); |
745 | typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); | 840 | typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); |
746 | 841 | ||
747 | ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm, | 842 | ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, |
748 | in_func in, void FAR *in_desc, | 843 | in_func in, void FAR *in_desc, |
749 | out_func out, void FAR *out_desc)); | 844 | out_func out, void FAR *out_desc)); |
750 | /* | 845 | /* |
@@ -813,7 +908,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm, | |||
813 | that inflateBack() cannot return Z_OK. | 908 | that inflateBack() cannot return Z_OK. |
814 | */ | 909 | */ |
815 | 910 | ||
816 | ZEXTERN int ZEXPORT inflateBackEnd OF((z_stream FAR *strm)); | 911 | ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); |
817 | /* | 912 | /* |
818 | All memory allocated by inflateBackInit() is freed. | 913 | All memory allocated by inflateBackInit() is freed. |
819 | 914 | ||
@@ -1119,7 +1214,6 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); | |||
1119 | */ | 1214 | */ |
1120 | 1215 | ||
1121 | ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); | 1216 | ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); |
1122 | |||
1123 | /* | 1217 | /* |
1124 | Update a running Adler-32 checksum with the bytes buf[0..len-1] and | 1218 | Update a running Adler-32 checksum with the bytes buf[0..len-1] and |
1125 | return the updated checksum. If buf is NULL, this function returns | 1219 | return the updated checksum. If buf is NULL, this function returns |
@@ -1135,12 +1229,21 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); | |||
1135 | if (adler != original_adler) error(); | 1229 | if (adler != original_adler) error(); |
1136 | */ | 1230 | */ |
1137 | 1231 | ||
1232 | ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, | ||
1233 | uLong len2)); | ||
1234 | /* | ||
1235 | Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 | ||
1236 | and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for | ||
1237 | each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of | ||
1238 | seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. | ||
1239 | */ | ||
1240 | |||
1138 | ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); | 1241 | ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); |
1139 | /* | 1242 | /* |
1140 | Update a running crc with the bytes buf[0..len-1] and return the updated | 1243 | Update a running CRC-32 with the bytes buf[0..len-1] and return the |
1141 | crc. If buf is NULL, this function returns the required initial value | 1244 | updated CRC-32. If buf is NULL, this function returns the required initial |
1142 | for the crc. Pre- and post-conditioning (one's complement) is performed | 1245 | value for the for the crc. Pre- and post-conditioning (one's complement) is |
1143 | within this function so it shouldn't be done by the application. | 1246 | performed within this function so it shouldn't be done by the application. |
1144 | Usage example: | 1247 | Usage example: |
1145 | 1248 | ||
1146 | uLong crc = crc32(0L, Z_NULL, 0); | 1249 | uLong crc = crc32(0L, Z_NULL, 0); |
@@ -1151,6 +1254,16 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); | |||
1151 | if (crc != original_crc) error(); | 1254 | if (crc != original_crc) error(); |
1152 | */ | 1255 | */ |
1153 | 1256 | ||
1257 | ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, uLong len2)); | ||
1258 | |||
1259 | /* | ||
1260 | Combine two CRC-32 check values into one. For two sequences of bytes, | ||
1261 | seq1 and seq2 with lengths len1 and len2, CRC-32 check values were | ||
1262 | calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 | ||
1263 | check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and | ||
1264 | len2. | ||
1265 | */ | ||
1266 | |||
1154 | 1267 | ||
1155 | /* various hacks, don't look :) */ | 1268 | /* various hacks, don't look :) */ |
1156 | 1269 | ||
@@ -1167,7 +1280,7 @@ ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, | |||
1167 | int stream_size)); | 1280 | int stream_size)); |
1168 | ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, | 1281 | ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, |
1169 | const char *version, int stream_size)); | 1282 | const char *version, int stream_size)); |
1170 | ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits, | 1283 | ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, |
1171 | unsigned char FAR *window, | 1284 | unsigned char FAR *window, |
1172 | const char *version, | 1285 | const char *version, |
1173 | int stream_size)); | 1286 | int stream_size)); |