1*0a6a1f1dSLionel Sambuc.\" $NetBSD: zlib.3,v 1.10 2014/03/18 18:20:38 riastradh Exp $ 2435f2b00SLionel Sambuc.\" $OpenBSD: zlib.3,v 1.1 2003/09/25 09:12:09 jmc Exp $ 3435f2b00SLionel Sambuc.\" 4435f2b00SLionel Sambuc.\" Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler 5435f2b00SLionel Sambuc.\" 6435f2b00SLionel Sambuc.\" This software is provided 'as-is', without any express or implied 7435f2b00SLionel Sambuc.\" warranty. In no event will the authors be held liable for any damages 8435f2b00SLionel Sambuc.\" arising from the use of this software. 9435f2b00SLionel Sambuc.\" 10435f2b00SLionel Sambuc.\" Permission is granted to anyone to use this software for any purpose, 11435f2b00SLionel Sambuc.\" including commercial applications, and to alter it and redistribute it 12435f2b00SLionel Sambuc.\" freely, subject to the following restrictions: 13435f2b00SLionel Sambuc.\" 14435f2b00SLionel Sambuc.\" The origin of this software must not be misrepresented; you must not 15435f2b00SLionel Sambuc.\" claim that you wrote the original software. If you use this software 16435f2b00SLionel Sambuc.\" in a product, an acknowledgment in the product documentation would be 17435f2b00SLionel Sambuc.\" appreciated but is not required. 18435f2b00SLionel Sambuc.\" Altered source versions must be plainly marked as such, and must not be 19435f2b00SLionel Sambuc.\" misrepresented as being the original software. 20435f2b00SLionel Sambuc.\" This notice may not be removed or altered from any source distribution. 21435f2b00SLionel Sambuc.\" 22435f2b00SLionel Sambuc.\" Converted to mdoc format for the OpenBSD project 23435f2b00SLionel Sambuc.\" by Jason McIntyre <jmc@openbsd.org> 24435f2b00SLionel Sambuc.\" 25435f2b00SLionel Sambuc.Dd May 1, 2004 26435f2b00SLionel Sambuc.Dt ZLIB 3 27435f2b00SLionel Sambuc.Os 28435f2b00SLionel Sambuc.Sh NAME 29435f2b00SLionel Sambuc.Nm zlib 30435f2b00SLionel Sambuc.Nd general purpose compression library 31435f2b00SLionel Sambuc.Sh SYNOPSIS 32435f2b00SLionel Sambuc.In zlib.h 33435f2b00SLionel Sambuc.Ss Basic functions 34435f2b00SLionel Sambuc.Ft const char * 35435f2b00SLionel Sambuc.Fn zlibVersion "void" 36435f2b00SLionel Sambuc.Ft int 37435f2b00SLionel Sambuc.Fn deflateInit "z_streamp strm" "int level" 38435f2b00SLionel Sambuc.Ft int 39435f2b00SLionel Sambuc.Fn deflate "z_streamp strm" "int flush" 40435f2b00SLionel Sambuc.Ft int 41435f2b00SLionel Sambuc.Fn deflateEnd "z_streamp strm" 42435f2b00SLionel Sambuc.Ft int 43435f2b00SLionel Sambuc.Fn inflateInit "z_streamp strm" 44435f2b00SLionel Sambuc.Ft int 45435f2b00SLionel Sambuc.Fn inflate "z_streamp strm" "int flush" 46435f2b00SLionel Sambuc.Ft int 47435f2b00SLionel Sambuc.Fn inflateEnd "z_streamp strm" 48435f2b00SLionel Sambuc.Ss Advanced functions 49435f2b00SLionel Sambuc.Ft int 50435f2b00SLionel Sambuc.Fn deflateInit2 "z_streamp strm" "int level" "int method" \ 51435f2b00SLionel Sambuc"int windowBits" "int memLevel" "int strategy" 52435f2b00SLionel Sambuc.Ft int 53435f2b00SLionel Sambuc.Fn deflateSetDictionary "z_streamp strm" "const Bytef *dictionary" \ 54435f2b00SLionel Sambuc"uInt dictLength" 55435f2b00SLionel Sambuc.Ft int 56435f2b00SLionel Sambuc.Fn deflateCopy "z_streamp dest" "z_streamp source" 57435f2b00SLionel Sambuc.Ft int 58435f2b00SLionel Sambuc.Fn deflateReset "z_streamp strm" 59435f2b00SLionel Sambuc.Ft int 60435f2b00SLionel Sambuc.Fn deflateParams "z_streamp strm" "int level" "int strategy" 61435f2b00SLionel Sambuc.Ft int 62435f2b00SLionel Sambuc.Fn inflateInit2 "z_streamp strm" "int windowBits" 63435f2b00SLionel Sambuc.Ft int 64435f2b00SLionel Sambuc.Fn inflateSetDictionary "z_streamp strm" "const Bytef *dictionary" "uInt dictLength" 65435f2b00SLionel Sambuc.Ft int 66435f2b00SLionel Sambuc.Fn inflateSync "z_streamp strm" 67435f2b00SLionel Sambuc.Ft int 68435f2b00SLionel Sambuc.Fn inflateReset "z_streamp strm" 69435f2b00SLionel Sambuc.Ss Utility functions 70435f2b00SLionel Sambuc.Fd typedef voidp gzFile ; 71435f2b00SLionel Sambuc.Pp 72435f2b00SLionel Sambuc.Ft int 73435f2b00SLionel Sambuc.Fn compress "Bytef *dest" "uLongf *destLen" "const Bytef *source" "uLong sourceLen" 74435f2b00SLionel Sambuc.Ft int 75435f2b00SLionel Sambuc.Fn compress2 "Bytef *dest" "uLongf *destLen" "const Bytef *source" "uLong sourceLen" "int level" 76435f2b00SLionel Sambuc.Ft int 77435f2b00SLionel Sambuc.Fn uncompress "Bytef *dest" "uLongf *destLen" "const Bytef *source" "uLong sourceLen" 78435f2b00SLionel Sambuc.Ft gzFile 79435f2b00SLionel Sambuc.Fn gzopen "const char *path" "const char *mode" 80435f2b00SLionel Sambuc.Ft gzFile 81435f2b00SLionel Sambuc.Fn gzdopen "int fd" "const char *mode" 82435f2b00SLionel Sambuc.Ft int 83435f2b00SLionel Sambuc.Fn gzsetparams "gzFile file" "int level" "int strategy" 84435f2b00SLionel Sambuc.Ft int 85435f2b00SLionel Sambuc.Fn gzread "gzFile file" "voidp buf" "unsigned len" 86435f2b00SLionel Sambuc.Ft int 87435f2b00SLionel Sambuc.Fn gzwrite "gzFile file" "const voidp buf" "unsigned len" 88435f2b00SLionel Sambuc.Ft int 89435f2b00SLionel Sambuc.Fn gzprintf "gzFile file" "const char *format" "..." 90435f2b00SLionel Sambuc.Ft int 91435f2b00SLionel Sambuc.Fn gzputs "gzFile file" "const char *s" 92435f2b00SLionel Sambuc.Ft char * 93435f2b00SLionel Sambuc.Fn gzgets "gzFile file" "char *buf" "int len" 94435f2b00SLionel Sambuc.Ft int 95435f2b00SLionel Sambuc.Fn gzputc "gzFile file" "int c" 96435f2b00SLionel Sambuc.Ft int 97435f2b00SLionel Sambuc.Fn gzgetc "gzFile file" 98435f2b00SLionel Sambuc.Ft int 99435f2b00SLionel Sambuc.Fn gzflush "gzFile file" "int flush" 100435f2b00SLionel Sambuc.Ft z_off_t 101435f2b00SLionel Sambuc.Fn gzseek "gzFile file" "z_off_t offset" "int whence" 102435f2b00SLionel Sambuc.Ft int 103435f2b00SLionel Sambuc.Fn gzrewind "gzFile file" 104435f2b00SLionel Sambuc.Ft z_off_t 105435f2b00SLionel Sambuc.Fn gztell "gzFile file" 106435f2b00SLionel Sambuc.Ft int 107435f2b00SLionel Sambuc.Fn gzeof "gzFile file" 108435f2b00SLionel Sambuc.Ft int 109435f2b00SLionel Sambuc.Fn gzclose "gzFile file" 110435f2b00SLionel Sambuc.Ft const char * 111435f2b00SLionel Sambuc.Fn gzerror "gzFile file" "int *errnum" 112435f2b00SLionel Sambuc.Ss Checksum functions 113435f2b00SLionel Sambuc.Ft uLong 114435f2b00SLionel Sambuc.Fn adler32 "uLong adler" "const Bytef *buf" "uInt len" 115435f2b00SLionel Sambuc.Ft uLong 116435f2b00SLionel Sambuc.Fn crc32 "uLong crc" "const Bytef *buf" "uInt len" 117435f2b00SLionel Sambuc.Sh DESCRIPTION 118435f2b00SLionel SambucThis manual page describes the 119435f2b00SLionel Sambuc.Nm 120435f2b00SLionel Sambucgeneral purpose compression library, version 1.1.4. 121435f2b00SLionel Sambuc.Pp 122435f2b00SLionel SambucThe 123435f2b00SLionel Sambuc.Nm 124435f2b00SLionel Sambuccompression library provides in-memory compression and decompression functions, 125435f2b00SLionel Sambucincluding integrity checks of the uncompressed data. 126435f2b00SLionel SambucThis version of the library supports only one compression method 127435f2b00SLionel Sambuc.Pq deflation 128435f2b00SLionel Sambucbut other algorithms will be added later and will have the same 129435f2b00SLionel Sambucstream interface. 130435f2b00SLionel Sambuc.Pp 131435f2b00SLionel SambucCompression can be done in a single step if the buffers are large enough 132435f2b00SLionel Sambuc.Pq for example if an input file is mmap'ed , 133435f2b00SLionel Sambucor can be done by repeated calls of the compression function. 134435f2b00SLionel SambucIn the latter case, the application must provide more input 135435f2b00SLionel Sambucand/or consume the output 136435f2b00SLionel Sambuc.Pq providing more output space 137435f2b00SLionel Sambucbefore each call. 138435f2b00SLionel Sambuc.Pp 139435f2b00SLionel SambucThe library also supports reading and writing files in 140435f2b00SLionel Sambuc.Xr gzip 1 141435f2b00SLionel Sambuc.Pq .gz 142435f2b00SLionel Sambucformat with an interface similar to that of 143435f2b00SLionel Sambuc.Xr stdio 3 . 144435f2b00SLionel Sambuc.Pp 145435f2b00SLionel SambucThe library does not install any signal handler. 146435f2b00SLionel SambucThe decoder checks the consistency of the compressed data, 147435f2b00SLionel Sambucso the library should never crash even in case of corrupted input. 148435f2b00SLionel Sambuc.Pp 149435f2b00SLionel SambucThe functions within the library are divided into the following sections: 150435f2b00SLionel Sambuc.Pp 151435f2b00SLionel Sambuc.Bl -dash -offset indent -compact 152435f2b00SLionel Sambuc.It 153435f2b00SLionel SambucBasic functions 154435f2b00SLionel Sambuc.It 155435f2b00SLionel SambucAdvanced functions 156435f2b00SLionel Sambuc.It 157435f2b00SLionel SambucUtility functions 158435f2b00SLionel Sambuc.It 159435f2b00SLionel SambucChecksum functions 160435f2b00SLionel Sambuc.El 161435f2b00SLionel Sambuc.Sh BASIC FUNCTIONS 162435f2b00SLionel Sambuc.Bl -tag -width Ds 163435f2b00SLionel Sambuc.It Fa const char * Fn zlibVersion "void" ; 164435f2b00SLionel Sambuc.Pp 165435f2b00SLionel SambucThe application can compare 166435f2b00SLionel Sambuc.Fn zlibVersion 167435f2b00SLionel Sambucand 168435f2b00SLionel Sambuc.Dv ZLIB_VERSION 169435f2b00SLionel Sambucfor consistency. 170435f2b00SLionel SambucIf the first character differs, the library code actually used is 171435f2b00SLionel Sambucnot compatible with the 172435f2b00SLionel Sambuc.In zlib.h 173435f2b00SLionel Sambucheader file used by the application. 174435f2b00SLionel SambucThis check is automatically made by 175435f2b00SLionel Sambuc.Fn deflateInit 176435f2b00SLionel Sambucand 177435f2b00SLionel Sambuc.Fn inflateInit . 178435f2b00SLionel Sambuc.It Fa int Fn deflateInit "z_streamp strm" "int level" ; 179435f2b00SLionel Sambuc.Pp 180435f2b00SLionel SambucThe 181435f2b00SLionel Sambuc.Fn deflateInit 182435f2b00SLionel Sambucfunction initializes the internal stream state for compression. 183435f2b00SLionel SambucThe fields 184435f2b00SLionel Sambuc.Fa zalloc , 185435f2b00SLionel Sambuc.Fa zfree , 186435f2b00SLionel Sambucand 187435f2b00SLionel Sambuc.Fa opaque 188435f2b00SLionel Sambucmust be initialized before by the caller. 189435f2b00SLionel SambucIf 190435f2b00SLionel Sambuc.Fa zalloc 191435f2b00SLionel Sambucand 192435f2b00SLionel Sambuc.Fa zfree 193435f2b00SLionel Sambucare set to 194435f2b00SLionel Sambuc.Dv Z_NULL , 195435f2b00SLionel Sambuc.Fn deflateInit 196435f2b00SLionel Sambucupdates them to use default allocation functions. 197435f2b00SLionel Sambuc.Pp 198435f2b00SLionel SambucThe compression level must be 199435f2b00SLionel Sambuc.Dv Z_DEFAULT_COMPRESSION , 200435f2b00SLionel Sambucor between 0 and 9: 201435f2b00SLionel Sambuc1 gives best speed, 9 gives best compression, 0 gives no compression at all 202435f2b00SLionel Sambuc(the input data is simply copied a block at a time). 203435f2b00SLionel Sambuc.Pp 204435f2b00SLionel Sambuc.Dv Z_DEFAULT_COMPRESSION 205435f2b00SLionel Sambucrequests a default compromise between speed and compression 206435f2b00SLionel Sambuc.Pq currently equivalent to level 6 . 207435f2b00SLionel Sambuc.Pp 208435f2b00SLionel Sambuc.Fn deflateInit 209435f2b00SLionel Sambucreturns 210435f2b00SLionel Sambuc.Dv Z_OK 211435f2b00SLionel Sambucif successful, 212435f2b00SLionel Sambuc.Dv Z_MEM_ERROR 213435f2b00SLionel Sambucif there was not enough memory, 214435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 215435f2b00SLionel Sambucif level is not a valid compression level, 216435f2b00SLionel Sambuc.Dv Z_VERSION_ERROR 217435f2b00SLionel Sambucif the 218435f2b00SLionel Sambuc.Nm 219435f2b00SLionel Sambuclibrary version 220435f2b00SLionel Sambuc.Pq zlib_version 221435f2b00SLionel Sambucis incompatible with the version assumed by the caller 222435f2b00SLionel Sambuc.Pq ZLIB_VERSION . 223435f2b00SLionel Sambuc.Fa msg 224435f2b00SLionel Sambucis set to null if there is no error message. 225435f2b00SLionel Sambuc.Fn deflateInit 226435f2b00SLionel Sambucdoes not perform any compression: this will be done by 227435f2b00SLionel Sambuc.Fn deflate . 228435f2b00SLionel Sambuc.It Fa int Fn deflate "z_streamp strm" "int flush" ; 229435f2b00SLionel Sambuc.Pp 230435f2b00SLionel Sambuc.Fn deflate 231435f2b00SLionel Sambuccompresses as much data as possible, and stops when the input 232435f2b00SLionel Sambucbuffer becomes empty or the output buffer becomes full. 233435f2b00SLionel SambucIt may introduce some output latency 234435f2b00SLionel Sambuc.Pq reading input without producing any output 235435f2b00SLionel Sambucexcept when forced to flush. 236435f2b00SLionel Sambuc.Pp 237435f2b00SLionel SambucThe detailed semantics are as follows. 238435f2b00SLionel Sambuc.Fn deflate 239435f2b00SLionel Sambucperforms one or both of the following actions: 240435f2b00SLionel Sambuc.Pp 241435f2b00SLionel SambucCompress more input starting at 242435f2b00SLionel Sambuc.Fa next_in 243435f2b00SLionel Sambucand update 244435f2b00SLionel Sambuc.Fa next_in 245435f2b00SLionel Sambucand 246435f2b00SLionel Sambuc.Fa avail_in 247435f2b00SLionel Sambucaccordingly. 248435f2b00SLionel SambucIf not all input can be processed 249435f2b00SLionel Sambuc(because there is not enough room in the output buffer), 250435f2b00SLionel Sambuc.Fa next_in 251435f2b00SLionel Sambucand 252435f2b00SLionel Sambuc.Fa avail_in 253435f2b00SLionel Sambucare updated and processing will resume at this point for the next call to 254435f2b00SLionel Sambuc.Fn deflate . 255435f2b00SLionel Sambuc.Pp 256435f2b00SLionel SambucProvide more output starting at 257435f2b00SLionel Sambuc.Fa next_out 258435f2b00SLionel Sambucand update 259435f2b00SLionel Sambuc.Fa next_out 260435f2b00SLionel Sambucand 261435f2b00SLionel Sambuc.Fa avail_out 262435f2b00SLionel Sambucaccordingly. 263435f2b00SLionel SambucThis action is forced if the parameter 264435f2b00SLionel Sambuc.Fa flush 265435f2b00SLionel Sambucis non-zero. 266435f2b00SLionel SambucForcing 267435f2b00SLionel Sambuc.Fa flush 268435f2b00SLionel Sambucfrequently degrades the compression ratio, 269435f2b00SLionel Sambucso this parameter should be set only when necessary 270435f2b00SLionel Sambuc.Pq in interactive applications . 271435f2b00SLionel SambucSome output may be provided even if 272435f2b00SLionel Sambuc.Fa flush 273435f2b00SLionel Sambucis not set. 274435f2b00SLionel Sambuc.Pp 275435f2b00SLionel SambucBefore the call to 276435f2b00SLionel Sambuc.Fn deflate , 277435f2b00SLionel Sambucthe application should ensure that at least 278435f2b00SLionel Sambucone of the actions is possible, by providing more input and/or consuming 279435f2b00SLionel Sambucmore output, and updating 280435f2b00SLionel Sambuc.Fa avail_in 281435f2b00SLionel Sambucor 282435f2b00SLionel Sambuc.Fa avail_out 283435f2b00SLionel Sambucaccordingly; 284435f2b00SLionel Sambuc.Fa avail_out 285435f2b00SLionel Sambucshould never be zero before the call. 286435f2b00SLionel SambucThe application can consume the compressed output when it wants, 287435f2b00SLionel Sambucfor example when the output buffer is full 288435f2b00SLionel Sambuc.Pq avail_out == 0 , 289435f2b00SLionel Sambucor after each call to 290435f2b00SLionel Sambuc.Fn deflate . 291435f2b00SLionel SambucIf 292435f2b00SLionel Sambuc.Fn deflate 293435f2b00SLionel Sambucreturns 294435f2b00SLionel Sambuc.Dv Z_OK 295435f2b00SLionel Sambucand with zero 296435f2b00SLionel Sambuc.Fa avail_out , 297435f2b00SLionel Sambucit must be called again after making room in the 298435f2b00SLionel Sambucoutput buffer because there might be more output pending. 299435f2b00SLionel Sambuc.Pp 300435f2b00SLionel SambucIf the parameter 301435f2b00SLionel Sambuc.Fa flush 302435f2b00SLionel Sambucis set to 303435f2b00SLionel Sambuc.Dv Z_SYNC_FLUSH , 304435f2b00SLionel Sambucall pending output is flushed to the output buffer and the output 305435f2b00SLionel Sambucis aligned on a byte boundary, so that the decompressor can get all 306435f2b00SLionel Sambucinput data available so far. 307435f2b00SLionel Sambuc(In particular, 308435f2b00SLionel Sambuc.Fa avail_in 309435f2b00SLionel Sambucis zero after the call if enough output space 310435f2b00SLionel Sambuchas been provided before the call.) 311435f2b00SLionel SambucFlushing may degrade compression for some compression algorithms 312435f2b00SLionel Sambucand so it should be used only when necessary. 313435f2b00SLionel Sambuc.Pp 314435f2b00SLionel SambucIf 315435f2b00SLionel Sambuc.Fa flush 316435f2b00SLionel Sambucis set to 317435f2b00SLionel Sambuc.Dv Z_FULL_FLUSH , 318435f2b00SLionel Sambucall output is flushed as with 319435f2b00SLionel Sambuc.Dv Z_SYNC_FLUSH , 320435f2b00SLionel Sambucand the compression state is reset so that decompression can restart from this 321435f2b00SLionel Sambucpoint if previous compressed data has been damaged or if random access 322435f2b00SLionel Sambucis desired. 323435f2b00SLionel SambucUsing 324435f2b00SLionel Sambuc.Dv Z_FULL_FLUSH 325435f2b00SLionel Sambuctoo often can seriously degrade the compression. 326435f2b00SLionel Sambuc.Pp 327435f2b00SLionel SambucIf 328435f2b00SLionel Sambuc.Fn deflate 329435f2b00SLionel Sambucreturns with avail_out == 0, this function must be called again 330435f2b00SLionel Sambucwith the same value of the flush parameter and more output space 331435f2b00SLionel Sambuc(updated 332435f2b00SLionel Sambuc.Fa avail_out ) , 333435f2b00SLionel Sambucuntil the flush is complete 334435f2b00SLionel Sambuc.Pf ( Fn deflate 335435f2b00SLionel Sambucreturns with non-zero 336435f2b00SLionel Sambuc.Fa avail_out ) . 337435f2b00SLionel Sambuc.Pp 338435f2b00SLionel SambucIf the parameter 339435f2b00SLionel Sambuc.Fa flush 340435f2b00SLionel Sambucis set to 341435f2b00SLionel Sambuc.Dv Z_FINISH , 342435f2b00SLionel Sambucpending input is processed, pending output is flushed and 343435f2b00SLionel Sambuc.Fn deflate 344435f2b00SLionel Sambucreturns with 345435f2b00SLionel Sambuc.Dv Z_STREAM_END 346435f2b00SLionel Sambucif there was enough output space; if 347435f2b00SLionel Sambuc.Fn deflate 348435f2b00SLionel Sambucreturns with 349435f2b00SLionel Sambuc.Dv Z_OK , 350435f2b00SLionel Sambucthis function must be called again with 351435f2b00SLionel Sambuc.Dv Z_FINISH 352435f2b00SLionel Sambucand more output space 353435f2b00SLionel Sambuc(updated 354435f2b00SLionel Sambuc.Fa avail_out 355435f2b00SLionel Sambucbut no more input data, until it returns with 356435f2b00SLionel Sambuc.Dv Z_STREAM_END 357435f2b00SLionel Sambucor an error. 358435f2b00SLionel SambucAfter 359435f2b00SLionel Sambuc.Fn deflate 360435f2b00SLionel Sambuchas returned 361435f2b00SLionel Sambuc.Dv Z_STREAM_END , 362435f2b00SLionel Sambucthe only possible operations on the stream are 363435f2b00SLionel Sambuc.Fn deflateReset 364435f2b00SLionel Sambucor 365435f2b00SLionel Sambuc.Fn deflateEnd . 366435f2b00SLionel Sambuc.Pp 367435f2b00SLionel Sambuc.Dv Z_FINISH 368435f2b00SLionel Sambuccan be used immediately after 369435f2b00SLionel Sambuc.Fn deflateInit 370435f2b00SLionel Sambucif all the compression is to be done in a single step. 371435f2b00SLionel SambucIn this case, 372435f2b00SLionel Sambuc.Fa avail_out 373435f2b00SLionel Sambucmust be at least 0.1% larger than 374435f2b00SLionel Sambuc.Fa avail_in 375435f2b00SLionel Sambucplus 12 bytes. 376435f2b00SLionel SambucIf 377435f2b00SLionel Sambuc.Fn deflate 378435f2b00SLionel Sambucdoes not return 379435f2b00SLionel Sambuc.Dv Z_STREAM_END , 380435f2b00SLionel Sambucthen it must be called again as described above. 381435f2b00SLionel Sambuc.Pp 382435f2b00SLionel Sambuc.Fn deflate 383435f2b00SLionel Sambucsets strm-\*[Gt]adler to the Adler-32 checksum of all input read so far 384435f2b00SLionel Sambuc(that is, 385435f2b00SLionel Sambuc.Fa total_in 386435f2b00SLionel Sambucbytes). 387435f2b00SLionel Sambuc.Pp 388435f2b00SLionel Sambuc.Fn deflate 389435f2b00SLionel Sambucmay update 390435f2b00SLionel Sambuc.Fa data_type 391435f2b00SLionel Sambucif it can make a good guess about the input data type 392435f2b00SLionel Sambuc.Pq Z_ASCII or Z_BINARY . 393435f2b00SLionel SambucIf in doubt, the data is considered binary. 394435f2b00SLionel SambucThis field is only for information purposes and does not affect 395435f2b00SLionel Sambucthe compression algorithm in any manner. 396435f2b00SLionel Sambuc.Pp 397435f2b00SLionel Sambuc.Fn deflate 398435f2b00SLionel Sambucreturns 399435f2b00SLionel Sambuc.Dv Z_OK 400435f2b00SLionel Sambucif some progress has been made 401435f2b00SLionel Sambuc.Pq more input processed or more output produced , 402435f2b00SLionel Sambuc.Dv Z_STREAM_END 403435f2b00SLionel Sambucif all input has been consumed and all output has been produced 404435f2b00SLionel Sambuc(only when 405435f2b00SLionel Sambuc.Fa flush 406435f2b00SLionel Sambucis set to 407435f2b00SLionel Sambuc.Dv Z_FINISH ) , 408435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 409435f2b00SLionel Sambucif the stream state was inconsistent 410435f2b00SLionel Sambuc(for example, if 411435f2b00SLionel Sambuc.Fa next_in 412435f2b00SLionel Sambucor 413435f2b00SLionel Sambuc.Fa next_out 414435f2b00SLionel Sambucwas 415435f2b00SLionel Sambuc.Dv NULL ) , 416435f2b00SLionel Sambuc.Dv Z_BUF_ERROR 417435f2b00SLionel Sambucif no progress is possible 418435f2b00SLionel Sambuc(for example, 419435f2b00SLionel Sambuc.Fa avail_in 420435f2b00SLionel Sambucor 421435f2b00SLionel Sambuc.Fa avail_out 422435f2b00SLionel Sambucwas zero). 423435f2b00SLionel Sambuc.It Fa int Fn deflateEnd "z_streamp strm" ; 424435f2b00SLionel Sambuc.Pp 425435f2b00SLionel SambucAll dynamically allocated data structures for this stream are freed. 426435f2b00SLionel SambucThis function discards any unprocessed input and does not flush any 427435f2b00SLionel Sambucpending output. 428435f2b00SLionel Sambuc.Pp 429435f2b00SLionel Sambuc.Fn deflateEnd 430435f2b00SLionel Sambucreturns 431435f2b00SLionel Sambuc.Dv Z_OK 432435f2b00SLionel Sambucif successful, 433435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 434435f2b00SLionel Sambucif the stream state was inconsistent, 435435f2b00SLionel Sambuc.Dv Z_DATA_ERROR 436435f2b00SLionel Sambucif the stream was freed prematurely 437435f2b00SLionel Sambuc.Pq some input or output was discarded . 438435f2b00SLionel SambucIn the error case, 439435f2b00SLionel Sambuc.Fa msg 440435f2b00SLionel Sambucmay be set but then points to a static string 441435f2b00SLionel Sambuc.Pq which must not be deallocated . 442435f2b00SLionel Sambuc.It Fa int Fn inflateInit "z_streamp strm" ; 443435f2b00SLionel SambucThe 444435f2b00SLionel Sambuc.Fn inflateInit 445435f2b00SLionel Sambucfunction initializes the internal stream state for decompression. 446435f2b00SLionel SambucThe fields 447435f2b00SLionel Sambuc.Fa next_in , 448435f2b00SLionel Sambuc.Fa avail_in , 449435f2b00SLionel Sambuc.Fa zalloc , 450435f2b00SLionel Sambuc.Fa zfree , 451435f2b00SLionel Sambucand 452435f2b00SLionel Sambuc.Fa opaque 453435f2b00SLionel Sambucmust be initialized before by the caller. 454435f2b00SLionel SambucIf 455435f2b00SLionel Sambuc.Fa next_in 456435f2b00SLionel Sambucis not 457435f2b00SLionel Sambuc.Dv Z_NULL 458435f2b00SLionel Sambucand 459435f2b00SLionel Sambuc.Fa avail_in 460435f2b00SLionel Sambucis large enough 461435f2b00SLionel Sambuc.Pq the exact value depends on the compression method , 462435f2b00SLionel Sambuc.Fn inflateInit 463435f2b00SLionel Sambucdetermines the compression method from the 464435f2b00SLionel Sambuc.Nm 465435f2b00SLionel Sambucheader and allocates all data structures accordingly; 466435f2b00SLionel Sambucotherwise the allocation will be deferred to the first call to 467435f2b00SLionel Sambuc.Fn inflate . 468435f2b00SLionel SambucIf 469435f2b00SLionel Sambuc.Fa zalloc 470435f2b00SLionel Sambucand 471435f2b00SLionel Sambuc.Fa zfree 472435f2b00SLionel Sambucare set to 473435f2b00SLionel Sambuc.Dv Z_NULL , 474435f2b00SLionel Sambuc.Fn inflateInit 475435f2b00SLionel Sambucupdates them to use default allocation functions. 476435f2b00SLionel Sambuc.Pp 477435f2b00SLionel Sambuc.Fn inflateInit 478435f2b00SLionel Sambucreturns 479435f2b00SLionel Sambuc.Dv Z_OK 480435f2b00SLionel Sambucif successful, 481435f2b00SLionel Sambuc.Dv Z_MEM_ERROR 482435f2b00SLionel Sambucif there was not enough memory, 483435f2b00SLionel Sambuc.Dv Z_VERSION_ERROR 484435f2b00SLionel Sambucif the 485435f2b00SLionel Sambuc.Nm 486435f2b00SLionel Sambuclibrary version is incompatible with the version assumed by the caller. 487435f2b00SLionel Sambuc.Fa msg 488435f2b00SLionel Sambucis set to null if there is no error message. 489435f2b00SLionel Sambuc.Fn inflateInit 490435f2b00SLionel Sambucdoes not perform any decompression apart from reading the 491435f2b00SLionel Sambuc.Nm 492435f2b00SLionel Sambucheader if present: this will be done by 493435f2b00SLionel Sambuc.Fn inflate . 494435f2b00SLionel Sambuc(So 495435f2b00SLionel Sambuc.Fa next_in 496435f2b00SLionel Sambucand 497435f2b00SLionel Sambuc.Fa avail_in 498435f2b00SLionel Sambucmay be modified, 499435f2b00SLionel Sambucbut 500435f2b00SLionel Sambuc.Fa next_out 501435f2b00SLionel Sambucand 502435f2b00SLionel Sambuc.Fa avail_out 503435f2b00SLionel Sambucare unchanged.) 504435f2b00SLionel Sambuc.It Fa int Fn inflate "z_streamp strm" "int flush" ; 505435f2b00SLionel Sambuc.Fn inflate 506435f2b00SLionel Sambucdecompresses as much data as possible, and stops when the input 507435f2b00SLionel Sambucbuffer becomes empty or the output buffer becomes full. 508435f2b00SLionel SambucIt may introduce some output latency 509435f2b00SLionel Sambuc.Pq reading input without producing any output 510435f2b00SLionel Sambucexcept when forced to flush. 511435f2b00SLionel Sambuc.Pp 512435f2b00SLionel SambucThe detailed semantics are as follows. 513435f2b00SLionel Sambuc.Fn inflate 514435f2b00SLionel Sambucperforms one or both of the following actions: 515435f2b00SLionel Sambuc.Pp 516435f2b00SLionel SambucDecompress more input starting at 517435f2b00SLionel Sambuc.Fa next_in 518435f2b00SLionel Sambucand update 519435f2b00SLionel Sambuc.Fa next_in 520435f2b00SLionel Sambucand 521435f2b00SLionel Sambuc.Fa avail_in 522435f2b00SLionel Sambucaccordingly. 523435f2b00SLionel SambucIf not all input can be processed 524435f2b00SLionel Sambuc(because there is not enough room in the output buffer), 525435f2b00SLionel Sambuc.Fa next_in 526435f2b00SLionel Sambucis updated and processing will resume at this point for the next call to 527435f2b00SLionel Sambuc.Fn inflate . 528435f2b00SLionel Sambuc.Pp 529435f2b00SLionel SambucProvide more output starting at 530435f2b00SLionel Sambuc.Fa next_out 531435f2b00SLionel Sambucand update 532435f2b00SLionel Sambuc.Fa next_out 533435f2b00SLionel Sambucand 534435f2b00SLionel Sambuc.Fa avail_out 535435f2b00SLionel Sambucaccordingly. 536435f2b00SLionel Sambuc.Fn inflate 537435f2b00SLionel Sambucprovides as much output as possible, 538435f2b00SLionel Sambucuntil there is no more input data or no more space in the output buffer 539435f2b00SLionel Sambuc.Pq see below about the flush parameter . 540435f2b00SLionel Sambuc.Pp 541435f2b00SLionel SambucBefore the call to 542435f2b00SLionel Sambuc.Fn inflate , 543435f2b00SLionel Sambucthe application should ensure that at least one of the actions is possible, 544435f2b00SLionel Sambucby providing more input and/or consuming more output, 545435f2b00SLionel Sambucand updating the next_* and avail_* values accordingly. 546435f2b00SLionel SambucThe application can consume the uncompressed output when it wants, 547435f2b00SLionel Sambucfor example when the output buffer is full (avail_out == 0), 548435f2b00SLionel Sambucor after each call to 549435f2b00SLionel Sambuc.Fn inflate . 550435f2b00SLionel SambucIf 551435f2b00SLionel Sambuc.Fn inflate 552435f2b00SLionel Sambucreturns 553435f2b00SLionel Sambuc.Dv Z_OK 554435f2b00SLionel Sambucand with zero 555435f2b00SLionel Sambuc.Fa avail_out , 556435f2b00SLionel Sambucit must be called again after making room 557435f2b00SLionel Sambucin the output buffer because there might be more output pending. 558435f2b00SLionel Sambuc.Pp 559435f2b00SLionel SambucIf the parameter 560435f2b00SLionel Sambuc.Fa flush 561435f2b00SLionel Sambucis set to 562435f2b00SLionel Sambuc.Dv Z_SYNC_FLUSH , 563435f2b00SLionel Sambuc.Fn inflate 564435f2b00SLionel Sambucflushes as much output as possible to the output buffer. 565435f2b00SLionel SambucThe flushing behavior of 566435f2b00SLionel Sambuc.Fn inflate 567435f2b00SLionel Sambucis not specified for values of the flush parameter other than 568435f2b00SLionel Sambuc.Dv Z_SYNC_FLUSH 569435f2b00SLionel Sambucand 570435f2b00SLionel Sambuc.Dv Z_FINISH , 571435f2b00SLionel Sambucbut the current implementation actually flushes as much output 572435f2b00SLionel Sambucas possible anyway. 573435f2b00SLionel Sambuc.Pp 574435f2b00SLionel Sambuc.Fn inflate 575435f2b00SLionel Sambucshould normally be called until it returns 576435f2b00SLionel Sambuc.Dv Z_STREAM_END 577435f2b00SLionel Sambucor an error. 578435f2b00SLionel SambucHowever if all decompression is to be performed in a single step 579435f2b00SLionel Sambuc.Pq a single call to inflate , 580435f2b00SLionel Sambucthe parameter 581435f2b00SLionel Sambuc.Fa flush 582435f2b00SLionel Sambucshould be set to 583435f2b00SLionel Sambuc.Dv Z_FINISH . 584435f2b00SLionel SambucIn this case all pending input is processed and all pending output is flushed; 585435f2b00SLionel Sambuc.Fa avail_out 586435f2b00SLionel Sambucmust be large enough to hold all the uncompressed data. 587435f2b00SLionel Sambuc(The size of the uncompressed data may have been saved 588435f2b00SLionel Sambucby the compressor for this purpose.) 589435f2b00SLionel SambucThe next operation on this stream must be 590435f2b00SLionel Sambuc.Fn inflateEnd 591435f2b00SLionel Sambucto deallocate the decompression state. 592435f2b00SLionel SambucThe use of 593435f2b00SLionel Sambuc.Dv Z_FINISH 594435f2b00SLionel Sambucis never required, but can be used to inform 595435f2b00SLionel Sambuc.Fn inflate 596435f2b00SLionel Sambucthat a faster routine may be used for the single 597435f2b00SLionel Sambuc.Fn inflate 598435f2b00SLionel Sambuccall. 599435f2b00SLionel Sambuc.Pp 600435f2b00SLionel SambucIf a preset dictionary is needed at this point (see 601435f2b00SLionel Sambuc.Fn inflateSetDictionary 602435f2b00SLionel Sambucbelow), 603435f2b00SLionel Sambuc.Fn inflate 604435f2b00SLionel Sambucsets strm-\*[Gt]adler to the Adler-32 checksum of the dictionary 605435f2b00SLionel Sambucchosen by the compressor and returns 606435f2b00SLionel Sambuc.Dv Z_NEED_DICT ; 607435f2b00SLionel Sambucotherwise it sets strm-\*[Gt]adler to the Adler-32 checksum of all output produced 608435f2b00SLionel Sambucso far 609435f2b00SLionel Sambuc(that is, 610435f2b00SLionel Sambuc.Fa total_out 611435f2b00SLionel Sambucbytes) 612435f2b00SLionel Sambucand returns 613435f2b00SLionel Sambuc.Dv Z_OK , 614435f2b00SLionel Sambuc.Dv Z_STREAM_END , 615435f2b00SLionel Sambucor an error code as described below. 616435f2b00SLionel SambucAt the end of the stream, 617435f2b00SLionel Sambuc.Fn inflate 618435f2b00SLionel Sambucchecks that its computed Adler-32 checksum is equal to that saved by the 619435f2b00SLionel Sambuccompressor and returns 620435f2b00SLionel Sambuc.Dv Z_STREAM_END 621435f2b00SLionel Sambuconly if the checksum is correct. 622435f2b00SLionel Sambuc.Pp 623435f2b00SLionel Sambuc.Fn inflate 624435f2b00SLionel Sambucreturns 625435f2b00SLionel Sambuc.Dv Z_OK 626435f2b00SLionel Sambucif some progress has been made 627435f2b00SLionel Sambuc.Pq more input processed or more output produced , 628435f2b00SLionel Sambuc.Dv Z_STREAM_END 629435f2b00SLionel Sambucif the end of the compressed data has been reached and all uncompressed output 630435f2b00SLionel Sambuchas been produced, 631435f2b00SLionel Sambuc.Dv Z_NEED_DICT 632435f2b00SLionel Sambucif a preset dictionary is needed at this point, 633435f2b00SLionel Sambuc.Dv Z_DATA_ERROR 634435f2b00SLionel Sambucif the input data was corrupted (input stream not conforming to the 635435f2b00SLionel Sambuc.Nm 636435f2b00SLionel Sambucformat or incorrect Adler-32 checksum), 637435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 638435f2b00SLionel Sambucif the stream structure was inconsistent 639435f2b00SLionel Sambuc(for example, if 640435f2b00SLionel Sambuc.Fa next_in 641435f2b00SLionel Sambucor 642435f2b00SLionel Sambuc.Fa next_out 643435f2b00SLionel Sambucwas 644435f2b00SLionel Sambuc.Dv NULL ) , 645435f2b00SLionel Sambuc.Dv Z_MEM_ERROR 646435f2b00SLionel Sambucif there was not enough memory, 647435f2b00SLionel Sambuc.Dv Z_BUF_ERROR 648435f2b00SLionel Sambucif no progress is possible or if there was not enough room in the output buffer 649435f2b00SLionel Sambucwhen 650435f2b00SLionel Sambuc.Dv Z_FINISH 651435f2b00SLionel Sambucis used. 652435f2b00SLionel SambucIn the 653435f2b00SLionel Sambuc.Dv Z_DATA_ERROR 654435f2b00SLionel Sambuccase, the application may then call 655435f2b00SLionel Sambuc.Fn inflateSync 656435f2b00SLionel Sambucto look for a good compression block. 657435f2b00SLionel Sambuc.It Fa int Fn inflateEnd "z_streamp strm" ; 658435f2b00SLionel SambucAll dynamically allocated data structures for this stream are freed. 659435f2b00SLionel SambucThis function discards any unprocessed input and does not flush any 660435f2b00SLionel Sambucpending output. 661435f2b00SLionel Sambuc.Pp 662435f2b00SLionel Sambuc.Fn inflateEnd 663435f2b00SLionel Sambucreturns 664435f2b00SLionel Sambuc.Dv Z_OK 665435f2b00SLionel Sambucif successful, or 666435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 667435f2b00SLionel Sambucif the stream state was inconsistent. 668435f2b00SLionel SambucIn the error case, 669435f2b00SLionel Sambuc.Fa msg 670435f2b00SLionel Sambucmay be set but then points to a static string 671435f2b00SLionel Sambuc.Pq which must not be deallocated . 672435f2b00SLionel Sambuc.El 673435f2b00SLionel Sambuc.Sh ADVANCED FUNCTIONS 674435f2b00SLionel SambucThe following functions are needed only in some special applications. 675435f2b00SLionel Sambuc.Bl -tag -width Ds 676435f2b00SLionel Sambuc.It Fa int Fn deflateInit2 "z_streamp strm" "int level" "int method" \ 677435f2b00SLionel Sambuc"int windowBits" "int memLevel" "int strategy" ; 678435f2b00SLionel Sambuc.Pp 679435f2b00SLionel SambucThis is another version of 680435f2b00SLionel Sambuc.Fn deflateInit 681435f2b00SLionel Sambucwith more compression options. 682435f2b00SLionel SambucThe fields 683435f2b00SLionel Sambuc.Fa next_in , 684435f2b00SLionel Sambuc.Fa zalloc , 685435f2b00SLionel Sambuc.Fa zfree , 686435f2b00SLionel Sambucand 687435f2b00SLionel Sambuc.Fa opaque 688435f2b00SLionel Sambucmust be initialized before by the caller. 689435f2b00SLionel Sambuc.Pp 690435f2b00SLionel SambucThe 691435f2b00SLionel Sambuc.Fa method 692435f2b00SLionel Sambucparameter is the compression method. 693435f2b00SLionel SambucIt must be 694435f2b00SLionel Sambuc.Dv Z_DEFLATED 695435f2b00SLionel Sambucin this version of the library. 696435f2b00SLionel Sambuc.Pp 697435f2b00SLionel SambucThe 698435f2b00SLionel Sambuc.Fa windowBits 699435f2b00SLionel Sambucparameter is the base two logarithm of the window size 700435f2b00SLionel Sambuc.Pq the size of the history buffer . 701435f2b00SLionel SambucIt should be in the range 8..15 for this version of the library. 702435f2b00SLionel SambucLarger values of this parameter result in better compression 703435f2b00SLionel Sambucat the expense of memory usage. 704435f2b00SLionel SambucThe default value is 15 if 705435f2b00SLionel Sambuc.Fn deflateInit 706435f2b00SLionel Sambucis used instead. 707435f2b00SLionel Sambuc.Pp 708435f2b00SLionel SambucThe 709435f2b00SLionel Sambuc.Fa memLevel 710435f2b00SLionel Sambucparameter specifies how much memory should be allocated 711435f2b00SLionel Sambucfor the internal compression state. 712435f2b00SLionel SambucmemLevel=1 uses minimum memory but is slow and reduces compression ratio; 713435f2b00SLionel SambucmemLevel=9 uses maximum memory for optimal speed. 714435f2b00SLionel SambucThe default value is 8. 715435f2b00SLionel SambucSee 716435f2b00SLionel Sambuc.In zconf.h 717435f2b00SLionel Sambucfor total memory usage as a function of 718435f2b00SLionel Sambuc.Fa windowBits 719435f2b00SLionel Sambucand 720435f2b00SLionel Sambuc.Fa memLevel . 721435f2b00SLionel Sambuc.Pp 722435f2b00SLionel SambucThe 723435f2b00SLionel Sambuc.Fa strategy 724435f2b00SLionel Sambucparameter is used to tune the compression algorithm. 725435f2b00SLionel SambucUse the value 726435f2b00SLionel Sambuc.Dv Z_DEFAULT_STRATEGY 727435f2b00SLionel Sambucfor normal data; 728435f2b00SLionel Sambuc.Dv Z_FILTERED 729435f2b00SLionel Sambucfor data produced by a filter 730435f2b00SLionel Sambuc.Pq or predictor ; 731435f2b00SLionel Sambucor 732435f2b00SLionel Sambuc.Dv Z_HUFFMAN_ONLY 733435f2b00SLionel Sambucto force Huffman encoding only 734435f2b00SLionel Sambuc.Pq no string match . 735435f2b00SLionel SambucFiltered data consists mostly of small values with a 736435f2b00SLionel Sambucsomewhat random distribution. 737435f2b00SLionel SambucIn this case, the compression algorithm is tuned to compress them better. 738435f2b00SLionel SambucThe effect of 739435f2b00SLionel Sambuc.Dv Z_FILTERED 740435f2b00SLionel Sambucis to force more Huffman coding and less string matching; 741435f2b00SLionel Sambucit is somewhat intermediate between 742435f2b00SLionel Sambuc.Dv Z_DEFAULT 743435f2b00SLionel Sambucand 744435f2b00SLionel Sambuc.Dv Z_HUFFMAN_ONLY . 745435f2b00SLionel SambucThe 746435f2b00SLionel Sambuc.Fa strategy 747435f2b00SLionel Sambucparameter only affects the compression ratio but not the correctness of the 748435f2b00SLionel Sambuccompressed output, even if it is not set appropriately. 749435f2b00SLionel Sambuc.Pp 750435f2b00SLionel Sambuc.Fn deflateInit2 751435f2b00SLionel Sambucreturns 752435f2b00SLionel Sambuc.Dv Z_OK 753435f2b00SLionel Sambucif successful, 754435f2b00SLionel Sambuc.Dv Z_MEM_ERROR 755435f2b00SLionel Sambucif there was not enough memory, 756435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 757435f2b00SLionel Sambucif a parameter is invalid 758435f2b00SLionel Sambuc.Pq such as an invalid method . 759435f2b00SLionel Sambuc.Fa msg 760435f2b00SLionel Sambucis set to null if there is no error message. 761435f2b00SLionel Sambuc.Fn deflateInit2 762435f2b00SLionel Sambucdoes not perform any compression: this will be done by 763435f2b00SLionel Sambuc.Fn deflate . 764435f2b00SLionel Sambuc.It Fa int Fn deflateSetDictionary "z_streamp strm" \ 765435f2b00SLionel Sambuc"const Bytef *dictionary" "uInt dictLength" ; 766435f2b00SLionel Sambuc.Pp 767435f2b00SLionel SambucInitializes the compression dictionary from the given byte sequence 768435f2b00SLionel Sambucwithout producing any compressed output. 769435f2b00SLionel SambucThis function must be called immediately after 770435f2b00SLionel Sambuc.Fn deflateInit , 771435f2b00SLionel Sambuc.Fn deflateInit2 , 772435f2b00SLionel Sambucor 773435f2b00SLionel Sambuc.Fn deflateReset , 774435f2b00SLionel Sambucbefore any call to 775435f2b00SLionel Sambuc.Fn deflate . 776435f2b00SLionel SambucThe compressor and decompressor must use exactly the same dictionary 777435f2b00SLionel Sambuc(see 778435f2b00SLionel Sambuc.Fn inflateSetDictionary ) . 779435f2b00SLionel Sambuc.Pp 780435f2b00SLionel SambucThe dictionary should consist of strings 781435f2b00SLionel Sambuc.Pq byte sequences 782435f2b00SLionel Sambucthat are likely to be encountered later in the data to be compressed, 783435f2b00SLionel Sambucwith the most commonly used strings preferably put towards 784435f2b00SLionel Sambucthe end of the dictionary. 785435f2b00SLionel SambucUsing a dictionary is most useful when the data to be compressed is short 786435f2b00SLionel Sambucand can be predicted with good accuracy; 787435f2b00SLionel Sambucthe data can then be compressed better than with the default empty dictionary. 788435f2b00SLionel Sambuc.Pp 789435f2b00SLionel SambucDepending on the size of the compression data structures selected by 790435f2b00SLionel Sambuc.Fn deflateInit 791435f2b00SLionel Sambucor 792435f2b00SLionel Sambuc.Fn deflateInit2 , 793435f2b00SLionel Sambuca part of the dictionary may in effect be discarded, 794435f2b00SLionel Sambucfor example if the dictionary is larger than the window size in 795435f2b00SLionel Sambuc.Fn deflate 796435f2b00SLionel Sambucor 797435f2b00SLionel Sambuc.Fn deflate2 . 798435f2b00SLionel SambucThus the strings most likely to be useful should be 799435f2b00SLionel Sambucput at the end of the dictionary, not at the front. 800435f2b00SLionel Sambuc.Pp 801435f2b00SLionel SambucUpon return of this function, strm-\*[Gt]adler is set to the Adler-32 value 802435f2b00SLionel Sambucof the dictionary; the decompressor may later use this value to determine 803435f2b00SLionel Sambucwhich dictionary has been used by the compressor. 804435f2b00SLionel Sambuc(The Adler-32 value applies to the whole dictionary even if only a subset 805435f2b00SLionel Sambucof the dictionary is actually used by the compressor.) 806435f2b00SLionel Sambuc.Pp 807435f2b00SLionel Sambuc.Fn deflateSetDictionary 808435f2b00SLionel Sambucreturns 809435f2b00SLionel Sambuc.Dv Z_OK 810435f2b00SLionel Sambucif successful, 811435f2b00SLionel Sambucor 812435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 813435f2b00SLionel Sambucif a parameter is invalid 814435f2b00SLionel Sambuc.Pq such as NULL dictionary 815435f2b00SLionel Sambucor the stream state is inconsistent 816435f2b00SLionel Sambuc(for example if 817435f2b00SLionel Sambuc.Fn deflate 818435f2b00SLionel Sambuchas already been called for this stream or if the compression method is bsort). 819435f2b00SLionel Sambuc.Fn deflateSetDictionary 820435f2b00SLionel Sambucdoes not perform any compression: this will be done by 821435f2b00SLionel Sambuc.Fn deflate . 822435f2b00SLionel Sambuc.It Fa int Fn deflateCopy "z_streamp dest" "z_streamp source" ; 823435f2b00SLionel Sambuc.Pp 824435f2b00SLionel SambucThe 825435f2b00SLionel Sambuc.Fn deflateCopy 826435f2b00SLionel Sambucfunction sets the destination stream as a complete copy of the source stream. 827435f2b00SLionel Sambuc.Pp 828435f2b00SLionel SambucThis function can be useful when several compression strategies will be 829435f2b00SLionel Sambuctried, for example when there are several ways of pre-processing the input 830435f2b00SLionel Sambucdata with a filter. 831435f2b00SLionel SambucThe streams that will be discarded should then be freed by calling 832435f2b00SLionel Sambuc.Fn deflateEnd . 833435f2b00SLionel SambucNote that 834435f2b00SLionel Sambuc.Fn deflateCopy 835435f2b00SLionel Sambucduplicates the internal compression state which can be quite large, 836435f2b00SLionel Sambucso this strategy is slow and can consume lots of memory. 837435f2b00SLionel Sambuc.Pp 838435f2b00SLionel Sambuc.Fn deflateCopy 839435f2b00SLionel Sambucreturns 840435f2b00SLionel Sambuc.Dv Z_OK 841435f2b00SLionel Sambucif successful, 842435f2b00SLionel Sambuc.Dv Z_MEM_ERROR 843435f2b00SLionel Sambucif there was not enough memory, 844435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 845435f2b00SLionel Sambucif the source stream state was inconsistent 846435f2b00SLionel Sambuc(such as 847435f2b00SLionel Sambuc.Fa zalloc 848435f2b00SLionel Sambucbeing NULL). 849435f2b00SLionel Sambuc.Fa msg 850435f2b00SLionel Sambucis left unchanged in both source and destination. 851435f2b00SLionel Sambuc.It Fa int Fn deflateReset "z_streamp strm" ; 852435f2b00SLionel Sambuc.Pp 853435f2b00SLionel SambucThis function is equivalent to 854435f2b00SLionel Sambuc.Fn deflateEnd 855435f2b00SLionel Sambucfollowed by 856435f2b00SLionel Sambuc.Fn deflateInit , 857435f2b00SLionel Sambucbut does not free and reallocate all the internal compression state. 858435f2b00SLionel SambucThe stream will keep the same compression level and any other attributes 859435f2b00SLionel Sambucthat may have been set by 860435f2b00SLionel Sambuc.Fn deflateInit2 . 861435f2b00SLionel Sambuc.Pp 862435f2b00SLionel Sambuc.Fn deflateReset 863435f2b00SLionel Sambucreturns 864435f2b00SLionel Sambuc.Dv Z_OK 865435f2b00SLionel Sambucif successful, or 866435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 867435f2b00SLionel Sambucif the source stream state was inconsistent 868435f2b00SLionel Sambuc(such as 869435f2b00SLionel Sambuc.Fa zalloc 870435f2b00SLionel Sambucor 871435f2b00SLionel Sambuc.Fa state 872435f2b00SLionel Sambucbeing NULL). 873435f2b00SLionel Sambuc.It Fa int Fn deflateParams "z_streamp strm" "int level" "int strategy" ; 874435f2b00SLionel Sambuc.Pp 875435f2b00SLionel SambucThe 876435f2b00SLionel Sambuc.Fn deflateParams 877435f2b00SLionel Sambucfunction dynamically updates the compression level and compression strategy. 878435f2b00SLionel SambucThe interpretation of level and strategy is as in 879435f2b00SLionel Sambuc.Fn deflateInit2 . 880435f2b00SLionel SambucThis can be used to switch between compression and straight copy 881435f2b00SLionel Sambucof the input data, or to switch to a different kind of input data 882435f2b00SLionel Sambucrequiring a different strategy. 883435f2b00SLionel SambucIf the compression level is changed, the input available so far 884435f2b00SLionel Sambucis compressed with the old level 885435f2b00SLionel Sambuc.Pq and may be flushed ; 886435f2b00SLionel Sambucthe new level will take effect only at the next call to 887435f2b00SLionel Sambuc.Fn deflate . 888435f2b00SLionel Sambuc.Pp 889435f2b00SLionel SambucBefore the call to 890435f2b00SLionel Sambuc.Fn deflateParams , 891435f2b00SLionel Sambucthe stream state must be set as for a call to 892435f2b00SLionel Sambuc.Fn deflate , 893435f2b00SLionel Sambucsince the currently available input may have to be compressed and flushed. 894435f2b00SLionel SambucIn particular, strm-\*[Gt]avail_out must be non-zero. 895435f2b00SLionel Sambuc.Pp 896435f2b00SLionel Sambuc.Fn deflateParams 897435f2b00SLionel Sambucreturns 898435f2b00SLionel Sambuc.Dv Z_OK 899435f2b00SLionel Sambucif successful, 900435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 901435f2b00SLionel Sambucif the source stream state was inconsistent or if a parameter was invalid, or 902435f2b00SLionel Sambuc.Dv Z_BUF_ERROR 903435f2b00SLionel Sambucif strm-\*[Gt]avail_out was zero. 904435f2b00SLionel Sambuc.It Fa int Fn inflateInit2 "z_streamp strm" "int windowBits" ; 905435f2b00SLionel Sambuc.Pp 906435f2b00SLionel SambucThis is another version of 907435f2b00SLionel Sambuc.Fn inflateInit 908435f2b00SLionel Sambucwith an extra parameter. 909435f2b00SLionel SambucThe fields 910435f2b00SLionel Sambuc.Fa next_in , 911435f2b00SLionel Sambuc.Fa avail_in , 912435f2b00SLionel Sambuc.Fa zalloc , 913435f2b00SLionel Sambuc.Fa zfree , 914435f2b00SLionel Sambucand 915435f2b00SLionel Sambuc.Fa opaque 916435f2b00SLionel Sambucmust be initialized before by the caller. 917435f2b00SLionel Sambuc.Pp 918435f2b00SLionel SambucThe 919435f2b00SLionel Sambuc.Fa windowBits 920435f2b00SLionel Sambucparameter is the base two logarithm of the maximum window size 921435f2b00SLionel Sambuc.Pq the size of the history buffer . 922435f2b00SLionel SambucIt should be in the range 8..15 for this version of the library. 923435f2b00SLionel SambucThe default value is 15 if 924435f2b00SLionel Sambuc.Fn inflateInit 925435f2b00SLionel Sambucis used instead. 926435f2b00SLionel SambucIf a compressed stream with a larger window size is given as input, 927435f2b00SLionel Sambuc.Fn inflate 928435f2b00SLionel Sambucwill return with the error code 929435f2b00SLionel Sambuc.Dv Z_DATA_ERROR 930435f2b00SLionel Sambucinstead of trying to allocate a larger window. 931435f2b00SLionel Sambuc.Pp 932435f2b00SLionel Sambuc.Fn inflateInit2 933435f2b00SLionel Sambucreturns 934435f2b00SLionel Sambuc.Dv Z_OK 935435f2b00SLionel Sambucif successful, 936435f2b00SLionel Sambuc.Dv Z_MEM_ERROR 937435f2b00SLionel Sambucif there was not enough memory, 938435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 939435f2b00SLionel Sambucif a parameter is invalid 940435f2b00SLionel Sambuc(such as a negative 941435f2b00SLionel Sambuc.Fa memLevel ) . 942435f2b00SLionel Sambuc.Fa msg 943435f2b00SLionel Sambucis set to null if there is no error message. 944435f2b00SLionel Sambuc.Fn inflateInit2 945435f2b00SLionel Sambucdoes not perform any decompression apart from reading the 946435f2b00SLionel Sambuc.Nm 947435f2b00SLionel Sambucheader if present: this will be done by 948435f2b00SLionel Sambuc.Fn inflate . 949435f2b00SLionel Sambuc(So 950435f2b00SLionel Sambuc.Fa next_in 951435f2b00SLionel Sambucand 952435f2b00SLionel Sambuc.Fa avail_in 953435f2b00SLionel Sambucmay be modified, but 954435f2b00SLionel Sambuc.Fa next_out 955435f2b00SLionel Sambucand 956435f2b00SLionel Sambuc.Fa avail_out 957435f2b00SLionel Sambucare unchanged.) 958435f2b00SLionel Sambuc.It Fa int Fn inflateSetDictionary "z_streamp strm" \ 959435f2b00SLionel Sambuc"const Bytef *dictionary" "uInt dictLength" ; 960435f2b00SLionel Sambuc.Pp 961435f2b00SLionel SambucInitializes the decompression dictionary from the given uncompressed byte 962435f2b00SLionel Sambucsequence. 963435f2b00SLionel SambucThis function must be called immediately after a call to 964435f2b00SLionel Sambuc.Fn inflate 965435f2b00SLionel Sambucif this call returned 966435f2b00SLionel Sambuc.Dv Z_NEED_DICT . 967435f2b00SLionel SambucThe dictionary chosen by the compressor can be determined from the 968435f2b00SLionel SambucAdler-32 value returned by this call to 969435f2b00SLionel Sambuc.Fn inflate . 970435f2b00SLionel SambucThe compressor and decompressor must use exactly the same dictionary 971435f2b00SLionel Sambuc(see 972435f2b00SLionel Sambuc.Fn deflateSetDictionary ) . 973435f2b00SLionel Sambuc.Pp 974435f2b00SLionel Sambuc.Fn inflateSetDictionary 975435f2b00SLionel Sambucreturns 976435f2b00SLionel Sambuc.Dv Z_OK 977435f2b00SLionel Sambucif successful, 978435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 979435f2b00SLionel Sambucif a parameter is invalid 980435f2b00SLionel Sambuc.Pq such as NULL dictionary 981435f2b00SLionel Sambucor the stream state is inconsistent, 982435f2b00SLionel Sambuc.Dv Z_DATA_ERROR 983435f2b00SLionel Sambucif the given dictionary doesn't match the expected one 984435f2b00SLionel Sambuc.Pq incorrect Adler-32 value . 985435f2b00SLionel Sambuc.Fn inflateSetDictionary 986435f2b00SLionel Sambucdoes not perform any decompression: this will be done by subsequent calls of 987435f2b00SLionel Sambuc.Fn inflate . 988435f2b00SLionel Sambuc.It Fa int Fn inflateSync "z_streamp strm" ; 989435f2b00SLionel Sambuc.Pp 990435f2b00SLionel SambucSkips invalid compressed data until a full flush point 991435f2b00SLionel Sambuc(see above the description of 992435f2b00SLionel Sambuc.Fn deflate 993435f2b00SLionel Sambucwith 994435f2b00SLionel Sambuc.Dv Z_FULL_FLUSH ) 995435f2b00SLionel Sambuccan be found, or until all available input is skipped. 996435f2b00SLionel SambucNo output is provided. 997435f2b00SLionel Sambuc.Pp 998435f2b00SLionel Sambuc.Fn inflateSync 999435f2b00SLionel Sambucreturns 1000435f2b00SLionel Sambuc.Dv Z_OK 1001435f2b00SLionel Sambucif a full flush point has been found, 1002435f2b00SLionel Sambuc.Dv Z_BUF_ERROR 1003435f2b00SLionel Sambucif no more input was provided, 1004435f2b00SLionel Sambuc.Dv Z_DATA_ERROR 1005435f2b00SLionel Sambucif no flush point has been found, or 1006435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 1007435f2b00SLionel Sambucif the stream structure was inconsistent. 1008435f2b00SLionel SambucIn the success case, the application may save the current value of 1009435f2b00SLionel Sambuc.Fa total_in 1010435f2b00SLionel Sambucwhich indicates where valid compressed data was found. 1011435f2b00SLionel SambucIn the error case, the application may repeatedly call 1012435f2b00SLionel Sambuc.Fn inflateSync , 1013435f2b00SLionel Sambucproviding more input each time, until success or end of the input data. 1014435f2b00SLionel Sambuc.It Fa int Fn inflateReset "z_streamp strm" ; 1015435f2b00SLionel Sambuc.Pp 1016435f2b00SLionel SambucThis function is equivalent to 1017435f2b00SLionel Sambuc.Fn inflateEnd 1018435f2b00SLionel Sambucfollowed by 1019435f2b00SLionel Sambuc.Fn inflateInit , 1020435f2b00SLionel Sambucbut does not free and reallocate all the internal decompression state. 1021435f2b00SLionel SambucThe stream will keep attributes that may have been set by 1022435f2b00SLionel Sambuc.Fn inflateInit2 . 1023435f2b00SLionel Sambuc.Pp 1024435f2b00SLionel Sambuc.Fn inflateReset 1025435f2b00SLionel Sambucreturns 1026435f2b00SLionel Sambuc.Dv Z_OK 1027435f2b00SLionel Sambucif successful, or 1028435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 1029435f2b00SLionel Sambucif the source stream state was inconsistent 1030435f2b00SLionel Sambuc(such as 1031435f2b00SLionel Sambuc.Fa zalloc 1032435f2b00SLionel Sambucor 1033435f2b00SLionel Sambuc.Fa state 1034435f2b00SLionel Sambucbeing NULL). 1035435f2b00SLionel Sambuc.El 1036435f2b00SLionel Sambuc.Sh UTILITY FUNCTIONS 1037435f2b00SLionel SambucThe following utility functions are implemented on top of the 1038435f2b00SLionel Sambucbasic stream-oriented functions. 1039435f2b00SLionel SambucTo simplify the interface, 1040435f2b00SLionel Sambucsome default options are assumed (compression level and memory usage, 1041435f2b00SLionel Sambucstandard memory allocation functions). 1042435f2b00SLionel SambucThe source code of these utility functions can easily be modified 1043435f2b00SLionel Sambucif you need special options. 1044435f2b00SLionel Sambuc.Bl -tag -width Ds 1045435f2b00SLionel Sambuc.It Fa int Fn compress "Bytef *dest" "uLongf *destLen" \ 1046435f2b00SLionel Sambuc"const Bytef *source" "uLong sourceLen" ; 1047435f2b00SLionel Sambuc.Pp 1048435f2b00SLionel SambucThe 1049435f2b00SLionel Sambuc.Fn compress 1050435f2b00SLionel Sambucfunction compresses the source buffer into the destination buffer. 1051435f2b00SLionel Sambuc.Fa sourceLen 1052435f2b00SLionel Sambucis the byte length of the source buffer. 1053435f2b00SLionel SambucUpon entry, 1054435f2b00SLionel Sambuc.Fa destLen 1055435f2b00SLionel Sambucis the total size of the destination buffer, 1056435f2b00SLionel Sambucwhich must be at least 0.1% larger than 1057435f2b00SLionel Sambuc.Fa sourceLen 1058435f2b00SLionel Sambucplus 12 bytes. 1059435f2b00SLionel SambucUpon exit, 1060435f2b00SLionel Sambuc.Fa destLen 1061435f2b00SLionel Sambucis the actual size of the compressed buffer. 1062435f2b00SLionel SambucThis function can be used to compress a whole file at once if the 1063435f2b00SLionel Sambucinput file is mmap'ed. 1064435f2b00SLionel Sambuc.Pp 1065435f2b00SLionel Sambuc.Fn compress 1066435f2b00SLionel Sambucreturns 1067435f2b00SLionel Sambuc.Dv Z_OK 1068435f2b00SLionel Sambucif successful, 1069435f2b00SLionel Sambuc.Dv Z_MEM_ERROR 1070435f2b00SLionel Sambucif there was not enough memory, or 1071435f2b00SLionel Sambuc.Dv Z_BUF_ERROR 1072435f2b00SLionel Sambucif there was not enough room in the output buffer. 1073435f2b00SLionel Sambuc.It Fa int Fn compress2 "Bytef *dest" "uLongf *destLen" \ 1074435f2b00SLionel Sambuc"const Bytef *source" "uLong sourceLen" "int level" ; 1075435f2b00SLionel Sambuc.Pp 1076435f2b00SLionel SambucThe 1077435f2b00SLionel Sambuc.Fn compress2 1078435f2b00SLionel Sambucfunction compresses the source buffer into the destination buffer. 1079435f2b00SLionel SambucThe 1080435f2b00SLionel Sambuc.Fa level 1081435f2b00SLionel Sambucparameter has the same meaning as in 1082435f2b00SLionel Sambuc.Fn deflateInit . 1083435f2b00SLionel Sambuc.Fa sourceLen 1084435f2b00SLionel Sambucis the byte length of the source buffer. 1085435f2b00SLionel SambucUpon entry, 1086435f2b00SLionel Sambuc.Fa destLen 1087435f2b00SLionel Sambucis the total size of the destination buffer, 1088435f2b00SLionel Sambucwhich must be at least 0.1% larger than 1089435f2b00SLionel Sambuc.Fa sourceLen 1090435f2b00SLionel Sambucplus 12 bytes. 1091435f2b00SLionel SambucUpon exit, 1092435f2b00SLionel Sambuc.Fa destLen 1093435f2b00SLionel Sambucis the actual size of the compressed buffer. 1094435f2b00SLionel Sambuc.Pp 1095435f2b00SLionel Sambuc.Fn compress2 1096435f2b00SLionel Sambucreturns 1097435f2b00SLionel Sambuc.Dv Z_OK 1098435f2b00SLionel Sambucif successful, 1099435f2b00SLionel Sambuc.Dv Z_MEM_ERROR 1100435f2b00SLionel Sambucif there was not enough memory, 1101435f2b00SLionel Sambuc.Dv Z_BUF_ERROR 1102435f2b00SLionel Sambucif there was not enough room in the output buffer, or 1103435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 1104435f2b00SLionel Sambucif the level parameter is invalid. 1105435f2b00SLionel Sambuc.It Fa int Fn uncompress "Bytef *dest" "uLongf *destLen" \ 1106435f2b00SLionel Sambuc"const Bytef *source" "uLong sourceLen" ; 1107435f2b00SLionel Sambuc.Pp 1108435f2b00SLionel SambucThe 1109435f2b00SLionel Sambuc.Fn uncompress 1110435f2b00SLionel Sambucfunction decompresses the source buffer into the destination buffer. 1111435f2b00SLionel Sambuc.Fa sourceLen 1112435f2b00SLionel Sambucis the byte length of the source buffer. 1113435f2b00SLionel SambucUpon entry, 1114435f2b00SLionel Sambuc.Fa destLen 1115435f2b00SLionel Sambucis the total size of the destination buffer, 1116435f2b00SLionel Sambucwhich must be large enough to hold the entire uncompressed data. 1117435f2b00SLionel Sambuc(The size of the uncompressed data must have been saved previously 1118435f2b00SLionel Sambucby the compressor and transmitted to the decompressor 1119435f2b00SLionel Sambucby some mechanism outside the scope of this compression library.) 1120435f2b00SLionel SambucUpon exit, 1121435f2b00SLionel Sambuc.Fa destLen 1122435f2b00SLionel Sambucis the actual size of the compressed buffer. 1123435f2b00SLionel SambucThis function can be used to decompress a whole file at once if the 1124435f2b00SLionel Sambucinput file is mmap'ed. 1125435f2b00SLionel Sambuc.Pp 1126435f2b00SLionel Sambuc.Fn uncompress 1127435f2b00SLionel Sambucreturns 1128435f2b00SLionel Sambuc.Dv Z_OK 1129435f2b00SLionel Sambucif successful, 1130435f2b00SLionel Sambuc.Dv Z_MEM_ERROR 1131435f2b00SLionel Sambucif there was not enough memory, 1132435f2b00SLionel Sambuc.Dv Z_BUF_ERROR 1133435f2b00SLionel Sambucif there was not enough room in the output buffer, or 1134435f2b00SLionel Sambuc.Dv Z_DATA_ERROR 1135435f2b00SLionel Sambucif the input data was corrupted. 1136435f2b00SLionel Sambuc.It Fa gzFile Fn gzopen "const char *path" "const char *mode" ; 1137435f2b00SLionel Sambuc.Pp 1138435f2b00SLionel SambucThe 1139435f2b00SLionel Sambuc.Fn gzopen 1140435f2b00SLionel Sambucfunction opens a gzip 1141435f2b00SLionel Sambuc.Pq .gz 1142435f2b00SLionel Sambucfile for reading or writing. 1143435f2b00SLionel SambucThe mode parameter is as in 1144435f2b00SLionel Sambuc.Xr fopen 3 1145435f2b00SLionel Sambuc.Po 1146435f2b00SLionel Sambuc.Qq rb 1147435f2b00SLionel Sambucor 1148435f2b00SLionel Sambuc.Qq wb 1149435f2b00SLionel Sambuc.Pc 1150435f2b00SLionel Sambucbut can also include a compression level 1151435f2b00SLionel Sambuc.Pq Qq wb9 1152435f2b00SLionel Sambucor a strategy: 1153435f2b00SLionel Sambuc.Sq f 1154435f2b00SLionel Sambucfor filtered data, as in 1155435f2b00SLionel Sambuc.Qq wb6f ; 1156435f2b00SLionel Sambuc.Sq h 1157435f2b00SLionel Sambucfor Huffman only compression, as in 1158435f2b00SLionel Sambuc.Qq wb1h . 1159435f2b00SLionel Sambuc(See the description of 1160435f2b00SLionel Sambuc.Fn deflateInit2 1161435f2b00SLionel Sambucfor more information about the strategy parameter.) 1162435f2b00SLionel Sambuc.Pp 1163435f2b00SLionel Sambuc.Fn gzopen 1164435f2b00SLionel Sambuccan be used to read a file which is not in gzip format; 1165435f2b00SLionel Sambucin this case 1166435f2b00SLionel Sambuc.Fn gzread 1167435f2b00SLionel Sambucwill directly read from the file without decompression. 1168435f2b00SLionel Sambuc.Pp 1169435f2b00SLionel Sambuc.Fn gzopen 1170435f2b00SLionel Sambucreturns 1171435f2b00SLionel Sambuc.Dv NULL 1172435f2b00SLionel Sambucif the file could not be opened or if there was 1173435f2b00SLionel Sambucinsufficient memory to allocate the (de)compression state; 1174435f2b00SLionel Sambucerrno can be checked to distinguish the two cases (if errno is zero, the 1175435f2b00SLionel Sambuc.Nm 1176435f2b00SLionel Sambucerror is 1177435f2b00SLionel Sambuc.Dv Z_MEM_ERROR ) . 1178435f2b00SLionel Sambuc.It Fa gzFile Fn gzdopen "int fd" "const char *mode" ; 1179435f2b00SLionel Sambuc.Pp 1180435f2b00SLionel SambucThe 1181435f2b00SLionel Sambuc.Fn gzdopen 1182435f2b00SLionel Sambucfunction associates a gzFile with the file descriptor 1183435f2b00SLionel Sambuc.Fa fd . 1184435f2b00SLionel SambucFile descriptors are obtained from calls like 1185435f2b00SLionel Sambuc.Xr open 2 , 1186435f2b00SLionel Sambuc.Xr dup 2 , 1187435f2b00SLionel Sambuc.Xr creat 3 , 1188435f2b00SLionel Sambuc.Xr pipe 2 , 1189435f2b00SLionel Sambucor 1190435f2b00SLionel Sambuc.Xr fileno 3 1191435f2b00SLionel Sambuc(if the file has been previously opened with 1192435f2b00SLionel Sambuc.Xr fopen 3 ) . 1193435f2b00SLionel SambucThe 1194435f2b00SLionel Sambuc.Fa mode 1195435f2b00SLionel Sambucparameter is as in 1196435f2b00SLionel Sambuc.Fn gzopen . 1197435f2b00SLionel Sambuc.Pp 1198435f2b00SLionel SambucThe next call to 1199435f2b00SLionel Sambuc.Fn gzclose 1200435f2b00SLionel Sambucon the returned gzFile will also close the file descriptor fd, 1201435f2b00SLionel Sambucjust like fclose(fdopen(fd), mode) closes the file descriptor fd. 1202435f2b00SLionel SambucIf you want to keep fd open, use gzdopen(dup(fd), mode). 1203435f2b00SLionel Sambuc.Pp 1204435f2b00SLionel Sambuc.Fn gzdopen 1205435f2b00SLionel Sambucreturns 1206435f2b00SLionel Sambuc.Dv NULL 1207435f2b00SLionel Sambucif there was insufficient memory to allocate the (de)compression state. 1208435f2b00SLionel Sambuc.It Fa int Fn gzsetparams "gzFile file" "int level" "int strategy" ; 1209435f2b00SLionel Sambuc.Pp 1210435f2b00SLionel SambucThe 1211435f2b00SLionel Sambuc.Fn gzsetparams 1212435f2b00SLionel Sambucfunction dynamically updates the compression level or strategy. 1213435f2b00SLionel SambucSee the description of 1214435f2b00SLionel Sambuc.Fn deflateInit2 1215435f2b00SLionel Sambucfor the meaning of these parameters. 1216435f2b00SLionel Sambuc.Pp 1217435f2b00SLionel Sambuc.Fn gzsetparams 1218435f2b00SLionel Sambucreturns 1219435f2b00SLionel Sambuc.Dv Z_OK 1220435f2b00SLionel Sambucif successful, or 1221435f2b00SLionel Sambuc.Dv Z_STREAM_ERROR 1222435f2b00SLionel Sambucif the file was not opened for writing. 1223435f2b00SLionel Sambuc.It Fa int Fn gzread "gzFile file" "voidp buf" "unsigned len" ; 1224435f2b00SLionel Sambuc.Pp 1225435f2b00SLionel SambucThe 1226435f2b00SLionel Sambuc.Fn gzread 1227435f2b00SLionel Sambucfunction reads the given number of uncompressed bytes from the compressed file. 1228435f2b00SLionel SambucIf the input file was not in gzip format, 1229435f2b00SLionel Sambuc.Fn gzread 1230435f2b00SLionel Sambuccopies the given number of bytes into the buffer. 1231435f2b00SLionel Sambuc.Pp 1232435f2b00SLionel Sambuc.Fn gzread 1233435f2b00SLionel Sambucreturns the number of uncompressed bytes actually read 1234435f2b00SLionel Sambuc(0 for end of file, \-1 for error). 1235435f2b00SLionel Sambuc.It Fa int Fn gzwrite "gzFile file" "const voidp buf" "unsigned len" ; 1236435f2b00SLionel Sambuc.Pp 1237435f2b00SLionel SambucThe 1238435f2b00SLionel Sambuc.Fn gzwrite 1239435f2b00SLionel Sambucfunction writes the given number of uncompressed bytes into the compressed file. 1240435f2b00SLionel Sambuc.Fn gzwrite 1241435f2b00SLionel Sambucreturns the number of uncompressed bytes actually written 1242435f2b00SLionel Sambuc.Pq 0 in case of error . 1243435f2b00SLionel Sambuc.It Fa int Fn gzprintf "gzFile file" "const char *format" "..." ; 1244435f2b00SLionel Sambuc.Pp 1245435f2b00SLionel SambucThe 1246435f2b00SLionel Sambuc.Fn gzprintf 1247435f2b00SLionel Sambucfunction converts, formats, and writes the args to the compressed file 1248435f2b00SLionel Sambucunder control of the format string, as in 1249435f2b00SLionel Sambuc.Xr fprintf 3 . 1250435f2b00SLionel Sambuc.Fn gzprintf 1251435f2b00SLionel Sambucreturns the number of uncompressed bytes actually written 1252435f2b00SLionel Sambuc.Pq 0 in case of error . 1253435f2b00SLionel Sambuc.It Fa int Fn gzputs "gzFile file" "const char *s" ; 1254435f2b00SLionel Sambuc.Pp 1255435f2b00SLionel SambucThe 1256435f2b00SLionel Sambuc.Fn gzputs 1257435f2b00SLionel Sambucfunction writes the given null-terminated string to the compressed file, 1258435f2b00SLionel Sambucexcluding the terminating null character. 1259435f2b00SLionel Sambuc.Pp 1260435f2b00SLionel Sambuc.Fn gzputs 1261435f2b00SLionel Sambucreturns the number of characters written, or \-1 in case of error. 1262435f2b00SLionel Sambuc.It Fa char * Fn gzgets "gzFile file" "char *buf" "int len" ; 1263435f2b00SLionel Sambuc.Pp 1264435f2b00SLionel SambucThe 1265435f2b00SLionel Sambuc.Fn gzgets 1266435f2b00SLionel Sambucfunction reads bytes from the compressed file until len\-1 characters are read, 1267435f2b00SLionel Sambucor a newline character is read and transferred to 1268435f2b00SLionel Sambuc.Fa buf , 1269435f2b00SLionel Sambucor an end-of-file condition is encountered. 1270435f2b00SLionel SambucThe string is then terminated with a null character. 1271435f2b00SLionel Sambuc.Pp 1272435f2b00SLionel Sambuc.Fn gzgets 1273435f2b00SLionel Sambucreturns 1274435f2b00SLionel Sambuc.Fa buf , 1275435f2b00SLionel Sambucor 1276435f2b00SLionel Sambuc.Dv Z_NULL 1277435f2b00SLionel Sambucin case of error. 1278435f2b00SLionel Sambuc.It Fa int Fn gzputc "gzFile file" "int c" ; 1279435f2b00SLionel Sambuc.Pp 1280435f2b00SLionel SambucThe 1281435f2b00SLionel Sambuc.Fn gzputc 1282435f2b00SLionel Sambucfunction writes 1283435f2b00SLionel Sambuc.Fa c , 1284435f2b00SLionel Sambucconverted to an unsigned char, into the compressed file. 1285435f2b00SLionel Sambuc.Fn gzputc 1286435f2b00SLionel Sambucreturns the value that was written, or \-1 in case of error. 1287435f2b00SLionel Sambuc.It Fa int Fn gzgetc "gzFile file" ; 1288435f2b00SLionel Sambuc.Pp 1289435f2b00SLionel SambucThe 1290435f2b00SLionel Sambuc.Fn gzgetc 1291435f2b00SLionel Sambucfunction reads one byte from the compressed file. 1292435f2b00SLionel Sambuc.Fn gzgetc 1293435f2b00SLionel Sambucreturns this byte or \-1 in case of end of file or error. 1294435f2b00SLionel Sambuc.It Fa int Fn gzflush "gzFile file" "int flush" ; 1295435f2b00SLionel Sambuc.Pp 1296435f2b00SLionel SambucThe 1297435f2b00SLionel Sambuc.Fn gzflush 1298435f2b00SLionel Sambucfunction flushes all pending output into the compressed file. 1299435f2b00SLionel SambucThe parameter 1300435f2b00SLionel Sambuc.Fa flush 1301435f2b00SLionel Sambucis as in the 1302435f2b00SLionel Sambuc.Fn deflate 1303435f2b00SLionel Sambucfunction. 1304435f2b00SLionel SambucThe return value is the 1305435f2b00SLionel Sambuc.Nm 1306435f2b00SLionel Sambucerror number (see function 1307435f2b00SLionel Sambuc.Fn gzerror 1308435f2b00SLionel Sambucbelow). 1309435f2b00SLionel Sambuc.Fn gzflush 1310435f2b00SLionel Sambucreturns 1311435f2b00SLionel Sambuc.Dv Z_OK 1312435f2b00SLionel Sambucif the flush parameter is 1313435f2b00SLionel Sambuc.Dv Z_FINISH 1314435f2b00SLionel Sambucand all output could be flushed. 1315435f2b00SLionel Sambuc.Pp 1316435f2b00SLionel Sambuc.Fn gzflush 1317435f2b00SLionel Sambucshould be called only when strictly necessary because it can 1318435f2b00SLionel Sambucdegrade compression. 1319435f2b00SLionel Sambuc.It Fa z_off_t Fn gzseek "gzFile file" "z_off_t offset" "int whence" ; 1320435f2b00SLionel Sambuc.Pp 1321435f2b00SLionel SambucSets the starting position for the next 1322435f2b00SLionel Sambuc.Fn gzread 1323435f2b00SLionel Sambucor 1324435f2b00SLionel Sambuc.Fn gzwrite 1325435f2b00SLionel Sambucon the given compressed file. 1326435f2b00SLionel SambucThe offset represents a number of bytes in the uncompressed data stream. 1327435f2b00SLionel SambucThe whence parameter is defined as in 1328435f2b00SLionel Sambuc.Xr lseek 2 ; 1329435f2b00SLionel Sambucthe value 1330435f2b00SLionel Sambuc.Dv SEEK_END 1331435f2b00SLionel Sambucis not supported. 1332435f2b00SLionel Sambuc.Pp 1333435f2b00SLionel SambucIf the file is opened for reading, this function is emulated but can be 1334435f2b00SLionel Sambucextremely slow. 1335435f2b00SLionel SambucIf the file is opened for writing, only forward seeks are supported; 1336435f2b00SLionel Sambuc.Fn gzseek 1337435f2b00SLionel Sambucthen compresses a sequence of zeroes up to the new starting position. 1338435f2b00SLionel Sambuc.Pp 1339435f2b00SLionel Sambuc.Fn gzseek 1340435f2b00SLionel Sambucreturns the resulting offset location as measured in bytes from 1341435f2b00SLionel Sambucthe beginning of the uncompressed stream, or \-1 in case of error, 1342435f2b00SLionel Sambucin particular if the file is opened for writing and the new starting position 1343435f2b00SLionel Sambucwould be before the current position. 1344435f2b00SLionel Sambuc.It Fa int Fn gzrewind "gzFile file" ; 1345435f2b00SLionel Sambuc.Pp 1346435f2b00SLionel SambucThe 1347435f2b00SLionel Sambuc.Fn gzrewind 1348435f2b00SLionel Sambucfunction rewinds the given 1349435f2b00SLionel Sambuc.Fa file . 1350435f2b00SLionel SambucThis function is supported only for reading. 1351435f2b00SLionel Sambuc.Pp 1352435f2b00SLionel Sambucgzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET). 1353435f2b00SLionel Sambuc.It Fa z_off_t Fn gztell "gzFile file" ; 1354435f2b00SLionel Sambuc.Pp 1355435f2b00SLionel SambucThe 1356435f2b00SLionel Sambuc.Fn gztell 1357435f2b00SLionel Sambucfunction returns the starting position for the next 1358435f2b00SLionel Sambuc.Fn gzread 1359435f2b00SLionel Sambucor 1360435f2b00SLionel Sambuc.Fn gzwrite 1361435f2b00SLionel Sambucon the given compressed file. 1362435f2b00SLionel SambucThis position represents a number of bytes in the uncompressed data stream. 1363435f2b00SLionel Sambuc.Pp 1364435f2b00SLionel Sambucgztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR). 1365435f2b00SLionel Sambuc.It Fa int Fn gzeof "gzFile file" ; 1366435f2b00SLionel Sambuc.Pp 1367435f2b00SLionel SambucThe 1368435f2b00SLionel Sambuc.Fn gzeof 1369435f2b00SLionel Sambucfunction returns 1 when 1370435f2b00SLionel Sambuc.Dv EOF 1371435f2b00SLionel Sambuchas previously been detected reading the given input stream, otherwise zero. 1372435f2b00SLionel Sambuc.It Fa int Fn gzclose "gzFile file" ; 1373435f2b00SLionel Sambuc.Pp 1374435f2b00SLionel SambucThe 1375435f2b00SLionel Sambuc.Fn gzclose 1376435f2b00SLionel Sambucfunction flushes all pending output if necessary, closes the compressed file 1377435f2b00SLionel Sambucand deallocates all the (de)compression state. 1378435f2b00SLionel SambucThe return value is the 1379435f2b00SLionel Sambuc.Nm 1380435f2b00SLionel Sambucerror number (see function 1381435f2b00SLionel Sambuc.Fn gzerror 1382435f2b00SLionel Sambucbelow). 1383435f2b00SLionel Sambuc.It Fa const char * Fn gzerror "gzFile file" "int *errnum" ; 1384435f2b00SLionel Sambuc.Pp 1385435f2b00SLionel SambucThe 1386435f2b00SLionel Sambuc.Fn gzerror 1387435f2b00SLionel Sambucfunction returns the error message for the last error which occurred on the 1388435f2b00SLionel Sambucgiven compressed 1389435f2b00SLionel Sambuc.Fa file . 1390435f2b00SLionel Sambuc.Fa errnum 1391435f2b00SLionel Sambucis set to the 1392435f2b00SLionel Sambuc.Nm 1393435f2b00SLionel Sambucerror number. 1394435f2b00SLionel SambucIf an error occurred in the file system and not in the compression library, 1395435f2b00SLionel Sambuc.Fa errnum 1396435f2b00SLionel Sambucis set to 1397435f2b00SLionel Sambuc.Dv Z_ERRNO 1398435f2b00SLionel Sambucand the application may consult errno to get the exact error code. 1399435f2b00SLionel Sambuc.El 1400435f2b00SLionel Sambuc.Sh CHECKSUM FUNCTIONS 1401435f2b00SLionel SambucThese functions are not related to compression but are exported 1402435f2b00SLionel Sambucanyway because they might be useful in applications using the 1403435f2b00SLionel Sambuccompression library. 1404435f2b00SLionel Sambuc.Bl -tag -width Ds 1405435f2b00SLionel Sambuc.It Fa uLong Fn adler32 "uLong adler" "const Bytef *buf" "uInt len" ; 1406435f2b00SLionel SambucThe 1407435f2b00SLionel Sambuc.Fn adler32 1408435f2b00SLionel Sambucfunction updates a running Adler-32 checksum with the bytes buf[0..len-1] 1409435f2b00SLionel Sambucand returns the updated checksum. 1410435f2b00SLionel SambucIf 1411435f2b00SLionel Sambuc.Fa buf 1412435f2b00SLionel Sambucis 1413435f2b00SLionel Sambuc.Dv NULL , 1414435f2b00SLionel Sambucthis function returns the required initial value for the checksum. 1415435f2b00SLionel Sambuc.Pp 1416435f2b00SLionel SambucAn Adler-32 checksum is almost as reliable as a CRC32 but can be computed 1417435f2b00SLionel Sambucmuch faster. 1418435f2b00SLionel SambucUsage example: 1419435f2b00SLionel Sambuc.Bd -literal -offset indent 1420435f2b00SLionel SambucuLong adler = adler32(0L, Z_NULL, 0); 1421435f2b00SLionel Sambuc 1422435f2b00SLionel Sambucwhile (read_buffer(buffer, length) != EOF) { 1423435f2b00SLionel Sambucadler = adler32(adler, buffer, length); 1424435f2b00SLionel Sambuc} 1425435f2b00SLionel Sambucif (adler != original_adler) error(); 1426435f2b00SLionel Sambuc.Ed 1427435f2b00SLionel Sambuc.It Fa uLong Fn crc32 "uLong crc" "const Bytef *buf" "uInt len" ; 1428435f2b00SLionel SambucThe 1429435f2b00SLionel Sambuc.Fn crc32 1430435f2b00SLionel Sambucfunction updates a running CRC with the bytes buf[0..len-1] 1431435f2b00SLionel Sambucand returns the updated CRC. 1432435f2b00SLionel SambucIf 1433435f2b00SLionel Sambuc.Fa buf 1434435f2b00SLionel Sambucis 1435435f2b00SLionel Sambuc.Dv NULL , 1436435f2b00SLionel Sambucthis function returns the required initial value for the CRC. 1437435f2b00SLionel SambucPre- and post-conditioning 1438435f2b00SLionel Sambuc.Pq one's complement 1439435f2b00SLionel Sambucis performed within this function so it shouldn't be done by the application. 1440435f2b00SLionel SambucUsage example: 1441435f2b00SLionel Sambuc.Bd -literal -offset indent 1442435f2b00SLionel SambucuLong crc = crc32(0L, Z_NULL, 0); 1443435f2b00SLionel Sambuc 1444435f2b00SLionel Sambucwhile (read_buffer(buffer, length) != EOF) { 1445435f2b00SLionel Sambuccrc = crc32(crc, buffer, length); 1446435f2b00SLionel Sambuc} 1447435f2b00SLionel Sambucif (crc != original_crc) error(); 1448435f2b00SLionel Sambuc.Ed 1449435f2b00SLionel Sambuc.El 1450435f2b00SLionel Sambuc.Sh STRUCTURES 1451435f2b00SLionel Sambuc.Bd -literal 1452435f2b00SLionel Sambucstruct internal_state; 1453435f2b00SLionel Sambuc 1454435f2b00SLionel Sambuctypedef struct z_stream_s { 1455435f2b00SLionel Sambuc Bytef *next_in; /* next input byte */ 1456435f2b00SLionel Sambuc uInt avail_in; /* number of bytes available at next_in */ 1457435f2b00SLionel Sambuc uLong total_in; /* total nb of input bytes read so far */ 1458435f2b00SLionel Sambuc 1459435f2b00SLionel Sambuc Bytef *next_out; /* next output byte should be put there */ 1460435f2b00SLionel Sambuc uInt avail_out; /* remaining free space at next_out */ 1461435f2b00SLionel Sambuc uLong total_out; /* total nb of bytes output so far */ 1462435f2b00SLionel Sambuc 1463435f2b00SLionel Sambuc char *msg; /* last error message, NULL if no error */ 1464435f2b00SLionel Sambuc struct internal_state FAR *state; /* not visible by applications */ 1465435f2b00SLionel Sambuc 1466435f2b00SLionel Sambuc alloc_func zalloc; /* used to allocate the internal state */ 1467435f2b00SLionel Sambuc free_func zfree; /* used to free the internal state */ 1468435f2b00SLionel Sambuc voidpf opaque; /* private data object passed to zalloc and zfree*/ 1469435f2b00SLionel Sambuc 1470435f2b00SLionel Sambuc int data_type; /*best guess about the data type: ascii or binary*/ 1471435f2b00SLionel Sambuc uLong adler; /* Adler-32 value of the uncompressed data */ 1472435f2b00SLionel Sambuc uLong reserved; /* reserved for future use */ 1473435f2b00SLionel Sambuc} z_stream; 1474435f2b00SLionel Sambuc 1475435f2b00SLionel Sambuctypedef z_stream FAR * z_streamp; 1476435f2b00SLionel Sambuc.Ed 1477435f2b00SLionel Sambuc.Pp 1478435f2b00SLionel SambucThe application must update 1479435f2b00SLionel Sambuc.Fa next_in 1480435f2b00SLionel Sambucand 1481435f2b00SLionel Sambuc.Fa avail_in 1482435f2b00SLionel Sambucwhen 1483435f2b00SLionel Sambuc.Fa avail_in 1484435f2b00SLionel Sambuchas dropped to zero. 1485435f2b00SLionel SambucIt must update 1486435f2b00SLionel Sambuc.Fa next_out 1487435f2b00SLionel Sambucand 1488435f2b00SLionel Sambuc.Fa avail_out 1489435f2b00SLionel Sambucwhen 1490435f2b00SLionel Sambuc.Fa avail_out 1491435f2b00SLionel Sambuchas dropped to zero. 1492435f2b00SLionel SambucThe application must initialize 1493435f2b00SLionel Sambuc.Fa zalloc , 1494435f2b00SLionel Sambuc.Fa zfree , 1495435f2b00SLionel Sambucand 1496435f2b00SLionel Sambuc.Fa opaque 1497435f2b00SLionel Sambucbefore calling the init function. 1498435f2b00SLionel SambucAll other fields are set by the compression library 1499435f2b00SLionel Sambucand must not be updated by the application. 1500435f2b00SLionel Sambuc.Pp 1501435f2b00SLionel SambucThe 1502435f2b00SLionel Sambuc.Fa opaque 1503435f2b00SLionel Sambucvalue provided by the application will be passed as the first 1504435f2b00SLionel Sambucparameter for calls to 1505435f2b00SLionel Sambuc.Fn zalloc 1506435f2b00SLionel Sambucand 1507435f2b00SLionel Sambuc.Fn zfree . 1508435f2b00SLionel SambucThis can be useful for custom memory management. 1509435f2b00SLionel SambucThe compression library attaches no meaning to the 1510435f2b00SLionel Sambuc.Fa opaque 1511435f2b00SLionel Sambucvalue. 1512435f2b00SLionel Sambuc.Pp 1513435f2b00SLionel Sambuc.Fa zalloc 1514435f2b00SLionel Sambucmust return 1515435f2b00SLionel Sambuc.Dv Z_NULL 1516435f2b00SLionel Sambucif there is not enough memory for the object. 1517435f2b00SLionel SambucIf 1518435f2b00SLionel Sambuc.Nm 1519435f2b00SLionel Sambucis used in a multi-threaded application, 1520435f2b00SLionel Sambuc.Fa zalloc 1521435f2b00SLionel Sambucand 1522435f2b00SLionel Sambuc.Fa zfree 1523435f2b00SLionel Sambucmust be thread safe. 1524435f2b00SLionel Sambuc.Pp 1525435f2b00SLionel SambucOn 16-bit systems, the functions 1526435f2b00SLionel Sambuc.Fa zalloc 1527435f2b00SLionel Sambucand 1528435f2b00SLionel Sambuc.Fa zfree 1529435f2b00SLionel Sambucmust be able to allocate exactly 65536 bytes, 1530435f2b00SLionel Sambucbut will not be required to allocate more than this if the symbol MAXSEG_64K 1531435f2b00SLionel Sambucis defined (see 1532435f2b00SLionel Sambuc.In zconf.h ) . 1533435f2b00SLionel Sambuc.Pp 1534435f2b00SLionel SambucWARNING: On MSDOS, pointers returned by 1535435f2b00SLionel Sambuc.Fa zalloc 1536435f2b00SLionel Sambucfor objects of exactly 65536 bytes *must* have their offset normalized to zero. 1537435f2b00SLionel SambucThe default allocation function provided by this library ensures this (see 1538435f2b00SLionel Sambuc.Pa zutil.c ) . 1539435f2b00SLionel SambucTo reduce memory requirements and avoid any allocation of 64K objects, 1540435f2b00SLionel Sambucat the expense of compression ratio, 1541435f2b00SLionel Sambuccompile the library with -DMAX_WBITS=14 (see 1542435f2b00SLionel Sambuc.In zconf.h ) . 1543435f2b00SLionel Sambuc.Pp 1544435f2b00SLionel SambucThe fields 1545435f2b00SLionel Sambuc.Fa total_in 1546435f2b00SLionel Sambucand 1547435f2b00SLionel Sambuc.Fa total_out 1548435f2b00SLionel Sambuccan be used for statistics or progress reports. 1549435f2b00SLionel SambucAfter compression, 1550435f2b00SLionel Sambuc.Fa total_in 1551435f2b00SLionel Sambucholds the total size of the uncompressed data and may be saved for use 1552435f2b00SLionel Sambucin the decompressor 1553435f2b00SLionel Sambuc(particularly if the decompressor wants to decompress everything 1554435f2b00SLionel Sambucin a single step). 1555435f2b00SLionel Sambuc.Sh CONSTANTS 1556435f2b00SLionel Sambuc.Bd -literal 1557435f2b00SLionel Sambuc#define Z_NO_FLUSH 0 1558435f2b00SLionel Sambuc#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ 1559435f2b00SLionel Sambuc#define Z_SYNC_FLUSH 2 1560435f2b00SLionel Sambuc#define Z_FULL_FLUSH 3 1561435f2b00SLionel Sambuc#define Z_FINISH 4 1562435f2b00SLionel Sambuc/* Allowed flush values; see deflate() below for details */ 1563435f2b00SLionel Sambuc 1564435f2b00SLionel Sambuc#define Z_OK 0 1565435f2b00SLionel Sambuc#define Z_STREAM_END 1 1566435f2b00SLionel Sambuc#define Z_NEED_DICT 2 1567435f2b00SLionel Sambuc#define Z_ERRNO (-1) 1568435f2b00SLionel Sambuc#define Z_STREAM_ERROR (-2) 1569435f2b00SLionel Sambuc#define Z_DATA_ERROR (-3) 1570435f2b00SLionel Sambuc#define Z_MEM_ERROR (-4) 1571435f2b00SLionel Sambuc#define Z_BUF_ERROR (-5) 1572435f2b00SLionel Sambuc#define Z_VERSION_ERROR (-6) 1573435f2b00SLionel Sambuc/* Return codes for the compression/decompression functions. 1574435f2b00SLionel Sambuc * Negative values are errors, 1575435f2b00SLionel Sambuc * positive values are used for special but normal events. 1576435f2b00SLionel Sambuc */ 1577435f2b00SLionel Sambuc 1578435f2b00SLionel Sambuc#define Z_NO_COMPRESSION 0 1579435f2b00SLionel Sambuc#define Z_BEST_SPEED 1 1580435f2b00SLionel Sambuc#define Z_BEST_COMPRESSION 9 1581435f2b00SLionel Sambuc#define Z_DEFAULT_COMPRESSION (-1) 1582435f2b00SLionel Sambuc/* compression levels */ 1583435f2b00SLionel Sambuc 1584435f2b00SLionel Sambuc#define Z_FILTERED 1 1585435f2b00SLionel Sambuc#define Z_HUFFMAN_ONLY 2 1586435f2b00SLionel Sambuc#define Z_DEFAULT_STRATEGY 0 1587435f2b00SLionel Sambuc/* compression strategy; see deflateInit2() below for details */ 1588435f2b00SLionel Sambuc 1589435f2b00SLionel Sambuc#define Z_BINARY 0 1590435f2b00SLionel Sambuc#define Z_ASCII 1 1591435f2b00SLionel Sambuc#define Z_UNKNOWN 2 1592435f2b00SLionel Sambuc/* Possible values of the data_type field */ 1593435f2b00SLionel Sambuc 1594435f2b00SLionel Sambuc#define Z_DEFLATED 8 1595435f2b00SLionel Sambuc/* The deflate compression method 1596435f2b00SLionel Sambuc * (the only one supported in this version) 1597435f2b00SLionel Sambuc*/ 1598435f2b00SLionel Sambuc 1599435f2b00SLionel Sambuc#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 1600435f2b00SLionel Sambuc 1601435f2b00SLionel Sambuc#define zlib_version zlibVersion() 1602435f2b00SLionel Sambuc/* for compatibility with versions \*[Lt] 1.0.2 */ 1603435f2b00SLionel Sambuc.Ed 1604435f2b00SLionel Sambuc.Sh VARIOUS HACKS 1605435f2b00SLionel SambucdeflateInit and inflateInit are macros to allow checking the 1606435f2b00SLionel Sambuc.Nm 1607435f2b00SLionel Sambucversion and the compiler's view of 1608435f2b00SLionel Sambuc.Fa z_stream . 1609435f2b00SLionel Sambuc.Bl -tag -width Ds 1610435f2b00SLionel Sambuc.It Fa int Fn deflateInit_ "z_stream strm" "int level" \ 1611435f2b00SLionel Sambuc"const char *version" "int stream_size" ; 1612435f2b00SLionel Sambuc.It Fa int Fn inflateInit_ "z_stream strm" "const char *version" \ 1613435f2b00SLionel Sambuc"int stream_size" ; 1614435f2b00SLionel Sambuc.It Fa int Fn deflateInit2_ "z_stream strm" "int level" "int method" \ 1615435f2b00SLionel Sambuc"int windowBits" "int memLevel" "int strategy" "const char *version" \ 1616435f2b00SLionel Sambuc"int stream_size" ; 1617435f2b00SLionel Sambuc.It Fa int Fn inflateInit2_ "z_stream strm" "int windowBits" \ 1618435f2b00SLionel Sambuc"const char *version" "int stream_size" ; 1619435f2b00SLionel Sambuc.It Fa const char * Fn zError "int err" ; 1620435f2b00SLionel Sambuc.It Fa int Fn inflateSyncPoint "z_streamp z" ; 1621435f2b00SLionel Sambuc.It Fa const uLongf * Fn "get_crc_table" "void" ; 1622435f2b00SLionel Sambuc.El 1623435f2b00SLionel Sambuc.Sh SEE ALSO 1624435f2b00SLionel Sambuc.Bl -tag -width 12n -compact 1625435f2b00SLionel Sambuc.It RFC 1950 1626435f2b00SLionel SambucZLIB Compressed Data Format Specification. 1627435f2b00SLionel Sambuc.It RFC 1951 1628435f2b00SLionel SambucDEFLATE Compressed Data Format Specification. 1629435f2b00SLionel Sambuc.It RFC 1952 1630435f2b00SLionel SambucGZIP File Format Specification. 1631435f2b00SLionel Sambuc.El 1632435f2b00SLionel Sambuc.Pp 1633435f2b00SLionel Sambuc.Lk http://www.gzip.org/zlib/ "zlib" 1634435f2b00SLionel Sambuc.Sh HISTORY 1635435f2b00SLionel SambucThis manual page is based on an HTML version of 1636435f2b00SLionel Sambuc.In zlib.h 1637435f2b00SLionel Sambucconverted by 163884d9c625SLionel Sambuc.An piaip Aq Mt piaip@csie.ntu.edu.tw 1639435f2b00SLionel Sambucand was converted to mdoc format by the 1640435f2b00SLionel Sambuc.Ox 1641435f2b00SLionel Sambucproject. 1642435f2b00SLionel Sambuc.Sh AUTHORS 164384d9c625SLionel Sambuc.An Jean-loup Gailly Aq Mt jloup@gzip.org 164484d9c625SLionel Sambuc.An Mark Adler Aq Mt madler@alumni.caltech.edu 1645