diff options
Diffstat (limited to 'zlib.h')
-rw-r--r-- | zlib.h | 282 |
1 files changed, 237 insertions, 45 deletions
@@ -1,7 +1,7 @@ | |||
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.1.4, March 11th, 2002 | 2 | version 1.2.0, March 9th, 2003 |
3 | 3 | ||
4 | Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler | 4 | Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler |
5 | 5 | ||
6 | This software is provided 'as-is', without any express or implied | 6 | This software is provided 'as-is', without any express or implied |
7 | warranty. In no event will the authors be held liable for any damages | 7 | warranty. In no event will the authors be held liable for any damages |
@@ -24,7 +24,7 @@ | |||
24 | 24 | ||
25 | 25 | ||
26 | The data format used by the zlib library is described by RFCs (Request for | 26 | The data format used by the zlib library is described by RFCs (Request for |
27 | Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt | 27 | Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt |
28 | (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). | 28 | (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). |
29 | */ | 29 | */ |
30 | 30 | ||
@@ -37,7 +37,7 @@ | |||
37 | extern "C" { | 37 | extern "C" { |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #define ZLIB_VERSION "1.1.4" | 40 | #define ZLIB_VERSION "1.2.0" |
41 | 41 | ||
42 | /* | 42 | /* |
43 | The 'zlib' compression library provides in-memory compression and | 43 | The 'zlib' compression library provides in-memory compression and |
@@ -52,8 +52,23 @@ extern "C" { | |||
52 | application must provide more input and/or consume the output | 52 | application must provide more input and/or consume the output |
53 | (providing more output space) before each call. | 53 | (providing more output space) before each call. |
54 | 54 | ||
55 | The compressed data format used by the in-memory functions is the zlib | ||
56 | format, which is a zlib wrapper documented in RFC 1950, wrapped around a | ||
57 | deflate stream, which is itself documented in RFC 1951. | ||
58 | |||
55 | The library also supports reading and writing files in gzip (.gz) format | 59 | The library also supports reading and writing files in gzip (.gz) format |
56 | with an interface similar to that of stdio. | 60 | with an interface similar to that of stdio using the functions that start |
61 | with "gz". The gzip format is different from the zlib format. gzip is a | ||
62 | gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. | ||
63 | |||
64 | The zlib format was designed to be compact and fast for use in memory | ||
65 | and on communications channels. The gzip format was designed for single- | ||
66 | file compression on file systems, has a larger header than zlib to maintain | ||
67 | directory information, and uses a different, slower check method than zlib. | ||
68 | |||
69 | This library does not provide any functions to write gzip files in memory. | ||
70 | However such functions could be easily written using zlib's deflate function, | ||
71 | the documentation in the gzip RFC, and the examples in gzio.c. | ||
57 | 72 | ||
58 | The library does not install any signal handler. The decoder checks | 73 | The library does not install any signal handler. The decoder checks |
59 | the consistency of the compressed data, so the library should never | 74 | the consistency of the compressed data, so the library should never |
@@ -244,7 +259,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); | |||
244 | If deflate returns with avail_out == 0, this function must be called again | 259 | If deflate returns with avail_out == 0, this function must be called again |
245 | with the same value of the flush parameter and more output space (updated | 260 | with the same value of the flush parameter and more output space (updated |
246 | avail_out), until the flush is complete (deflate returns with non-zero | 261 | avail_out), until the flush is complete (deflate returns with non-zero |
247 | avail_out). | 262 | avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that |
263 | avail_out is greater than six to avoid repeated flush markers due to | ||
264 | avail_out == 0 on return. | ||
248 | 265 | ||
249 | If the parameter flush is set to Z_FINISH, pending input is processed, | 266 | If the parameter flush is set to Z_FINISH, pending input is processed, |
250 | pending output is flushed and deflate returns with Z_STREAM_END if there | 267 | pending output is flushed and deflate returns with Z_STREAM_END if there |
@@ -256,7 +273,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); | |||
256 | 273 | ||
257 | Z_FINISH can be used immediately after deflateInit if all the compression | 274 | Z_FINISH can be used immediately after deflateInit if all the compression |
258 | is to be done in a single step. In this case, avail_out must be at least | 275 | is to be done in a single step. In this case, avail_out must be at least |
259 | 0.1% larger than avail_in plus 12 bytes. If deflate does not return | 276 | the value returned by deflateBound (see below). If deflate does not return |
260 | Z_STREAM_END, then it must be called again as described above. | 277 | Z_STREAM_END, then it must be called again as described above. |
261 | 278 | ||
262 | deflate() sets strm->adler to the adler32 checksum of all input read | 279 | deflate() sets strm->adler to the adler32 checksum of all input read |
@@ -272,7 +289,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); | |||
272 | consumed and all output has been produced (only when flush is set to | 289 | consumed and all output has been produced (only when flush is set to |
273 | Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example | 290 | Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example |
274 | if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible | 291 | if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible |
275 | (for example avail_in or avail_out was zero). | 292 | (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not |
293 | fatal, and deflate() can be called again with more input and more output | ||
294 | space to continue compressing. | ||
276 | */ | 295 | */ |
277 | 296 | ||
278 | 297 | ||
@@ -340,11 +359,9 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); | |||
340 | must be called again after making room in the output buffer because there | 359 | must be called again after making room in the output buffer because there |
341 | might be more output pending. | 360 | might be more output pending. |
342 | 361 | ||
343 | If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much | 362 | The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, or |
344 | output as possible to the output buffer. The flushing behavior of inflate is | 363 | Z_FINISH. Z_SYNC_FLUSH requests that inflate() flush as much output as |
345 | not specified for values of the flush parameter other than Z_SYNC_FLUSH | 364 | possible to the output buffer. |
346 | and Z_FINISH, but the current implementation actually flushes as much output | ||
347 | as possible anyway. | ||
348 | 365 | ||
349 | inflate() should normally be called until it returns Z_STREAM_END or an | 366 | inflate() should normally be called until it returns Z_STREAM_END or an |
350 | error. However if all decompression is to be performed in a single step | 367 | error. However if all decompression is to be performed in a single step |
@@ -354,29 +371,43 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); | |||
354 | uncompressed data. (The size of the uncompressed data may have been saved | 371 | uncompressed data. (The size of the uncompressed data may have been saved |
355 | by the compressor for this purpose.) The next operation on this stream must | 372 | by the compressor for this purpose.) The next operation on this stream must |
356 | be inflateEnd to deallocate the decompression state. The use of Z_FINISH | 373 | be inflateEnd to deallocate the decompression state. The use of Z_FINISH |
357 | is never required, but can be used to inform inflate that a faster routine | 374 | is never required, but can be used to inform inflate that a faster approach |
358 | may be used for the single inflate() call. | 375 | may be used for the single inflate() call. |
359 | 376 | ||
360 | If a preset dictionary is needed at this point (see inflateSetDictionary | 377 | In this implementation, inflate() always flushes as much output as |
361 | below), inflate sets strm-adler to the adler32 checksum of the | 378 | possible to the output buffer, and always uses the faster approach on the |
362 | dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise | 379 | first call. So the only effect of the flush parameter in this implementation |
363 | it sets strm->adler to the adler32 checksum of all output produced | 380 | is on the return value of inflate(), as noted below. |
364 | so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or | 381 | |
365 | an error code as described below. At the end of the stream, inflate() | 382 | If a preset dictionary is needed after this call (see inflateSetDictionary |
366 | checks that its computed adler32 checksum is equal to that saved by the | 383 | below), inflate sets strm-adler to the adler32 checksum of the dictionary |
367 | compressor and returns Z_STREAM_END only if the checksum is correct. | 384 | chosen by the compressor and returns Z_NEED_DICT; otherwise it sets |
385 | strm->adler to the adler32 checksum of all output produced so far (that is, | ||
386 | total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described | ||
387 | below. At the end of the stream, inflate() checks that its computed adler32 | ||
388 | checksum is equal to that saved by the compressor and returns Z_STREAM_END | ||
389 | only if the checksum is correct. | ||
390 | |||
391 | inflate() will decompress and check either zlib-wrapped or gzip-wrapped | ||
392 | deflate data. The header type is detected automatically. Any information | ||
393 | contained in the gzip header is not retained, so applications that need that | ||
394 | information should instead use raw inflate, see inflateInit2() below, or | ||
395 | inflateBack() and perform their own processing of the gzip header and | ||
396 | trailer. | ||
368 | 397 | ||
369 | inflate() returns Z_OK if some progress has been made (more input processed | 398 | inflate() returns Z_OK if some progress has been made (more input processed |
370 | or more output produced), Z_STREAM_END if the end of the compressed data has | 399 | or more output produced), Z_STREAM_END if the end of the compressed data has |
371 | been reached and all uncompressed output has been produced, Z_NEED_DICT if a | 400 | been reached and all uncompressed output has been produced, Z_NEED_DICT if a |
372 | preset dictionary is needed at this point, Z_DATA_ERROR if the input data was | 401 | preset dictionary is needed at this point, Z_DATA_ERROR if the input data was |
373 | corrupted (input stream not conforming to the zlib format or incorrect | 402 | corrupted (input stream not conforming to the zlib format or incorrect check |
374 | adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent | 403 | value), Z_STREAM_ERROR if the stream structure was inconsistent (for example |
375 | (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not | 404 | if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, |
376 | enough memory, Z_BUF_ERROR if no progress is possible or if there was not | 405 | Z_BUF_ERROR if no progress is possible or if there was not enough room in the |
377 | enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR | 406 | output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and |
378 | case, the application may then call inflateSync to look for a good | 407 | inflate() can be called again with more input and more output space to |
379 | compression block. | 408 | continue decompressing. If Z_DATA_ERROR is returned, the application may then |
409 | call inflateSync() to look for a good compression block if a partial recovery | ||
410 | of the data is desired. | ||
380 | */ | 411 | */ |
381 | 412 | ||
382 | 413 | ||
@@ -418,6 +449,10 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, | |||
418 | compression at the expense of memory usage. The default value is 15 if | 449 | compression at the expense of memory usage. The default value is 15 if |
419 | deflateInit is used instead. | 450 | deflateInit is used instead. |
420 | 451 | ||
452 | windowBits can also be -8..-15 for raw deflate. In this case, -windowBits | ||
453 | determines the window size. deflate() will then generate raw deflate data | ||
454 | with no zlib header or trailer, and will not compute an adler32 check value. | ||
455 | |||
421 | The memLevel parameter specifies how much memory should be allocated | 456 | The memLevel parameter specifies how much memory should be allocated |
422 | for the internal compression state. memLevel=1 uses minimum memory but | 457 | for the internal compression state. memLevel=1 uses minimum memory but |
423 | is slow and reduces compression ratio; memLevel=9 uses maximum memory | 458 | is slow and reduces compression ratio; memLevel=9 uses maximum memory |
@@ -464,11 +499,12 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, | |||
464 | deflate or deflate2. Thus the strings most likely to be useful should be | 499 | deflate or deflate2. Thus the strings most likely to be useful should be |
465 | put at the end of the dictionary, not at the front. | 500 | put at the end of the dictionary, not at the front. |
466 | 501 | ||
467 | Upon return of this function, strm->adler is set to the Adler32 value | 502 | Upon return of this function, strm->adler is set to the adler32 value |
468 | of the dictionary; the decompressor may later use this value to determine | 503 | of the dictionary; the decompressor may later use this value to determine |
469 | which dictionary has been used by the compressor. (The Adler32 value | 504 | which dictionary has been used by the compressor. (The adler32 value |
470 | applies to the whole dictionary even if only a subset of the dictionary is | 505 | applies to the whole dictionary even if only a subset of the dictionary is |
471 | actually used by the compressor.) | 506 | actually used by the compressor.) If a raw deflate was requested, then the |
507 | adler32 value is not computed and strm->adler is not set. | ||
472 | 508 | ||
473 | deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a | 509 | deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a |
474 | parameter is invalid (such as NULL dictionary) or the stream state is | 510 | parameter is invalid (such as NULL dictionary) or the stream state is |
@@ -507,8 +543,8 @@ ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); | |||
507 | */ | 543 | */ |
508 | 544 | ||
509 | ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, | 545 | ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, |
510 | int level, | 546 | int level, |
511 | int strategy)); | 547 | int strategy)); |
512 | /* | 548 | /* |
513 | Dynamically update the compression level and compression strategy. The | 549 | Dynamically update the compression level and compression strategy. The |
514 | interpretation of level and strategy is as in deflateInit2. This can be | 550 | interpretation of level and strategy is as in deflateInit2. This can be |
@@ -527,6 +563,15 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, | |||
527 | if strm->avail_out was zero. | 563 | if strm->avail_out was zero. |
528 | */ | 564 | */ |
529 | 565 | ||
566 | ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, | ||
567 | uLong sourceLen)); | ||
568 | /* | ||
569 | deflateBound() returns an upper bound on the compressed size after | ||
570 | deflation of sourceLen bytes. It must be called after deflateInit() | ||
571 | or deflateInit2(). This would be used to allocate an output buffer | ||
572 | for deflation in a single pass, and so would be called before deflate(). | ||
573 | */ | ||
574 | |||
530 | /* | 575 | /* |
531 | ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, | 576 | ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, |
532 | int windowBits)); | 577 | int windowBits)); |
@@ -542,7 +587,18 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, | |||
542 | input, inflate() will return with the error code Z_DATA_ERROR instead of | 587 | input, inflate() will return with the error code Z_DATA_ERROR instead of |
543 | trying to allocate a larger window. | 588 | trying to allocate a larger window. |
544 | 589 | ||
545 | inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough | 590 | windowBits can also be -8..-15 for raw inflate. In this case, -windowBits |
591 | determines the window size. inflate() will then process raw deflate data, | ||
592 | not looking for a zlib or gzip header, not generating a check value, and not | ||
593 | looking for any check values for comparison at the end of the stream. This | ||
594 | is for use with other formats that use the deflate compressed data format | ||
595 | such as zip. Those formats provide their own check values. If a custom | ||
596 | format is developed using the raw deflate format for compressed data, it is | ||
597 | recommended that a check value such as an adler32 or a crc32 be applied to | ||
598 | the uncompressed data as is done in the zlib, gzip, and zip formats. For | ||
599 | most applications, the zlib format should be used as is. | ||
600 | |||
601 | inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough | ||
546 | memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative | 602 | memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative |
547 | memLevel). msg is set to null if there is no error message. inflateInit2 | 603 | memLevel). msg is set to null if there is no error message. inflateInit2 |
548 | does not perform any decompression apart from reading the zlib header if | 604 | does not perform any decompression apart from reading the zlib header if |
@@ -557,14 +613,14 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, | |||
557 | Initializes the decompression dictionary from the given uncompressed byte | 613 | Initializes the decompression dictionary from the given uncompressed byte |
558 | sequence. This function must be called immediately after a call of inflate | 614 | sequence. This function must be called immediately after a call of inflate |
559 | if this call returned Z_NEED_DICT. The dictionary chosen by the compressor | 615 | if this call returned Z_NEED_DICT. The dictionary chosen by the compressor |
560 | can be determined from the Adler32 value returned by this call of | 616 | can be determined from the adler32 value returned by this call of |
561 | inflate. The compressor and decompressor must use exactly the same | 617 | inflate. The compressor and decompressor must use exactly the same |
562 | dictionary (see deflateSetDictionary). | 618 | dictionary (see deflateSetDictionary). |
563 | 619 | ||
564 | inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a | 620 | inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a |
565 | parameter is invalid (such as NULL dictionary) or the stream state is | 621 | parameter is invalid (such as NULL dictionary) or the stream state is |
566 | inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the | 622 | inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the |
567 | expected one (incorrect Adler32 value). inflateSetDictionary does not | 623 | expected one (incorrect adler32 value). inflateSetDictionary does not |
568 | perform any decompression: this will be done by subsequent calls of | 624 | perform any decompression: this will be done by subsequent calls of |
569 | inflate(). | 625 | inflate(). |
570 | */ | 626 | */ |
@@ -584,6 +640,22 @@ ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); | |||
584 | until success or end of the input data. | 640 | until success or end of the input data. |
585 | */ | 641 | */ |
586 | 642 | ||
643 | ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, | ||
644 | z_streamp source)); | ||
645 | /* | ||
646 | Sets the destination stream as a complete copy of the source stream. | ||
647 | |||
648 | This function can be useful when randomly accessing a large stream. The | ||
649 | first pass through the stream can periodically record the inflate state, | ||
650 | allowing restarting inflate at those points when randomly accessing the | ||
651 | stream. | ||
652 | |||
653 | inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not | ||
654 | enough memory, Z_STREAM_ERROR if the source stream state was inconsistent | ||
655 | (such as zalloc being NULL). msg is left unchanged in both source and | ||
656 | destination. | ||
657 | */ | ||
658 | |||
587 | ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); | 659 | ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); |
588 | /* | 660 | /* |
589 | This function is equivalent to inflateEnd followed by inflateInit, | 661 | This function is equivalent to inflateEnd followed by inflateInit, |
@@ -594,6 +666,108 @@ ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); | |||
594 | stream state was inconsistent (such as zalloc or state being NULL). | 666 | stream state was inconsistent (such as zalloc or state being NULL). |
595 | */ | 667 | */ |
596 | 668 | ||
669 | /* | ||
670 | ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits, | ||
671 | unsigned char FAR *window)); | ||
672 | |||
673 | Initialize the internal stream state for decompression using inflateBack() | ||
674 | calls. The fields zalloc, zfree and opaque in strm must be initialized | ||
675 | before the call. If zalloc and zfree are Z_NULL, then the default library- | ||
676 | derived memory allocation routines are used. windowBits is the base two | ||
677 | logarithm of the window size, in the range 8..15. window is a caller | ||
678 | supplied buffer of that size. Except for special applications where it is | ||
679 | assured that deflate was used with small window sizes, windowBits must be 15 | ||
680 | and a 32K byte window must be supplied to be able to decompress general | ||
681 | deflate streams. | ||
682 | |||
683 | See inflateBack() for the usage of these routines. | ||
684 | |||
685 | inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of | ||
686 | the paramaters are invalid, Z_MEM_ERROR if the internal state could not | ||
687 | be allocated, or Z_VERSION_ERROR if the version of the library does not | ||
688 | match the version of the header file. | ||
689 | */ | ||
690 | |||
691 | typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); | ||
692 | typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); | ||
693 | |||
694 | ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm, | ||
695 | in_func in, void FAR *in_desc, | ||
696 | out_func out, void FAR *out_desc)); | ||
697 | /* | ||
698 | inflateBack() does a raw inflate with a single call using a call-back | ||
699 | interface for input and output. This is more efficient than inflate() for | ||
700 | file i/o applications in that it avoids copying between the output and the | ||
701 | sliding window by simply making the window itself the output buffer. This | ||
702 | function trusts the application to not change the output buffer passed by | ||
703 | the output function, at least until inflateBack() returns. | ||
704 | |||
705 | inflateBackInit() must be called first to allocate the internal state | ||
706 | and to initialize the state with the user-provided window buffer. | ||
707 | inflateBack() may then be used multiple times to inflate a complete, raw | ||
708 | deflate stream with each call. inflateBackEnd() is then called to free | ||
709 | the allocated state. | ||
710 | |||
711 | A raw deflate stream is one with no zlib or gzip header or trailer. | ||
712 | This routine would normally be used in a utility that reads zip or gzip | ||
713 | files and writes out uncompressed files. The utility would decode the | ||
714 | header and process the trailer on its own, hence this routine expects | ||
715 | only the raw deflate stream to decompress. This is different from the | ||
716 | normal behavior of inflate(), which expects either a zlib or gzip header and | ||
717 | trailer around the deflate stream. | ||
718 | |||
719 | inflateBack() uses two subroutines supplied by the caller that are then | ||
720 | called by inflateBack() for input and output. inflateBack() calls those | ||
721 | routines until it reads a complete deflate stream and writes out all of the | ||
722 | uncompressed data, or until it encounters an error. The function's | ||
723 | parameters and return types are defined above in the in_func and out_func | ||
724 | typedefs. inflateBack() will call in(in_desc, &buf) which should return the | ||
725 | number of bytes of provided input, and a pointer to that input in buf. If | ||
726 | there is no input available, in() must return zero--buf is ignored in that | ||
727 | case--and inflateBack() will return a buffer error. inflateBack() will call | ||
728 | out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() | ||
729 | should return zero on success, or non-zero on failure. If out() returns | ||
730 | non-zero, inflateBack() will return with an error. Neither in() nor out() | ||
731 | are permitted to change the contents of the window provided to | ||
732 | inflateBackInit(), which is also the buffer that out() uses to write from. | ||
733 | The length written by out() will be at most the window size. Any non-zero | ||
734 | amount of input may be provided by in(). | ||
735 | |||
736 | For convenience, inflateBack() can be provided input on the first call by | ||
737 | setting strm->next_in and strm->avail_in. If that input is exhausted, then | ||
738 | in() will be called. Therefore strm->next_in must be initialized before | ||
739 | calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called | ||
740 | immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in | ||
741 | must also be initialized, and then if strm->avail_in is not zero, input will | ||
742 | initially be taken from strm->next_in[0 .. strm->avail_in - 1]. | ||
743 | |||
744 | The in_desc and out_desc parameters of inflateBack() is passed as the | ||
745 | first parameter of in() and out() respectively when they are called. These | ||
746 | descriptors can be optinally used to pass any information that the caller- | ||
747 | supplied in() and out() functions need to do their job. | ||
748 | |||
749 | On return, inflateBack() will set strm->next_in and strm->avail_in to | ||
750 | pass back any unused input that was provided by the last in() call. The | ||
751 | return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR | ||
752 | if in() or out() returned an error, Z_DATA_ERROR if there was a format | ||
753 | error in the deflate stream (in which case strm->msg is set to indicate the | ||
754 | nature of the error), or Z_STREAM_ERROR if the stream was not properly | ||
755 | initialized. In the case of Z_BUF_ERROR, an input or output error can be | ||
756 | distinguished using strm->next_in which will be Z_NULL only if in() returned | ||
757 | an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to | ||
758 | out() returning non-zero. (in() will always be called before out(), so | ||
759 | strm->next_in is assured to be defined if out() returns non-zero.) Note | ||
760 | that inflateBack() cannot return Z_OK. | ||
761 | */ | ||
762 | |||
763 | ZEXTERN int ZEXPORT inflateBackEnd(z_stream FAR *strm); | ||
764 | /* | ||
765 | All memory allocated by inflateBackInit() is freed. | ||
766 | |||
767 | inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream | ||
768 | state was inconsistent. | ||
769 | */ | ||
770 | |||
597 | 771 | ||
598 | /* utility functions */ | 772 | /* utility functions */ |
599 | 773 | ||
@@ -610,8 +784,8 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, | |||
610 | /* | 784 | /* |
611 | Compresses the source buffer into the destination buffer. sourceLen is | 785 | Compresses the source buffer into the destination buffer. sourceLen is |
612 | the byte length of the source buffer. Upon entry, destLen is the total | 786 | the byte length of the source buffer. Upon entry, destLen is the total |
613 | size of the destination buffer, which must be at least 0.1% larger than | 787 | size of the destination buffer, which must be at least the value returned |
614 | sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the | 788 | by compressBound(sourceLen). Upon exit, destLen is the actual size of the |
615 | compressed buffer. | 789 | compressed buffer. |
616 | This function can be used to compress a whole file at once if the | 790 | This function can be used to compress a whole file at once if the |
617 | input file is mmap'ed. | 791 | input file is mmap'ed. |
@@ -627,14 +801,22 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, | |||
627 | Compresses the source buffer into the destination buffer. The level | 801 | Compresses the source buffer into the destination buffer. The level |
628 | parameter has the same meaning as in deflateInit. sourceLen is the byte | 802 | parameter has the same meaning as in deflateInit. sourceLen is the byte |
629 | length of the source buffer. Upon entry, destLen is the total size of the | 803 | length of the source buffer. Upon entry, destLen is the total size of the |
630 | destination buffer, which must be at least 0.1% larger than sourceLen plus | 804 | destination buffer, which must be at least the value returned by |
631 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. | 805 | compressBound(sourceLen). Upon exit, destLen is the actual size of the |
806 | compressed buffer. | ||
632 | 807 | ||
633 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough | 808 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
634 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, | 809 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, |
635 | Z_STREAM_ERROR if the level parameter is invalid. | 810 | Z_STREAM_ERROR if the level parameter is invalid. |
636 | */ | 811 | */ |
637 | 812 | ||
813 | ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); | ||
814 | /* | ||
815 | compressBound() returns an upper bound on the compressed size after | ||
816 | compress() or compress2() on sourceLen bytes. It would be used before | ||
817 | a compress() or compress2() call to allocate the destination buffer. | ||
818 | */ | ||
819 | |||
638 | ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, | 820 | ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, |
639 | const Bytef *source, uLong sourceLen)); | 821 | const Bytef *source, uLong sourceLen)); |
640 | /* | 822 | /* |
@@ -650,7 +832,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, | |||
650 | 832 | ||
651 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not | 833 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not |
652 | enough memory, Z_BUF_ERROR if there was not enough room in the output | 834 | enough memory, Z_BUF_ERROR if there was not enough room in the output |
653 | buffer, or Z_DATA_ERROR if the input data was corrupted. | 835 | buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. |
654 | */ | 836 | */ |
655 | 837 | ||
656 | 838 | ||
@@ -702,7 +884,7 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); | |||
702 | end of file, -1 for error). */ | 884 | end of file, -1 for error). */ |
703 | 885 | ||
704 | ZEXTERN int ZEXPORT gzwrite OF((gzFile file, | 886 | ZEXTERN int ZEXPORT gzwrite OF((gzFile file, |
705 | const voidp buf, unsigned len)); | 887 | voidpc buf, unsigned len)); |
706 | /* | 888 | /* |
707 | Writes the given number of uncompressed bytes into the compressed file. | 889 | Writes the given number of uncompressed bytes into the compressed file. |
708 | gzwrite returns the number of uncompressed bytes actually written | 890 | gzwrite returns the number of uncompressed bytes actually written |
@@ -713,7 +895,10 @@ ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); | |||
713 | /* | 895 | /* |
714 | Converts, formats, and writes the args to the compressed file under | 896 | Converts, formats, and writes the args to the compressed file under |
715 | control of the format string, as in fprintf. gzprintf returns the number of | 897 | control of the format string, as in fprintf. gzprintf returns the number of |
716 | uncompressed bytes actually written (0 in case of error). | 898 | uncompressed bytes actually written (0 in case of error). The number of |
899 | uncompressed bytes written is limited to 4095. The caller should assure | ||
900 | that this limit is not exceeded, since otherwise a buffer overflow may | ||
901 | result. | ||
717 | */ | 902 | */ |
718 | 903 | ||
719 | ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); | 904 | ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); |
@@ -755,7 +940,7 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); | |||
755 | */ | 940 | */ |
756 | 941 | ||
757 | ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, | 942 | ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, |
758 | z_off_t offset, int whence)); | 943 | z_off_t offset, int whence)); |
759 | /* | 944 | /* |
760 | Sets the starting position for the next gzread or gzwrite on the | 945 | Sets the starting position for the next gzread or gzwrite on the |
761 | given compressed file. The offset represents a number of bytes in the | 946 | given compressed file. The offset represents a number of bytes in the |
@@ -867,6 +1052,10 @@ ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, | |||
867 | int stream_size)); | 1052 | int stream_size)); |
868 | ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, | 1053 | ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, |
869 | const char *version, int stream_size)); | 1054 | const char *version, int stream_size)); |
1055 | ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits, | ||
1056 | unsigned char FAR *window, | ||
1057 | const char *version, | ||
1058 | int stream_size)); | ||
870 | #define deflateInit(strm, level) \ | 1059 | #define deflateInit(strm, level) \ |
871 | deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) | 1060 | deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) |
872 | #define inflateInit(strm) \ | 1061 | #define inflateInit(strm) \ |
@@ -876,6 +1065,9 @@ ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, | |||
876 | (strategy), ZLIB_VERSION, sizeof(z_stream)) | 1065 | (strategy), ZLIB_VERSION, sizeof(z_stream)) |
877 | #define inflateInit2(strm, windowBits) \ | 1066 | #define inflateInit2(strm, windowBits) \ |
878 | inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) | 1067 | inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) |
1068 | #define inflateBackInit(strm, windowBits, window) \ | ||
1069 | inflateBackInit_((strm), (windowBits), (window), \ | ||
1070 | ZLIB_VERSION, sizeof(z_stream)) | ||
879 | 1071 | ||
880 | 1072 | ||
881 | #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) | 1073 | #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) |