This commit was generated by cvs2svn to compensate for changes in r33904,
which included commits to RCS files with non-trunk default branches.
This commit is contained in:
commit
9521a6bb06
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=33905
@ -1,6 +1,171 @@
|
||||
|
||||
ChangeLog file for zlib
|
||||
|
||||
Changes in 1.1.1 (27 Feb 98)
|
||||
- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson)
|
||||
- remove block truncation heuristic which had very marginal effect for zlib
|
||||
(smaller lit_bufsize than in gzip 1.2.4) and degraded a little the
|
||||
compression ratio on some files. This also allows inlining _tr_tally for
|
||||
matches in deflate_slow.
|
||||
- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier)
|
||||
|
||||
Changes in 1.1.0 (24 Feb 98)
|
||||
- do not return STREAM_END prematurely in inflate (John Bowler)
|
||||
- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
|
||||
- compile with -DFASTEST to get compression code optimized for speed only
|
||||
- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
|
||||
- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
|
||||
on Sun but significant on HP)
|
||||
|
||||
- add a pointer to experimental unzip library in README (Gilles Vollant)
|
||||
- initialize variable gcc in configure (Chris Herborth)
|
||||
|
||||
Changes in 1.0.9 (17 Feb 1998)
|
||||
- added gzputs and gzgets functions
|
||||
- do not clear eof flag in gzseek (Mark Diekhans)
|
||||
- fix gzseek for files in transparent mode (Mark Diekhans)
|
||||
- do not assume that vsprintf returns the number of bytes written (Jens Krinke)
|
||||
- replace EXPORT with ZEXPORT to avoid conflict with other programs
|
||||
- added compress2 in zconf.h, zlib.def, zlib.dnt
|
||||
- new asm code from Gilles Vollant in contrib/asm386
|
||||
- simplify the inflate code (Mark):
|
||||
. Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new()
|
||||
. ZALLOC the length list in inflate_trees_fixed() instead of using stack
|
||||
. ZALLOC the value area for huft_build() instead of using stack
|
||||
. Simplify Z_FINISH check in inflate()
|
||||
|
||||
- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8
|
||||
- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi)
|
||||
- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with
|
||||
the declaration of FAR (Gilles VOllant)
|
||||
- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann)
|
||||
- read_buf buf parameter of type Bytef* instead of charf*
|
||||
- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout)
|
||||
- do not redeclare unlink in minigzip.c for WIN32 (John Bowler)
|
||||
- fix check for presence of directories in "make install" (Ian Willis)
|
||||
|
||||
Changes in 1.0.8 (27 Jan 1998)
|
||||
- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant)
|
||||
- fix gzgetc and gzputc for big endian systems (Markus Oberhumer)
|
||||
- added compress2() to allow setting the compression level
|
||||
- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong)
|
||||
- use constant arrays for the static trees in trees.c instead of computing
|
||||
them at run time (thanks to Ken Raeburn for this suggestion). To create
|
||||
trees.h, compile with GEN_TREES_H and run "make test".
|
||||
- check return code of example in "make test" and display result
|
||||
- pass minigzip command line options to file_compress
|
||||
- simplifying code of inflateSync to avoid gcc 2.8 bug
|
||||
|
||||
- support CC="gcc -Wall" in configure -s (QingLong)
|
||||
- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn)
|
||||
- fix test for shared library support to avoid compiler warnings
|
||||
- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant)
|
||||
- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit)
|
||||
- do not use fdopen for Metrowerks on Mac (Brad Pettit))
|
||||
- add checks for gzputc and gzputc in example.c
|
||||
- avoid warnings in gzio.c and deflate.c (Andreas Kleinert)
|
||||
- use const for the CRC table (Ken Raeburn)
|
||||
- fixed "make uninstall" for shared libraries
|
||||
- use Tracev instead of Trace in infblock.c
|
||||
- in example.c use correct compressed length for test_sync
|
||||
- suppress +vnocompatwarnings in configure for HPUX (not always supported)
|
||||
|
||||
Changes in 1.0.7 (20 Jan 1998)
|
||||
- fix gzseek which was broken in write mode
|
||||
- return error for gzseek to negative absolute position
|
||||
- fix configure for Linux (Chun-Chung Chen)
|
||||
- increase stack space for MSC (Tim Wegner)
|
||||
- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant)
|
||||
- define EXPORTVA for gzprintf (Gilles Vollant)
|
||||
- added man page zlib.3 (Rick Rodgers)
|
||||
- for contrib/untgz, fix makedir() and improve Makefile
|
||||
|
||||
- check gzseek in write mode in example.c
|
||||
- allocate extra buffer for seeks only if gzseek is actually called
|
||||
- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant)
|
||||
- add inflateSyncPoint in zconf.h
|
||||
- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def
|
||||
|
||||
Changes in 1.0.6 (19 Jan 1998)
|
||||
- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
|
||||
gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
|
||||
- Fix a deflate bug occuring only with compression level 0 (thanks to
|
||||
Andy Buckler for finding this one).
|
||||
- In minigzip, pass transparently also the first byte for .Z files.
|
||||
- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()
|
||||
- check Z_FINISH in inflate (thanks to Marc Schluper)
|
||||
- Implement deflateCopy (thanks to Adam Costello)
|
||||
- make static libraries by default in configure, add --shared option.
|
||||
- move MSDOS or Windows specific files to directory msdos
|
||||
- suppress the notion of partial flush to simplify the interface
|
||||
(but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4)
|
||||
- suppress history buffer provided by application to simplify the interface
|
||||
(this feature was not implemented anyway in 1.0.4)
|
||||
- next_in and avail_in must be initialized before calling inflateInit or
|
||||
inflateInit2
|
||||
- add EXPORT in all exported functions (for Windows DLL)
|
||||
- added Makefile.nt (thanks to Stephen Williams)
|
||||
- added the unsupported "contrib" directory:
|
||||
contrib/asm386/ by Gilles Vollant <info@winimage.com>
|
||||
386 asm code replacing longest_match().
|
||||
contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
|
||||
A C++ I/O streams interface to the zlib gz* functions
|
||||
contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
|
||||
Another C++ I/O streams interface
|
||||
contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
|
||||
A very simple tar.gz file extractor using zlib
|
||||
contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
|
||||
How to use compress(), uncompress() and the gz* functions from VB.
|
||||
- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression
|
||||
level) in minigzip (thanks to Tom Lane)
|
||||
|
||||
- use const for rommable constants in deflate
|
||||
- added test for gzseek and gztell in example.c
|
||||
- add undocumented function inflateSyncPoint() (hack for Paul Mackerras)
|
||||
- add undocumented function zError to convert error code to string
|
||||
(for Tim Smithers)
|
||||
- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code.
|
||||
- Use default memcpy for Symantec MSDOS compiler.
|
||||
- Add EXPORT keyword for check_func (needed for Windows DLL)
|
||||
- add current directory to LD_LIBRARY_PATH for "make test"
|
||||
- create also a link for libz.so.1
|
||||
- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura)
|
||||
- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX)
|
||||
- added -soname for Linux in configure (Chun-Chung Chen,
|
||||
- assign numbers to the exported functions in zlib.def (for Windows DLL)
|
||||
- add advice in zlib.h for best usage of deflateSetDictionary
|
||||
- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn)
|
||||
- allow compilation with ANSI keywords only enabled for TurboC in large model
|
||||
- avoid "versionString"[0] (Borland bug)
|
||||
- add NEED_DUMMY_RETURN for Borland
|
||||
- use variable z_verbose for tracing in debug mode (Peter Deutsch).
|
||||
- allow compilation with CC
|
||||
- defined STDC for OS/2 (David Charlap)
|
||||
- limit external names to 8 chars for MVS (Thomas Lund)
|
||||
- in minigzip.c, use static buffers only for 16-bit systems
|
||||
- fix suffix check for "minigzip -d foo.gz"
|
||||
- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee)
|
||||
- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau)
|
||||
- added makelcc.bat for lcc-win32 (Tom St Denis)
|
||||
- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe)
|
||||
- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion.
|
||||
- check for unistd.h in configure (for off_t)
|
||||
- remove useless check parameter in inflate_blocks_free
|
||||
- avoid useless assignment of s->check to itself in inflate_blocks_new
|
||||
- do not flush twice in gzclose (thanks to Ken Raeburn)
|
||||
- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h
|
||||
- use NO_ERRNO_H instead of enumeration of operating systems with errno.h
|
||||
- work around buggy fclose on pipes for HP/UX
|
||||
- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson)
|
||||
- fix configure if CC is already equal to gcc
|
||||
|
||||
Changes in 1.0.5 (3 Jan 98)
|
||||
- Fix inflate to terminate gracefully when fed corrupted or invalid data
|
||||
- Use const for rommable constants in inflate
|
||||
- Eliminate memory leaks on error conditions in inflate
|
||||
- Removed some vestigial code in inflate
|
||||
- Update web address in README
|
||||
|
||||
Changes in 1.0.4 (24 Jul 96)
|
||||
- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF
|
||||
bit, so the decompressor could decompress all the correct data but went
|
||||
|
@ -1,15 +1,16 @@
|
||||
zlib 1.0.4 is a general purpose data compression library. All the code
|
||||
is reentrant (thread safe). The data format used by the zlib library
|
||||
zlib 1.1.1 is a general purpose data compression library. All the code
|
||||
is thread safe. The data format used by the zlib library
|
||||
is described by RFCs (Request for Comments) 1950 to 1952 in the files
|
||||
ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate
|
||||
format) and rfc1952.txt (gzip format). These documents are also available in
|
||||
other formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
|
||||
|
||||
All functions of the compression library are documented in the file
|
||||
zlib.h. A usage example of the library is given in the file example.c
|
||||
which also tests that the library is working correctly. Another
|
||||
example is given in the file minigzip.c. The compression library itself
|
||||
is composed of all source files except example.c and minigzip.c.
|
||||
All functions of the compression library are documented in the file zlib.h
|
||||
(volunteer to write man pages welcome, contact jloup@gzip.org). A usage
|
||||
example of the library is given in the file example.c which also tests that
|
||||
the library is working correctly. Another example is given in the file
|
||||
minigzip.c. The compression library itself is composed of all source files
|
||||
except example.c and minigzip.c.
|
||||
|
||||
To compile all files and run the test program, follow the instructions
|
||||
given at the top of Makefile. In short "make test; make install"
|
||||
@ -18,45 +19,72 @@ makefiles such as Makefile.msc; for VMS, use Make_vms.com or descrip.mms.
|
||||
|
||||
Questions about zlib should be sent to <zlib@quest.jpl.nasa.gov> or,
|
||||
if this fails, to the addresses given below in the Copyright section.
|
||||
The zlib home page is http://quest.jpl.nasa.gov/zlib/
|
||||
The zlib home page is http://www.cdrom.com/pub/infozip/zlib/
|
||||
The official zlib ftp site is ftp://ftp.cdrom.com/pub/infozip/zlib/
|
||||
Mark Nelson wrote an article about zlib for the Jan. 1997 issue of
|
||||
Dr. Dobb's Journal; a copy of the article is available in
|
||||
http://web2.airmail.net/markn/articles/zlibtool/zlibtool.htm
|
||||
|
||||
The changes made in version 1.0.4 are documented in the file ChangeLog.
|
||||
The main changes since 1.0.3 are:
|
||||
The changes made in version 1.1.1 are documented in the file ChangeLog.
|
||||
The main changes since 1.1.0 are:
|
||||
|
||||
- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF
|
||||
bit, so the decompressor could decompress all the correct data but went
|
||||
on to attempt decompressing extra garbage data. This affected minigzip too.
|
||||
- zlibVersion and gzerror return const char* (needed for DLL)
|
||||
- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno)
|
||||
- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson)
|
||||
- remove block truncation heuristic which had very marginal effect for zlib
|
||||
(smaller lit_bufsize than in gzip 1.2.4) and degraded a little the
|
||||
compression ratio on some files. This also allows inlining _tr_tally for
|
||||
matches in deflate_slow.
|
||||
|
||||
|
||||
Unsupported third party contributions are provided in directory "contrib".
|
||||
|
||||
A Java implementation of zlib is available in the Java Development Kit 1.1
|
||||
http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html
|
||||
See the zlib home page http://www.cdrom.com/pub/infozip/zlib/ for details.
|
||||
|
||||
A Perl interface to zlib written by Paul Marquess <pmarquess@bfsec.bt.co.uk>
|
||||
is in the CPAN (Comprehensive Perl Archive Network) sites, such as:
|
||||
ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib*
|
||||
|
||||
A Python interface to zlib written by A.M. Kuchling <amk@magnet.com>
|
||||
is available from the Python Software Association sites, such as:
|
||||
ftp://ftp.python.org/pub/python/contrib/Encoding/zlib*.tar.gz
|
||||
|
||||
An experimental package to read files in .zip format, written on top of
|
||||
zlib by Gilles Vollant <info@winimage.com>, is available at
|
||||
http://www.winimage.com/zLibDll/unzip.html
|
||||
|
||||
|
||||
Notes for some targets:
|
||||
|
||||
- For Turbo C the small model is supported only with reduced performance to
|
||||
avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
|
||||
- To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc
|
||||
and all .c files except example.c and minigzip.c; compile with -DZLIB_DLL
|
||||
The zlib DLL support was initially done by Alessandro Iacopetti and is
|
||||
now maintained by Gilles Vollant <info@winimage.com>. Check the zlib DLL
|
||||
home page at http://www.winimage.com/zLibDll
|
||||
|
||||
- For 64-bit Iris, deflate.c must be compiled without any optimization.
|
||||
From Visual Basic, you can call the DLL functions which do not take
|
||||
a structure as argument: compress, uncompress and all gz* functions.
|
||||
See contrib/visual-basic.txt for more information.
|
||||
I don't know how to handle structures in Visual Basic, sorry.
|
||||
|
||||
- For 64-bit Irix, deflate.c must be compiled without any optimization.
|
||||
With -O, one libpng test fails. The test works in 32 bit mode (with
|
||||
the -32 compiler flag). The compiler bug has been reported to SGI.
|
||||
the -n32 compiler flag). The compiler bug has been reported to SGI.
|
||||
|
||||
- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1
|
||||
it works when compiled with cc.
|
||||
|
||||
- zlib doesn't work on HP-UX 9.05 with one cc compiler (the one not
|
||||
accepting the -O option). It works with the other cc compiler.
|
||||
- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works
|
||||
with other compilers. Use "make test" to check your compiler.
|
||||
|
||||
- To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc
|
||||
and all .c files except example.c and minigzip.c; compile with -DZLIB_DLL
|
||||
For help on building a zlib DLL, contact Alessandro Iacopetti
|
||||
<iaco@email.alessandria.alpcom.it> http://lisa.unial.it/iaco ,
|
||||
or contact Brad Clarke <bclarke@cyberus.ca>.
|
||||
- For shared memory multiprocessors, the decompression code assumes that
|
||||
writes to pointers are atomic. Also the functions zalloc and zfree passed
|
||||
to deflateInit must be multi-threaded in this case.
|
||||
|
||||
- gzdopen is not supported on RISCOS
|
||||
- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers.
|
||||
|
||||
- For Turbo C the small model is supported only with reduced performance to
|
||||
avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
|
||||
|
||||
|
||||
Acknowledgments:
|
||||
@ -68,7 +96,7 @@ Acknowledgments:
|
||||
|
||||
Copyright notice:
|
||||
|
||||
(C) 1995-1996 Jean-loup Gailly and Mark Adler
|
||||
(C) 1995-1998 Jean-loup Gailly and Mark Adler
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@ -87,7 +115,7 @@ Copyright notice:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Jean-loup Gailly Mark Adler
|
||||
gzip@prep.ai.mit.edu madler@alumni.caltech.edu
|
||||
jloup@gzip.org madler@alumni.caltech.edu
|
||||
|
||||
If you use the zlib library in a product, we would appreciate *not*
|
||||
receiving lengthy legal documents to sign. The sources are provided
|
||||
|
213
lib/libz/algorithm.txt
Normal file
213
lib/libz/algorithm.txt
Normal file
@ -0,0 +1,213 @@
|
||||
1. Compression algorithm (deflate)
|
||||
|
||||
The deflation algorithm used by gzip (also zip and zlib) is a variation of
|
||||
LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in
|
||||
the input data. The second occurrence of a string is replaced by a
|
||||
pointer to the previous string, in the form of a pair (distance,
|
||||
length). Distances are limited to 32K bytes, and lengths are limited
|
||||
to 258 bytes. When a string does not occur anywhere in the previous
|
||||
32K bytes, it is emitted as a sequence of literal bytes. (In this
|
||||
description, `string' must be taken as an arbitrary sequence of bytes,
|
||||
and is not restricted to printable characters.)
|
||||
|
||||
Literals or match lengths are compressed with one Huffman tree, and
|
||||
match distances are compressed with another tree. The trees are stored
|
||||
in a compact form at the start of each block. The blocks can have any
|
||||
size (except that the compressed data for one block must fit in
|
||||
available memory). A block is terminated when deflate() determines that
|
||||
it would be useful to start another block with fresh trees. (This is
|
||||
somewhat similar to the behavior of LZW-based _compress_.)
|
||||
|
||||
Duplicated strings are found using a hash table. All input strings of
|
||||
length 3 are inserted in the hash table. A hash index is computed for
|
||||
the next 3 bytes. If the hash chain for this index is not empty, all
|
||||
strings in the chain are compared with the current input string, and
|
||||
the longest match is selected.
|
||||
|
||||
The hash chains are searched starting with the most recent strings, to
|
||||
favor small distances and thus take advantage of the Huffman encoding.
|
||||
The hash chains are singly linked. There are no deletions from the
|
||||
hash chains, the algorithm simply discards matches that are too old.
|
||||
|
||||
To avoid a worst-case situation, very long hash chains are arbitrarily
|
||||
truncated at a certain length, determined by a runtime option (level
|
||||
parameter of deflateInit). So deflate() does not always find the longest
|
||||
possible match but generally finds a match which is long enough.
|
||||
|
||||
deflate() also defers the selection of matches with a lazy evaluation
|
||||
mechanism. After a match of length N has been found, deflate() searches for
|
||||
a longer match at the next input byte. If a longer match is found, the
|
||||
previous match is truncated to a length of one (thus producing a single
|
||||
literal byte) and the process of lazy evaluation begins again. Otherwise,
|
||||
the original match is kept, and the next match search is attempted only N
|
||||
steps later.
|
||||
|
||||
The lazy match evaluation is also subject to a runtime parameter. If
|
||||
the current match is long enough, deflate() reduces the search for a longer
|
||||
match, thus speeding up the whole process. If compression ratio is more
|
||||
important than speed, deflate() attempts a complete second search even if
|
||||
the first match is already long enough.
|
||||
|
||||
The lazy match evaluation is not performed for the fastest compression
|
||||
modes (level parameter 1 to 3). For these fast modes, new strings
|
||||
are inserted in the hash table only when no match was found, or
|
||||
when the match is not too long. This degrades the compression ratio
|
||||
but saves time since there are both fewer insertions and fewer searches.
|
||||
|
||||
|
||||
2. Decompression algorithm (inflate)
|
||||
|
||||
2.1 Introduction
|
||||
|
||||
The real question is, given a Huffman tree, how to decode fast. The most
|
||||
important realization is that shorter codes are much more common than
|
||||
longer codes, so pay attention to decoding the short codes fast, and let
|
||||
the long codes take longer to decode.
|
||||
|
||||
inflate() sets up a first level table that covers some number of bits of
|
||||
input less than the length of longest code. It gets that many bits from the
|
||||
stream, and looks it up in the table. The table will tell if the next
|
||||
code is that many bits or less and how many, and if it is, it will tell
|
||||
the value, else it will point to the next level table for which inflate()
|
||||
grabs more bits and tries to decode a longer code.
|
||||
|
||||
How many bits to make the first lookup is a tradeoff between the time it
|
||||
takes to decode and the time it takes to build the table. If building the
|
||||
table took no time (and if you had infinite memory), then there would only
|
||||
be a first level table to cover all the way to the longest code. However,
|
||||
building the table ends up taking a lot longer for more bits since short
|
||||
codes are replicated many times in such a table. What inflate() does is
|
||||
simply to make the number of bits in the first table a variable, and set it
|
||||
for the maximum speed.
|
||||
|
||||
inflate() sends new trees relatively often, so it is possibly set for a
|
||||
smaller first level table than an application that has only one tree for
|
||||
all the data. For inflate, which has 286 possible codes for the
|
||||
literal/length tree, the size of the first table is nine bits. Also the
|
||||
distance trees have 30 possible values, and the size of the first table is
|
||||
six bits. Note that for each of those cases, the table ended up one bit
|
||||
longer than the ``average'' code length, i.e. the code length of an
|
||||
approximately flat code which would be a little more than eight bits for
|
||||
286 symbols and a little less than five bits for 30 symbols. It would be
|
||||
interesting to see if optimizing the first level table for other
|
||||
applications gave values within a bit or two of the flat code size.
|
||||
|
||||
|
||||
2.2 More details on the inflate table lookup
|
||||
|
||||
Ok, you want to know what this cleverly obfuscated inflate tree actually
|
||||
looks like. You are correct that it's not a Huffman tree. It is simply a
|
||||
lookup table for the first, let's say, nine bits of a Huffman symbol. The
|
||||
symbol could be as short as one bit or as long as 15 bits. If a particular
|
||||
symbol is shorter than nine bits, then that symbol's translation is duplicated
|
||||
in all those entries that start with that symbol's bits. For example, if the
|
||||
symbol is four bits, then it's duplicated 32 times in a nine-bit table. If a
|
||||
symbol is nine bits long, it appears in the table once.
|
||||
|
||||
If the symbol is longer than nine bits, then that entry in the table points
|
||||
to another similar table for the remaining bits. Again, there are duplicated
|
||||
entries as needed. The idea is that most of the time the symbol will be short
|
||||
and there will only be one table look up. (That's whole idea behind data
|
||||
compression in the first place.) For the less frequent long symbols, there
|
||||
will be two lookups. If you had a compression method with really long
|
||||
symbols, you could have as many levels of lookups as is efficient. For
|
||||
inflate, two is enough.
|
||||
|
||||
So a table entry either points to another table (in which case nine bits in
|
||||
the above example are gobbled), or it contains the translation for the symbol
|
||||
and the number of bits to gobble. Then you start again with the next
|
||||
ungobbled bit.
|
||||
|
||||
You may wonder: why not just have one lookup table for how ever many bits the
|
||||
longest symbol is? The reason is that if you do that, you end up spending
|
||||
more time filling in duplicate symbol entries than you do actually decoding.
|
||||
At least for deflate's output that generates new trees every several 10's of
|
||||
kbytes. You can imagine that filling in a 2^15 entry table for a 15-bit code
|
||||
would take too long if you're only decoding several thousand symbols. At the
|
||||
other extreme, you could make a new table for every bit in the code. In fact,
|
||||
that's essentially a Huffman tree. But then you spend two much time
|
||||
traversing the tree while decoding, even for short symbols.
|
||||
|
||||
So the number of bits for the first lookup table is a trade of the time to
|
||||
fill out the table vs. the time spent looking at the second level and above of
|
||||
the table.
|
||||
|
||||
Here is an example, scaled down:
|
||||
|
||||
The code being decoded, with 10 symbols, from 1 to 6 bits long:
|
||||
|
||||
A: 0
|
||||
B: 10
|
||||
C: 1100
|
||||
D: 11010
|
||||
E: 11011
|
||||
F: 11100
|
||||
G: 11101
|
||||
H: 11110
|
||||
I: 111110
|
||||
J: 111111
|
||||
|
||||
Let's make the first table three bits long (eight entries):
|
||||
|
||||
000: A,1
|
||||
001: A,1
|
||||
010: A,1
|
||||
011: A,1
|
||||
100: B,2
|
||||
101: B,2
|
||||
110: -> table X (gobble 3 bits)
|
||||
111: -> table Y (gobble 3 bits)
|
||||
|
||||
Each entry is what the bits decode to and how many bits that is, i.e. how
|
||||
many bits to gobble. Or the entry points to another table, with the number of
|
||||
bits to gobble implicit in the size of the table.
|
||||
|
||||
Table X is two bits long since the longest code starting with 110 is five bits
|
||||
long:
|
||||
|
||||
00: C,1
|
||||
01: C,1
|
||||
10: D,2
|
||||
11: E,2
|
||||
|
||||
Table Y is three bits long since the longest code starting with 111 is six
|
||||
bits long:
|
||||
|
||||
000: F,2
|
||||
001: F,2
|
||||
010: G,2
|
||||
011: G,2
|
||||
100: H,2
|
||||
101: H,2
|
||||
110: I,3
|
||||
111: J,3
|
||||
|
||||
So what we have here are three tables with a total of 20 entries that had to
|
||||
be constructed. That's compared to 64 entries for a single table. Or
|
||||
compared to 16 entries for a Huffman tree (six two entry tables and one four
|
||||
entry table). Assuming that the code ideally represents the probability of
|
||||
the symbols, it takes on the average 1.25 lookups per symbol. That's compared
|
||||
to one lookup for the single table, or 1.66 lookups per symbol for the
|
||||
Huffman tree.
|
||||
|
||||
There, I think that gives you a picture of what's going on. For inflate, the
|
||||
meaning of a particular symbol is often more than just a letter. It can be a
|
||||
byte (a "literal"), or it can be either a length or a distance which
|
||||
indicates a base value and a number of bits to fetch after the code that is
|
||||
added to the base value. Or it might be the special end-of-block code. The
|
||||
data structures created in inftrees.c try to encode all that information
|
||||
compactly in the tables.
|
||||
|
||||
|
||||
Jean-loup Gailly Mark Adler
|
||||
jloup@gzip.org madler@alumni.caltech.edu
|
||||
|
||||
|
||||
References:
|
||||
|
||||
[LZ77] Ziv J., Lempel A., ``A Universal Algorithm for Sequential Data
|
||||
Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3,
|
||||
pp. 337-343.
|
||||
|
||||
``DEFLATE Compressed Data Format Specification'' available in
|
||||
ftp://ds.internic.net/rfc/rfc1951.txt
|
@ -1,5 +1,5 @@
|
||||
/* infblock.c -- interpret and process block types to last block
|
||||
* Copyright (C) 1995-1996 Mark Adler
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@ -66,23 +66,19 @@ inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
uLongf *c;
|
||||
{
|
||||
if (s->checkfn != Z_NULL)
|
||||
if (c != Z_NULL)
|
||||
*c = s->check;
|
||||
if (s->mode == BTREE || s->mode == DTREE)
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
if (s->mode == CODES)
|
||||
{
|
||||
inflate_codes_free(s->sub.decode.codes, z);
|
||||
inflate_trees_free(s->sub.decode.td, z);
|
||||
inflate_trees_free(s->sub.decode.tl, z);
|
||||
}
|
||||
s->mode = TYPE;
|
||||
s->bitk = 0;
|
||||
s->bitb = 0;
|
||||
s->read = s->write = s->window;
|
||||
if (s->checkfn != Z_NULL)
|
||||
z->adler = s->check = (*s->checkfn)(0L, Z_NULL, 0);
|
||||
Trace((stderr, "inflate: blocks reset\n"));
|
||||
z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0);
|
||||
Tracev((stderr, "inflate: blocks reset\n"));
|
||||
}
|
||||
|
||||
|
||||
@ -96,23 +92,27 @@ uInt w;
|
||||
if ((s = (inflate_blocks_statef *)ZALLOC
|
||||
(z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
|
||||
return s;
|
||||
if ((s->hufts =
|
||||
(inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
|
||||
{
|
||||
ZFREE(z, s);
|
||||
return Z_NULL;
|
||||
}
|
||||
if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
|
||||
{
|
||||
ZFREE(z, s->hufts);
|
||||
ZFREE(z, s);
|
||||
return Z_NULL;
|
||||
}
|
||||
s->end = s->window + w;
|
||||
s->checkfn = c;
|
||||
s->mode = TYPE;
|
||||
Trace((stderr, "inflate: blocks allocated\n"));
|
||||
inflate_blocks_reset(s, z, &s->check);
|
||||
Tracev((stderr, "inflate: blocks allocated\n"));
|
||||
inflate_blocks_reset(s, z, Z_NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
extern uInt inflate_hufts;
|
||||
#endif
|
||||
int inflate_blocks(s, z, r)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
@ -139,7 +139,7 @@ int r;
|
||||
switch (t >> 1)
|
||||
{
|
||||
case 0: /* stored */
|
||||
Trace((stderr, "inflate: stored block%s\n",
|
||||
Tracev((stderr, "inflate: stored block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
DUMPBITS(3)
|
||||
t = k & 7; /* go to byte boundary */
|
||||
@ -147,27 +147,25 @@ int r;
|
||||
s->mode = LENS; /* get length of stored block */
|
||||
break;
|
||||
case 1: /* fixed */
|
||||
Trace((stderr, "inflate: fixed codes block%s\n",
|
||||
Tracev((stderr, "inflate: fixed codes block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
{
|
||||
uInt bl, bd;
|
||||
inflate_huft *tl, *td;
|
||||
|
||||
inflate_trees_fixed(&bl, &bd, &tl, &td);
|
||||
inflate_trees_fixed(&bl, &bd, &tl, &td, z);
|
||||
s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
|
||||
if (s->sub.decode.codes == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
s->sub.decode.tl = Z_NULL; /* don't try to free these */
|
||||
s->sub.decode.td = Z_NULL;
|
||||
}
|
||||
DUMPBITS(3)
|
||||
s->mode = CODES;
|
||||
break;
|
||||
case 2: /* dynamic */
|
||||
Trace((stderr, "inflate: dynamic codes block%s\n",
|
||||
Tracev((stderr, "inflate: dynamic codes block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
DUMPBITS(3)
|
||||
s->mode = TABLE;
|
||||
@ -224,8 +222,6 @@ int r;
|
||||
}
|
||||
#endif
|
||||
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
|
||||
if (t < 19)
|
||||
t = 19;
|
||||
if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
@ -246,7 +242,7 @@ int r;
|
||||
s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
|
||||
s->sub.trees.bb = 7;
|
||||
t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
|
||||
&s->sub.trees.tb, z);
|
||||
&s->sub.trees.tb, s->hufts, z);
|
||||
if (t != Z_OK)
|
||||
{
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
@ -288,7 +284,6 @@ int r;
|
||||
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
|
||||
(c == 16 && i < 1))
|
||||
{
|
||||
inflate_trees_free(s->sub.trees.tb, z);
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
s->mode = BAD;
|
||||
z->msg = (char*)"invalid bit length repeat";
|
||||
@ -302,7 +297,6 @@ int r;
|
||||
s->sub.trees.index = i;
|
||||
}
|
||||
}
|
||||
inflate_trees_free(s->sub.trees.tb, z);
|
||||
s->sub.trees.tb = Z_NULL;
|
||||
{
|
||||
uInt bl, bd;
|
||||
@ -312,11 +306,9 @@ int r;
|
||||
bl = 9; /* must be <= 9 for lookahead assumptions */
|
||||
bd = 6; /* must be <= 9 for lookahead assumptions */
|
||||
t = s->sub.trees.table;
|
||||
#ifdef DEBUG
|
||||
inflate_hufts = 0;
|
||||
#endif
|
||||
t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
|
||||
s->sub.trees.blens, &bl, &bd, &tl, &td, z);
|
||||
s->sub.trees.blens, &bl, &bd, &tl, &td,
|
||||
s->hufts, z);
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
if (t != Z_OK)
|
||||
{
|
||||
@ -325,18 +317,13 @@ int r;
|
||||
r = t;
|
||||
LEAVE
|
||||
}
|
||||
Tracev((stderr, "inflate: trees ok, %d * %d bytes used\n",
|
||||
inflate_hufts, sizeof(inflate_huft)));
|
||||
Tracev((stderr, "inflate: trees ok\n"));
|
||||
if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
|
||||
{
|
||||
inflate_trees_free(td, z);
|
||||
inflate_trees_free(tl, z);
|
||||
r = Z_MEM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
s->sub.decode.codes = c;
|
||||
s->sub.decode.tl = tl;
|
||||
s->sub.decode.td = td;
|
||||
}
|
||||
s->mode = CODES;
|
||||
case CODES:
|
||||
@ -345,8 +332,6 @@ int r;
|
||||
return inflate_flush(s, z, r);
|
||||
r = Z_OK;
|
||||
inflate_codes_free(s->sub.decode.codes, z);
|
||||
inflate_trees_free(s->sub.decode.td, z);
|
||||
inflate_trees_free(s->sub.decode.tl, z);
|
||||
LOAD
|
||||
Tracev((stderr, "inflate: codes end, %lu total out\n",
|
||||
z->total_out + (q >= s->read ? q - s->read :
|
||||
@ -382,15 +367,15 @@ int r;
|
||||
}
|
||||
|
||||
|
||||
int inflate_blocks_free(s, z, c)
|
||||
int inflate_blocks_free(s, z)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
uLongf *c;
|
||||
{
|
||||
inflate_blocks_reset(s, z, c);
|
||||
inflate_blocks_reset(s, z, Z_NULL);
|
||||
ZFREE(z, s->window);
|
||||
ZFREE(z, s->hufts);
|
||||
ZFREE(z, s);
|
||||
Trace((stderr, "inflate: blocks freed\n"));
|
||||
Tracev((stderr, "inflate: blocks freed\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
@ -400,6 +385,17 @@ inflate_blocks_statef *s;
|
||||
const Bytef *d;
|
||||
uInt n;
|
||||
{
|
||||
zmemcpy((charf *)s->window, d, n);
|
||||
zmemcpy(s->window, d, n);
|
||||
s->read = s->write = s->window + n;
|
||||
}
|
||||
|
||||
|
||||
/* Returns true if inflate is currently at the end of a block generated
|
||||
* by Z_SYNC_FLUSH or Z_FULL_FLUSH.
|
||||
* IN assertion: s != Z_NULL
|
||||
*/
|
||||
int inflate_blocks_sync_point(s)
|
||||
inflate_blocks_statef *s;
|
||||
{
|
||||
return s->mode == LENS;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* infblock.h -- header to use infblock.c
|
||||
* Copyright (C) 1995-1996 Mark Adler
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@ -28,10 +28,12 @@ extern void inflate_blocks_reset OF((
|
||||
|
||||
extern int inflate_blocks_free OF((
|
||||
inflate_blocks_statef *,
|
||||
z_streamp ,
|
||||
uLongf *)); /* check value on output */
|
||||
z_streamp));
|
||||
|
||||
extern void inflate_set_dictionary OF((
|
||||
inflate_blocks_statef *s,
|
||||
const Bytef *d, /* dictionary */
|
||||
uInt n)); /* dictionary length */
|
||||
|
||||
extern int inflate_blocks_sync_point OF((
|
||||
inflate_blocks_statef *s));
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* infcodes.c -- process literals and length/distance pairs
|
||||
* Copyright (C) 1995-1996 Mark Adler
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@ -16,11 +16,7 @@
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
/* inflate codes private state */
|
||||
struct inflate_codes_state {
|
||||
|
||||
/* mode */
|
||||
enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
||||
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
||||
START, /* x: set up for LEN */
|
||||
LEN, /* i: get length/literal/eob next */
|
||||
LENEXT, /* i: getting length extra (have base) */
|
||||
@ -31,7 +27,13 @@ struct inflate_codes_state {
|
||||
WASH, /* o: got eob, possibly still output waiting */
|
||||
END, /* x: got eob and all data flushed */
|
||||
BADCODE} /* x: got error */
|
||||
mode; /* current inflate_codes mode */
|
||||
inflate_codes_mode;
|
||||
|
||||
/* inflate codes private state */
|
||||
struct inflate_codes_state {
|
||||
|
||||
/* mode */
|
||||
inflate_codes_mode mode; /* current inflate_codes mode */
|
||||
|
||||
/* mode dependent information */
|
||||
uInt len;
|
||||
@ -235,6 +237,9 @@ int r;
|
||||
r = Z_STREAM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
#ifdef NEED_DUMMY_RETURN
|
||||
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* infcodes.h -- header to use infcodes.c
|
||||
* Copyright (C) 1995-1996 Mark Adler
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* inffast.c -- process literals and length/distance pairs fast
|
||||
* Copyright (C) 1995-1996 Mark Adler
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* inffast.h -- header to use inffast.c
|
||||
* Copyright (C) 1995-1996 Mark Adler
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* inflate.c -- zlib interface to inflate modules
|
||||
* Copyright (C) 1995-1996 Mark Adler
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@ -8,11 +8,7 @@
|
||||
|
||||
struct inflate_blocks_state {int dummy;}; /* for buggy compilers */
|
||||
|
||||
/* inflate private state */
|
||||
struct internal_state {
|
||||
|
||||
/* mode */
|
||||
enum {
|
||||
typedef enum {
|
||||
METHOD, /* waiting for method byte */
|
||||
FLAG, /* waiting for flag byte */
|
||||
DICT4, /* four dictionary check bytes to go */
|
||||
@ -27,7 +23,13 @@ struct internal_state {
|
||||
CHECK1, /* one check byte to go */
|
||||
DONE, /* finished check, done */
|
||||
BAD} /* got an error--stay here */
|
||||
mode; /* current inflate mode */
|
||||
inflate_mode;
|
||||
|
||||
/* inflate private state */
|
||||
struct internal_state {
|
||||
|
||||
/* mode */
|
||||
inflate_mode mode; /* current inflate mode */
|
||||
|
||||
/* mode dependent information */
|
||||
union {
|
||||
@ -48,39 +50,35 @@ struct internal_state {
|
||||
};
|
||||
|
||||
|
||||
int inflateReset(z)
|
||||
int ZEXPORT inflateReset(z)
|
||||
z_streamp z;
|
||||
{
|
||||
uLong c;
|
||||
|
||||
if (z == Z_NULL || z->state == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
z->total_in = z->total_out = 0;
|
||||
z->msg = Z_NULL;
|
||||
z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
|
||||
inflate_blocks_reset(z->state->blocks, z, &c);
|
||||
Trace((stderr, "inflate: reset\n"));
|
||||
inflate_blocks_reset(z->state->blocks, z, Z_NULL);
|
||||
Tracev((stderr, "inflate: reset\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
int inflateEnd(z)
|
||||
int ZEXPORT inflateEnd(z)
|
||||
z_streamp z;
|
||||
{
|
||||
uLong c;
|
||||
|
||||
if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
if (z->state->blocks != Z_NULL)
|
||||
inflate_blocks_free(z->state->blocks, z, &c);
|
||||
inflate_blocks_free(z->state->blocks, z);
|
||||
ZFREE(z, z->state);
|
||||
z->state = Z_NULL;
|
||||
Trace((stderr, "inflate: end\n"));
|
||||
Tracev((stderr, "inflate: end\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
int inflateInit2_(z, w, version, stream_size)
|
||||
int ZEXPORT inflateInit2_(z, w, version, stream_size)
|
||||
z_streamp z;
|
||||
int w;
|
||||
const char *version;
|
||||
@ -129,7 +127,7 @@ int stream_size;
|
||||
inflateEnd(z);
|
||||
return Z_MEM_ERROR;
|
||||
}
|
||||
Trace((stderr, "inflate: allocated\n"));
|
||||
Tracev((stderr, "inflate: allocated\n"));
|
||||
|
||||
/* reset state */
|
||||
inflateReset(z);
|
||||
@ -137,7 +135,7 @@ int stream_size;
|
||||
}
|
||||
|
||||
|
||||
int inflateInit_(z, version, stream_size)
|
||||
int ZEXPORT inflateInit_(z, version, stream_size)
|
||||
z_streamp z;
|
||||
const char *version;
|
||||
int stream_size;
|
||||
@ -146,18 +144,19 @@ int stream_size;
|
||||
}
|
||||
|
||||
|
||||
#define NEEDBYTE {if(z->avail_in==0)return r;r=Z_OK;}
|
||||
#define NEEDBYTE {if(z->avail_in==0)return r;r=f;}
|
||||
#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
|
||||
|
||||
int inflate(z, f)
|
||||
int ZEXPORT inflate(z, f)
|
||||
z_streamp z;
|
||||
int f;
|
||||
{
|
||||
int r;
|
||||
uInt b;
|
||||
|
||||
if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL || f < 0)
|
||||
if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
|
||||
r = Z_BUF_ERROR;
|
||||
while (1) switch (z->state->mode)
|
||||
{
|
||||
@ -188,11 +187,11 @@ int f;
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
break;
|
||||
}
|
||||
Trace((stderr, "inflate: zlib header ok\n"));
|
||||
Tracev((stderr, "inflate: zlib header ok\n"));
|
||||
if (!(b & PRESET_DICT))
|
||||
{
|
||||
z->state->mode = BLOCKS;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
z->state->mode = DICT4;
|
||||
case DICT4:
|
||||
@ -226,9 +225,11 @@ int f;
|
||||
z->state->sub.marker = 0; /* can try inflateSync */
|
||||
break;
|
||||
}
|
||||
if (r == Z_OK)
|
||||
r = f;
|
||||
if (r != Z_STREAM_END)
|
||||
return r;
|
||||
r = Z_OK;
|
||||
r = f;
|
||||
inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
|
||||
if (z->state->nowrap)
|
||||
{
|
||||
@ -259,7 +260,7 @@ int f;
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
break;
|
||||
}
|
||||
Trace((stderr, "inflate: zlib check ok\n"));
|
||||
Tracev((stderr, "inflate: zlib check ok\n"));
|
||||
z->state->mode = DONE;
|
||||
case DONE:
|
||||
return Z_STREAM_END;
|
||||
@ -268,10 +269,13 @@ int f;
|
||||
default:
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
#ifdef NEED_DUMMY_RETURN
|
||||
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int inflateSetDictionary(z, dictionary, dictLength)
|
||||
int ZEXPORT inflateSetDictionary(z, dictionary, dictLength)
|
||||
z_streamp z;
|
||||
const Bytef *dictionary;
|
||||
uInt dictLength;
|
||||
@ -295,7 +299,7 @@ uInt dictLength;
|
||||
}
|
||||
|
||||
|
||||
int inflateSync(z)
|
||||
int ZEXPORT inflateSync(z)
|
||||
z_streamp z;
|
||||
{
|
||||
uInt n; /* number of bytes to look at */
|
||||
@ -319,7 +323,8 @@ z_streamp z;
|
||||
/* search */
|
||||
while (n && m < 4)
|
||||
{
|
||||
if (*p == (Byte)(m < 2 ? 0 : 0xff))
|
||||
static const Byte mark[4] = {0, 0, 0xff, 0xff};
|
||||
if (*p == mark[m])
|
||||
m++;
|
||||
else if (*p)
|
||||
m = 0;
|
||||
@ -343,3 +348,19 @@ z_streamp z;
|
||||
z->state->mode = BLOCKS;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
/* Returns true if inflate is currently at the end of a block generated
|
||||
* by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
|
||||
* implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
|
||||
* but removes the length bytes of the resulting empty stored block. When
|
||||
* decompressing, PPP checks that at the end of input packet, inflate is
|
||||
* waiting for these length bytes.
|
||||
*/
|
||||
int ZEXPORT inflateSyncPoint(z)
|
||||
z_streamp z;
|
||||
{
|
||||
if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
return inflate_blocks_sync_point(z->state->blocks);
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
/* inftrees.c -- generate Huffman trees for efficient decoding
|
||||
* Copyright (C) 1995-1996 Mark Adler
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
|
||||
char inflate_copyright[] = " inflate 1.0.4 Copyright 1995-1996 Mark Adler ";
|
||||
const char inflate_copyright[] =
|
||||
" inflate 1.1.1 Copyright 1995-1998 Mark Adler ";
|
||||
/*
|
||||
If you use the zlib library in a product, an acknowledgment is welcome
|
||||
in the documentation of your product. If for some reason you cannot
|
||||
@ -30,12 +31,9 @@ local int huft_build OF((
|
||||
const uIntf *, /* list of extra bits for non-simple codes */
|
||||
inflate_huft * FAR*,/* result: starting table */
|
||||
uIntf *, /* maximum lookup bits (returns actual) */
|
||||
z_streamp )); /* for zalloc function */
|
||||
|
||||
local voidpf falloc OF((
|
||||
voidpf, /* opaque pointer (not used) */
|
||||
uInt, /* number of items */
|
||||
uInt)); /* size of item */
|
||||
inflate_huft *, /* space for trees */
|
||||
uInt *, /* hufts used in space */
|
||||
uIntf * )); /* space for values */
|
||||
|
||||
/* Tables for deflate from PKZIP's appnote.txt. */
|
||||
local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
|
||||
@ -89,21 +87,18 @@ local const uInt cpdext[30] = { /* Extra bits for distance codes */
|
||||
|
||||
/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
|
||||
#define BMAX 15 /* maximum bit length of any code */
|
||||
#define N_MAX 288 /* maximum number of codes in any set */
|
||||
|
||||
#ifdef DEBUG
|
||||
uInt inflate_hufts;
|
||||
#endif
|
||||
|
||||
local int huft_build(b, n, s, d, e, t, m, zs)
|
||||
local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
|
||||
uIntf *b; /* code lengths in bits (all assumed <= BMAX) */
|
||||
uInt n; /* number of codes (assumed <= N_MAX) */
|
||||
uInt n; /* number of codes (assumed <= 288) */
|
||||
uInt s; /* number of simple-valued codes (0..s-1) */
|
||||
const uIntf *d; /* list of base values for non-simple codes */
|
||||
const uIntf *e; /* list of extra bits for non-simple codes */
|
||||
inflate_huft * FAR *t; /* result: starting table */
|
||||
uIntf *m; /* maximum lookup bits, returns actual */
|
||||
z_streamp zs; /* for zalloc function */
|
||||
inflate_huft *hp; /* space for trees */
|
||||
uInt *hn; /* hufts used in space */
|
||||
uIntf *v; /* working area: values in order of bit length */
|
||||
/* Given a list of code lengths and a maximum table size, make a set of
|
||||
tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
|
||||
if the given code set is incomplete (the tables are still built in this
|
||||
@ -120,11 +115,11 @@ z_streamp zs; /* for zalloc function */
|
||||
register uInt j; /* counter */
|
||||
register int k; /* number of bits in current code */
|
||||
int l; /* bits per table (returned in m) */
|
||||
uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
|
||||
register uIntf *p; /* pointer into c[], b[], or v[] */
|
||||
inflate_huft *q; /* points to current table */
|
||||
struct inflate_huft_s r; /* table entry for structure assignment */
|
||||
inflate_huft *u[BMAX]; /* table stack */
|
||||
uInt v[N_MAX]; /* values in order of bit length */
|
||||
register int w; /* bits before this table == (l * h) */
|
||||
uInt x[BMAX+1]; /* bit offsets, then code stack */
|
||||
uIntf *xp; /* pointer into x */
|
||||
@ -190,7 +185,7 @@ z_streamp zs; /* for zalloc function */
|
||||
if ((j = *p++) != 0)
|
||||
v[x[j]++] = i;
|
||||
} while (++i < n);
|
||||
n = x[g]; /* set n to length of v */
|
||||
n = x[g]; /* set n to length of v */
|
||||
|
||||
|
||||
/* Generate the Huffman codes and for each, make the table entries */
|
||||
@ -232,20 +227,16 @@ z_streamp zs; /* for zalloc function */
|
||||
}
|
||||
z = 1 << j; /* table entries for j-bit table */
|
||||
|
||||
/* allocate and link in new table */
|
||||
if ((q = (inflate_huft *)ZALLOC
|
||||
(zs,z + 1,sizeof(inflate_huft))) == Z_NULL)
|
||||
{
|
||||
if (h)
|
||||
inflate_trees_free(u[0], zs);
|
||||
/* allocate new table */
|
||||
if (*hn + z > MANY) /* (note: doesn't matter for fixed) */
|
||||
return Z_MEM_ERROR; /* not enough memory */
|
||||
u[h] = q = hp + *hn;
|
||||
*hn += z;
|
||||
if (t != Z_NULL) /* first table is returned result */
|
||||
{
|
||||
*t = q;
|
||||
t = Z_NULL;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
inflate_hufts += z + 1;
|
||||
#endif
|
||||
*t = q + 1; /* link to list for huft_free() */
|
||||
*(t = &(q->next)) = Z_NULL;
|
||||
u[h] = ++q; /* table starts after link */
|
||||
|
||||
/* connect to last table, if there is one */
|
||||
if (h)
|
||||
@ -285,10 +276,12 @@ z_streamp zs; /* for zalloc function */
|
||||
i ^= j;
|
||||
|
||||
/* backup over finished tables */
|
||||
while ((i & ((1 << w) - 1)) != x[h])
|
||||
mask = (1 << w) - 1; /* needed on HP, cc -O bug */
|
||||
while ((i & mask) != x[h])
|
||||
{
|
||||
h--; /* don't need to update q */
|
||||
w -= l;
|
||||
mask = (1 << w) - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -299,28 +292,34 @@ z_streamp zs; /* for zalloc function */
|
||||
}
|
||||
|
||||
|
||||
int inflate_trees_bits(c, bb, tb, z)
|
||||
int inflate_trees_bits(c, bb, tb, hp, z)
|
||||
uIntf *c; /* 19 code lengths */
|
||||
uIntf *bb; /* bits tree desired/actual depth */
|
||||
inflate_huft * FAR *tb; /* bits tree result */
|
||||
z_streamp z; /* for zfree function */
|
||||
inflate_huft *hp; /* space for trees */
|
||||
z_streamp z; /* for messages */
|
||||
{
|
||||
int r;
|
||||
uInt hn = 0; /* hufts used in space */
|
||||
uIntf *v; /* work area for huft_build */
|
||||
|
||||
r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, tb, bb, z);
|
||||
if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
|
||||
return Z_MEM_ERROR;
|
||||
r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
|
||||
tb, bb, hp, &hn, v);
|
||||
if (r == Z_DATA_ERROR)
|
||||
z->msg = (char*)"oversubscribed dynamic bit lengths tree";
|
||||
else if (r == Z_BUF_ERROR || *bb == 0)
|
||||
{
|
||||
inflate_trees_free(*tb, z);
|
||||
z->msg = (char*)"incomplete dynamic bit lengths tree";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
ZFREE(z, v);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, z)
|
||||
int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z)
|
||||
uInt nl; /* number of literal/length codes */
|
||||
uInt nd; /* number of distance codes */
|
||||
uIntf *c; /* that many (total) code lengths */
|
||||
@ -328,27 +327,34 @@ uIntf *bl; /* literal desired/actual bit depth */
|
||||
uIntf *bd; /* distance desired/actual bit depth */
|
||||
inflate_huft * FAR *tl; /* literal/length tree result */
|
||||
inflate_huft * FAR *td; /* distance tree result */
|
||||
z_streamp z; /* for zfree function */
|
||||
inflate_huft *hp; /* space for trees */
|
||||
z_streamp z; /* for messages */
|
||||
{
|
||||
int r;
|
||||
uInt hn = 0; /* hufts used in space */
|
||||
uIntf *v; /* work area for huft_build */
|
||||
|
||||
/* allocate work area */
|
||||
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
|
||||
return Z_MEM_ERROR;
|
||||
|
||||
/* build literal/length tree */
|
||||
r = huft_build(c, nl, 257, cplens, cplext, tl, bl, z);
|
||||
r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
|
||||
if (r != Z_OK || *bl == 0)
|
||||
{
|
||||
if (r == Z_DATA_ERROR)
|
||||
z->msg = (char*)"oversubscribed literal/length tree";
|
||||
else if (r != Z_MEM_ERROR)
|
||||
{
|
||||
inflate_trees_free(*tl, z);
|
||||
z->msg = (char*)"incomplete literal/length tree";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
ZFREE(z, v);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* build distance tree */
|
||||
r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, z);
|
||||
r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
|
||||
if (r != Z_OK || (*bd == 0 && nl > 257))
|
||||
{
|
||||
if (r == Z_DATA_ERROR)
|
||||
@ -358,7 +364,6 @@ z_streamp z; /* for zfree function */
|
||||
r = Z_OK;
|
||||
}
|
||||
#else
|
||||
inflate_trees_free(*td, z);
|
||||
z->msg = (char*)"incomplete distance tree";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
@ -367,19 +372,20 @@ z_streamp z; /* for zfree function */
|
||||
z->msg = (char*)"empty distance tree with lengths";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
inflate_trees_free(*tl, z);
|
||||
ZFREE(z, v);
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* done */
|
||||
ZFREE(z, v);
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
/* build fixed tables only once--keep them here */
|
||||
local int fixed_built = 0;
|
||||
#define FIXEDH 530 /* number of hufts used by fixed tables */
|
||||
#define FIXEDH 424 /* number of hufts used by fixed tables */
|
||||
local inflate_huft fixed_mem[FIXEDH];
|
||||
local uInt fixed_bl;
|
||||
local uInt fixed_bd;
|
||||
@ -387,36 +393,29 @@ local inflate_huft *fixed_tl;
|
||||
local inflate_huft *fixed_td;
|
||||
|
||||
|
||||
local voidpf falloc(q, n, s)
|
||||
voidpf q; /* opaque pointer */
|
||||
uInt n; /* number of items */
|
||||
uInt s; /* size of item */
|
||||
{
|
||||
Assert(s == sizeof(inflate_huft) && n <= *(intf *)q,
|
||||
"inflate_trees falloc overflow");
|
||||
*(intf *)q -= n+s-s; /* s-s to avoid warning */
|
||||
return (voidpf)(fixed_mem + *(intf *)q);
|
||||
}
|
||||
|
||||
|
||||
int inflate_trees_fixed(bl, bd, tl, td)
|
||||
int inflate_trees_fixed(bl, bd, tl, td, z)
|
||||
uIntf *bl; /* literal desired/actual bit depth */
|
||||
uIntf *bd; /* distance desired/actual bit depth */
|
||||
inflate_huft * FAR *tl; /* literal/length tree result */
|
||||
inflate_huft * FAR *td; /* distance tree result */
|
||||
z_streamp z; /* for memory allocation */
|
||||
{
|
||||
/* build fixed tables if not already (multiple overlapped executions ok) */
|
||||
if (!fixed_built)
|
||||
{
|
||||
int k; /* temporary variable */
|
||||
unsigned c[288]; /* length list for huft_build */
|
||||
z_stream z; /* for falloc function */
|
||||
int f = FIXEDH; /* number of hufts left in fixed_mem */
|
||||
uInt f = 0; /* number of hufts used in fixed_mem */
|
||||
uIntf *c; /* length list for huft_build */
|
||||
uIntf *v; /* work area for huft_build */
|
||||
|
||||
/* set up fake z_stream for memory routines */
|
||||
z.zalloc = falloc;
|
||||
z.zfree = Z_NULL;
|
||||
z.opaque = (voidpf)&f;
|
||||
/* allocate memory */
|
||||
if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
|
||||
return Z_MEM_ERROR;
|
||||
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
|
||||
{
|
||||
ZFREE(z, c);
|
||||
return Z_MEM_ERROR;
|
||||
}
|
||||
|
||||
/* literal table */
|
||||
for (k = 0; k < 144; k++)
|
||||
@ -428,16 +427,19 @@ inflate_huft * FAR *td; /* distance tree result */
|
||||
for (; k < 288; k++)
|
||||
c[k] = 8;
|
||||
fixed_bl = 7;
|
||||
huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl, &z);
|
||||
huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl,
|
||||
fixed_mem, &f, v);
|
||||
|
||||
/* distance table */
|
||||
for (k = 0; k < 30; k++)
|
||||
c[k] = 5;
|
||||
fixed_bd = 5;
|
||||
huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd, &z);
|
||||
huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd,
|
||||
fixed_mem, &f, v);
|
||||
|
||||
/* done */
|
||||
Assert(f == 0, "invalid build of fixed tables");
|
||||
ZFREE(z, v);
|
||||
ZFREE(z, c);
|
||||
fixed_built = 1;
|
||||
}
|
||||
*bl = fixed_bl;
|
||||
@ -446,33 +448,3 @@ inflate_huft * FAR *td; /* distance tree result */
|
||||
*td = fixed_td;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
int inflate_trees_free(t, z)
|
||||
inflate_huft *t; /* table to free */
|
||||
z_streamp z; /* for zfree function */
|
||||
/* Free the malloc'ed tables built by huft_build(), which makes a linked
|
||||
list of the tables it made, with the links in a dummy first entry of
|
||||
each table. */
|
||||
{
|
||||
register inflate_huft *p, *q, *r;
|
||||
|
||||
/* Reverse linked list */
|
||||
p = Z_NULL;
|
||||
q = t;
|
||||
while (q != Z_NULL)
|
||||
{
|
||||
r = (q - 1)->next;
|
||||
(q - 1)->next = p;
|
||||
p = q;
|
||||
q = r;
|
||||
}
|
||||
/* Go through linked list, freeing from the malloced (t[-1]) address. */
|
||||
while (p != Z_NULL)
|
||||
{
|
||||
q = (--p)->next;
|
||||
ZFREE(z,p);
|
||||
p = q;
|
||||
}
|
||||
return Z_OK;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* inftrees.h -- header to use inftrees.c
|
||||
* Copyright (C) 1995-1996 Mark Adler
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@ -27,15 +27,19 @@ struct inflate_huft_s {
|
||||
} more;
|
||||
};
|
||||
|
||||
#ifdef DEBUG
|
||||
extern uInt inflate_hufts;
|
||||
#endif
|
||||
/* Maximum size of dynamic tree. The maximum found in a long but non-
|
||||
exhaustive search was 1041 huft structures (875 for length/literals
|
||||
and 166 for distances, the latter actually the result of an
|
||||
exhaustive search). The actual maximum is not known, but the
|
||||
value below is more than safe. */
|
||||
#define MANY 1440
|
||||
|
||||
extern int inflate_trees_bits OF((
|
||||
uIntf *, /* 19 code lengths */
|
||||
uIntf *, /* bits tree desired/actual depth */
|
||||
inflate_huft * FAR *, /* bits tree result */
|
||||
z_streamp )); /* for zalloc, zfree functions */
|
||||
inflate_huft *, /* space for trees */
|
||||
z_streamp)); /* for messages */
|
||||
|
||||
extern int inflate_trees_dynamic OF((
|
||||
uInt, /* number of literal/length codes */
|
||||
@ -45,15 +49,12 @@ extern int inflate_trees_dynamic OF((
|
||||
uIntf *, /* distance desired/actual bit depth */
|
||||
inflate_huft * FAR *, /* literal/length tree result */
|
||||
inflate_huft * FAR *, /* distance tree result */
|
||||
z_streamp )); /* for zalloc, zfree functions */
|
||||
inflate_huft *, /* space for trees */
|
||||
z_streamp)); /* for messages */
|
||||
|
||||
extern int inflate_trees_fixed OF((
|
||||
uIntf *, /* literal desired/actual bit depth */
|
||||
uIntf *, /* distance desired/actual bit depth */
|
||||
inflate_huft * FAR *, /* literal/length tree result */
|
||||
inflate_huft * FAR *)); /* distance tree result */
|
||||
|
||||
extern int inflate_trees_free OF((
|
||||
inflate_huft *, /* tables to free */
|
||||
z_streamp )); /* for zfree function */
|
||||
|
||||
inflate_huft * FAR *, /* distance tree result */
|
||||
z_streamp)); /* for memory allocation */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* inflate_util.c -- data and routines common to blocks and codes
|
||||
* Copyright (C) 1995-1996 Mark Adler
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* infutil.h -- types and macros common to blocks and codes
|
||||
* Copyright (C) 1995-1996 Mark Adler
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
@ -41,8 +41,6 @@ struct inflate_blocks_state {
|
||||
inflate_huft *tb; /* bit length decoding tree */
|
||||
} trees; /* if DTREE, decoding info for trees */
|
||||
struct {
|
||||
inflate_huft *tl;
|
||||
inflate_huft *td; /* trees to free */
|
||||
inflate_codes_statef
|
||||
*codes;
|
||||
} decode; /* if CODES, current state */
|
||||
@ -52,6 +50,7 @@ struct inflate_blocks_state {
|
||||
/* mode independent information */
|
||||
uInt bitk; /* bits in bit buffer */
|
||||
uLong bitb; /* bit buffer */
|
||||
inflate_huft *hufts; /* single malloc for tree space */
|
||||
Bytef *window; /* sliding window */
|
||||
Bytef *end; /* one byte after sliding window */
|
||||
Bytef *read; /* window read pointer */
|
||||
|
128
lib/libz/trees.h
Normal file
128
lib/libz/trees.h
Normal file
@ -0,0 +1,128 @@
|
||||
/* header created automatically with -DGEN_TREES_H */
|
||||
|
||||
local const ct_data static_ltree[L_CODES+2] = {
|
||||
{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
|
||||
{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
|
||||
{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
|
||||
{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
|
||||
{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
|
||||
{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
|
||||
{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
|
||||
{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
|
||||
{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
|
||||
{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
|
||||
{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
|
||||
{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
|
||||
{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
|
||||
{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
|
||||
{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
|
||||
{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
|
||||
{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
|
||||
{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
|
||||
{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
|
||||
{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
|
||||
{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
|
||||
{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
|
||||
{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
|
||||
{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
|
||||
{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
|
||||
{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
|
||||
{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
|
||||
{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
|
||||
{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
|
||||
{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
|
||||
{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
|
||||
{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
|
||||
{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
|
||||
{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
|
||||
{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
|
||||
{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
|
||||
{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
|
||||
{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
|
||||
{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
|
||||
{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
|
||||
{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
|
||||
{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
|
||||
{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
|
||||
{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
|
||||
{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
|
||||
{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
|
||||
{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
|
||||
{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
|
||||
{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
|
||||
{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
|
||||
{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
|
||||
{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
|
||||
{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
|
||||
{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
|
||||
{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
|
||||
{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
|
||||
{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
|
||||
{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
|
||||
};
|
||||
|
||||
local const ct_data static_dtree[D_CODES] = {
|
||||
{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
|
||||
{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
|
||||
{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
|
||||
{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
|
||||
{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
|
||||
{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
|
||||
};
|
||||
|
||||
const uch _dist_code[DIST_CODE_LEN] = {
|
||||
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
|
||||
18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
|
||||
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
|
||||
};
|
||||
|
||||
const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
|
||||
13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
||||
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
|
||||
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
|
||||
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
|
||||
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
|
||||
};
|
||||
|
||||
local const int base_length[LENGTH_CODES] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
|
||||
64, 80, 96, 112, 128, 160, 192, 224, 0
|
||||
};
|
||||
|
||||
local const int base_dist[D_CODES] = {
|
||||
0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
|
||||
32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
|
||||
1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
|
||||
};
|
||||
|
107
lib/libz/zlib.3
Normal file
107
lib/libz/zlib.3
Normal file
@ -0,0 +1,107 @@
|
||||
.TH ZLIB 3 "27 February 1998"
|
||||
.SH NAME
|
||||
zlib \- compression/decompression library
|
||||
.SH SYNOPSIS
|
||||
[see
|
||||
.I zlib.h
|
||||
for full description]
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.I zlib
|
||||
library is a general purpose data compression library.
|
||||
The code is thread safe.
|
||||
It provides in-memory compression and decompression functions,
|
||||
including integrity checks of the uncompressed data.
|
||||
This version of the library supports only one compression method (deflation)
|
||||
but other algorithms will be added later and will have the same stream interface.
|
||||
.LP
|
||||
Compression can be done in a single step if the buffers are large enough
|
||||
(for example if an input file is mmap'ed),
|
||||
or can be done by repeated calls of the compression function.
|
||||
In the latter case,
|
||||
the application must provide more input and/or consume the output
|
||||
(providing more output space) before each call.
|
||||
.LP
|
||||
The library also supports reading and writing files in
|
||||
.I gzip
|
||||
(.gz) format
|
||||
with an interface similar to that of stdio.
|
||||
.LP
|
||||
The library does not install any signal handler. The decoder checks
|
||||
the consistency of the compressed data, so the library should never
|
||||
crash even in case of corrupted input.
|
||||
.LP
|
||||
All functions of the compression library are documented in the file
|
||||
.IR zlib.h.
|
||||
The distribution source includes examples of use of the library
|
||||
the files
|
||||
.I example.c
|
||||
and
|
||||
.IR minigzip.c .
|
||||
.LP
|
||||
A Java implementation of
|
||||
.IR zlib
|
||||
is available in the Java Development Kit 1.1
|
||||
.IP
|
||||
http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html
|
||||
.LP
|
||||
A Perl interface to
|
||||
.IR zlib ,
|
||||
written by Paul Marquess (pmarquess@bfsec.bt.co.uk)
|
||||
is available at CPAN (Comprehensive Perl Archive Network) sites,
|
||||
such as:
|
||||
.IP
|
||||
ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib*
|
||||
.LP
|
||||
A Python interface to
|
||||
.IR zlib
|
||||
written by A.M. Kuchling <amk@magnet.com>
|
||||
is available from the Python Software Association sites, such as:
|
||||
.IP
|
||||
ftp://ftp.python.org/pub/python/contrib/Encoding/zlib*.tar.gz
|
||||
.SH "SEE ALSO"
|
||||
Questions about zlib should be sent to:
|
||||
.IP
|
||||
zlib@quest.jpl.nasa.gov
|
||||
or, if this fails, to the author addresses given below.
|
||||
The zlib home page is:
|
||||
.IP
|
||||
http://www.cdrom.com/pub/infozip/zlib/
|
||||
.LP
|
||||
The data format used by the zlib library is described by RFC
|
||||
(Request for Comments) 1950 to 1952 in the files:
|
||||
.IP
|
||||
ftp://ds.internic.net/rfc/rfc1950.txt (zlib format)
|
||||
.br
|
||||
rfc1951.txt (deflate format)
|
||||
.br
|
||||
rfc1952.txt (gzip format)
|
||||
.LP
|
||||
These documents are also available in other formats from:
|
||||
.IP
|
||||
ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
|
||||
.SH AUTHORS
|
||||
Version 1.1.1
|
||||
Copyright (C) 1995-1998 Jean-loup Gailly (jloup@gzip.org)
|
||||
and Mark Adler (madler@alumni.caltech.edu).
|
||||
.LP
|
||||
This software is provided "as-is,"
|
||||
without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
See the distribution directory with respect to requirements
|
||||
governing redistribution.
|
||||
The deflate format used by
|
||||
.I zlib
|
||||
was defined by Phil Katz.
|
||||
The deflate and
|
||||
.I zlib
|
||||
specifications were written by Peter Deutsch.
|
||||
Thanks to all the people who reported problems and suggested various
|
||||
improvements in
|
||||
.IR zlib ;
|
||||
who are too numerous to cite here.
|
||||
.LP
|
||||
UNIX manual page by R. P. C. Rodgers,
|
||||
U.S. National Library of Medicine (rodgers@nlm.nih.gov).
|
||||
.\" end of man page
|
498
lib/libz/zlib.h
498
lib/libz/zlib.h
@ -1,7 +1,7 @@
|
||||
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
||||
version 1.0.4, Jul 24th, 1996.
|
||||
version 1.1.1, Feb 27th, 1998
|
||||
|
||||
Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler
|
||||
Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@ -20,7 +20,7 @@
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Jean-loup Gailly Mark Adler
|
||||
gzip@prep.ai.mit.edu madler@alumni.caltech.edu
|
||||
jloup@gzip.org madler@alumni.caltech.edu
|
||||
|
||||
|
||||
The data format used by the zlib library is described by RFCs (Request for
|
||||
@ -37,30 +37,27 @@ extern "C" {
|
||||
|
||||
#include "zconf.h"
|
||||
|
||||
#define ZLIB_VERSION "1.0.4"
|
||||
#define ZLIB_VERSION "1.1.1"
|
||||
|
||||
/*
|
||||
The 'zlib' compression library provides in-memory compression and
|
||||
decompression functions, including integrity checks of the uncompressed
|
||||
data. This version of the library supports only one compression method
|
||||
(deflation) but other algorithms may be added later and will have the same
|
||||
(deflation) but other algorithms will be added later and will have the same
|
||||
stream interface.
|
||||
|
||||
For compression the application must provide the output buffer and
|
||||
may optionally provide the input buffer for optimization. For decompression,
|
||||
the application must provide the input buffer and may optionally provide
|
||||
the output buffer for optimization.
|
||||
|
||||
Compression can be done in a single step if the buffers are large
|
||||
enough (for example if an input file is mmap'ed), or can be done by
|
||||
repeated calls of the compression function. In the latter case, the
|
||||
application must provide more input and/or consume the output
|
||||
(providing more output space) before each call.
|
||||
|
||||
The library does not install any signal handler. It is recommended to
|
||||
add at least a handler for SIGSEGV when decompressing; the library checks
|
||||
the consistency of the input data whenever possible but may go nuts
|
||||
for some forms of corrupted input.
|
||||
The library also supports reading and writing files in gzip (.gz) format
|
||||
with an interface similar to that of stdio.
|
||||
|
||||
The library does not install any signal handler. The decoder checks
|
||||
the consistency of the compressed data, so the library should never
|
||||
crash even in case of corrupted input.
|
||||
*/
|
||||
|
||||
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
|
||||
@ -104,6 +101,9 @@ typedef z_stream FAR *z_streamp;
|
||||
opaque value.
|
||||
|
||||
zalloc must return Z_NULL if there is not enough memory for the object.
|
||||
If zlib is used in a multi-threaded application, zalloc and zfree must be
|
||||
thread safe.
|
||||
|
||||
On 16-bit systems, the functions zalloc and zfree must be able to allocate
|
||||
exactly 65536 bytes, but will not be required to allocate more than this
|
||||
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
|
||||
@ -123,7 +123,7 @@ typedef z_stream FAR *z_streamp;
|
||||
/* constants */
|
||||
|
||||
#define Z_NO_FLUSH 0
|
||||
#define Z_PARTIAL_FLUSH 1
|
||||
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
|
||||
#define Z_SYNC_FLUSH 2
|
||||
#define Z_FULL_FLUSH 3
|
||||
#define Z_FINISH 4
|
||||
@ -168,7 +168,7 @@ typedef z_stream FAR *z_streamp;
|
||||
|
||||
/* basic functions */
|
||||
|
||||
extern const char * EXPORT zlibVersion OF((void));
|
||||
extern const char * ZEXPORT zlibVersion OF((void));
|
||||
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
|
||||
If the first character differs, the library code actually used is
|
||||
not compatible with the zlib.h header file used by the application.
|
||||
@ -176,7 +176,7 @@ extern const char * EXPORT zlibVersion OF((void));
|
||||
*/
|
||||
|
||||
/*
|
||||
extern int EXPORT deflateInit OF((z_streamp strm, int level));
|
||||
extern int ZEXPORT deflateInit OF((z_streamp strm, int level));
|
||||
|
||||
Initializes the internal stream state for compression. The fields
|
||||
zalloc, zfree and opaque must be initialized before by the caller.
|
||||
@ -198,9 +198,15 @@ extern int EXPORT deflateInit OF((z_streamp strm, int level));
|
||||
*/
|
||||
|
||||
|
||||
extern int EXPORT deflate OF((z_streamp strm, int flush));
|
||||
extern int ZEXPORT deflate OF((z_streamp strm, int flush));
|
||||
/*
|
||||
Performs one or both of the following actions:
|
||||
deflate compresses as much data as possible, and stops when the input
|
||||
buffer becomes empty or the output buffer becomes full. It may introduce some
|
||||
output latency (reading input without producing any output) except when
|
||||
forced to flush.
|
||||
|
||||
The detailed semantics are as follows. deflate performs one or both of the
|
||||
following actions:
|
||||
|
||||
- Compress more input starting at next_in and update next_in and avail_in
|
||||
accordingly. If not all input can be processed (because there is not
|
||||
@ -222,24 +228,23 @@ extern int EXPORT deflate OF((z_streamp strm, int flush));
|
||||
and with zero avail_out, it must be called again after making room in the
|
||||
output buffer because there might be more output pending.
|
||||
|
||||
If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
|
||||
block is terminated and flushed to the output buffer so that the
|
||||
decompressor can get all input data available so far. For method 9, a future
|
||||
variant on method 8, the current block will be flushed but not terminated.
|
||||
Z_SYNC_FLUSH has the same effect as partial flush except that the compressed
|
||||
output is byte aligned (the compressor can clear its internal bit buffer)
|
||||
and the current block is always terminated; this can be useful if the
|
||||
compressor has to be restarted from scratch after an interruption (in which
|
||||
case the internal state of the compressor may be lost).
|
||||
If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
|
||||
special marker is output and the compression dictionary is discarded; this
|
||||
is useful to allow the decompressor to synchronize if one compressed block
|
||||
has been damaged (see inflateSync below). Flushing degrades compression and
|
||||
so should be used only when necessary. Using Z_FULL_FLUSH too often can
|
||||
seriously degrade the compression. If deflate returns with avail_out == 0,
|
||||
this function must be called again with the same value of the flush
|
||||
parameter and more output space (updated avail_out), until the flush is
|
||||
complete (deflate returns with non-zero avail_out).
|
||||
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
|
||||
flushed to the output buffer and the output is aligned on a byte boundary, so
|
||||
that the decompressor can get all input data available so far. (In particular
|
||||
avail_in is zero after the call if enough output space has been provided
|
||||
before the call.) Flushing may degrade compression for some compression
|
||||
algorithms and so it should be used only when necessary.
|
||||
|
||||
If flush is set to Z_FULL_FLUSH, all output is flushed as with
|
||||
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
|
||||
restart from this point if previous compressed data has been damaged or if
|
||||
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
|
||||
the compression.
|
||||
|
||||
If deflate returns with avail_out == 0, this function must be called again
|
||||
with the same value of the flush parameter and more output space (updated
|
||||
avail_out), until the flush is complete (deflate returns with non-zero
|
||||
avail_out).
|
||||
|
||||
If the parameter flush is set to Z_FINISH, pending input is processed,
|
||||
pending output is flushed and deflate returns with Z_STREAM_END if there
|
||||
@ -254,6 +259,9 @@ extern int EXPORT deflate OF((z_streamp strm, int flush));
|
||||
0.1% larger than avail_in plus 12 bytes. If deflate does not return
|
||||
Z_STREAM_END, then it must be called again as described above.
|
||||
|
||||
deflate() sets strm->adler to the adler32 checksum of all input read
|
||||
so far (that is, total_in bytes).
|
||||
|
||||
deflate() may update data_type if it can make a good guess about
|
||||
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
|
||||
binary. This field is only for information purposes and does not affect
|
||||
@ -267,7 +275,7 @@ extern int EXPORT deflate OF((z_streamp strm, int flush));
|
||||
*/
|
||||
|
||||
|
||||
extern int EXPORT deflateEnd OF((z_streamp strm));
|
||||
extern int ZEXPORT deflateEnd OF((z_streamp strm));
|
||||
/*
|
||||
All dynamically allocated data structures for this stream are freed.
|
||||
This function discards any unprocessed input and does not flush any
|
||||
@ -282,24 +290,35 @@ extern int EXPORT deflateEnd OF((z_streamp strm));
|
||||
|
||||
|
||||
/*
|
||||
extern int EXPORT inflateInit OF((z_streamp strm));
|
||||
extern int ZEXPORT inflateInit OF((z_streamp strm));
|
||||
|
||||
Initializes the internal stream state for decompression. The fields
|
||||
zalloc, zfree and opaque must be initialized before by the caller. If
|
||||
zalloc and zfree are set to Z_NULL, inflateInit updates them to use default
|
||||
allocation functions.
|
||||
next_in, avail_in, zalloc, zfree and opaque must be initialized before by
|
||||
the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
|
||||
value depends on the compression method), inflateInit determines the
|
||||
compression method from the zlib header and allocates all data structures
|
||||
accordingly; otherwise the allocation will be deferred to the first call of
|
||||
inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
|
||||
use default allocation functions.
|
||||
|
||||
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_VERSION_ERROR if the zlib library version is incompatible
|
||||
with the version assumed by the caller. msg is set to null if there is no
|
||||
error message. inflateInit does not perform any decompression: this will be
|
||||
done by inflate().
|
||||
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
|
||||
version assumed by the caller. msg is set to null if there is no error
|
||||
message. inflateInit does not perform any decompression apart from reading
|
||||
the zlib header if present: this will be done by inflate(). (So next_in and
|
||||
avail_in may be modified, but next_out and avail_out are unchanged.)
|
||||
*/
|
||||
|
||||
|
||||
extern int EXPORT inflate OF((z_streamp strm, int flush));
|
||||
extern int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||
/*
|
||||
Performs one or both of the following actions:
|
||||
inflate decompresses as much data as possible, and stops when the input
|
||||
buffer becomes empty or the output buffer becomes full. It may some
|
||||
introduce some output latency (reading input without producing any output)
|
||||
except when forced to flush.
|
||||
|
||||
The detailed semantics are as follows. inflate performs one or both of the
|
||||
following actions:
|
||||
|
||||
- Decompress more input starting at next_in and update next_in and avail_in
|
||||
accordingly. If not all input can be processed (because there is not
|
||||
@ -320,9 +339,9 @@ extern int EXPORT inflate OF((z_streamp strm, int flush));
|
||||
must be called again after making room in the output buffer because there
|
||||
might be more output pending.
|
||||
|
||||
If the parameter flush is set to Z_PARTIAL_FLUSH, inflate flushes as much
|
||||
If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
|
||||
output as possible to the output buffer. The flushing behavior of inflate is
|
||||
not specified for values of the flush parameter other than Z_PARTIAL_FLUSH
|
||||
not specified for values of the flush parameter other than Z_SYNC_FLUSH
|
||||
and Z_FINISH, but the current implementation actually flushes as much output
|
||||
as possible anyway.
|
||||
|
||||
@ -337,22 +356,30 @@ extern int EXPORT inflate OF((z_streamp strm, int flush));
|
||||
is never required, but can be used to inform inflate that a faster routine
|
||||
may be used for the single inflate() call.
|
||||
|
||||
inflate() returns Z_OK if some progress has been made (more input
|
||||
processed or more output produced), Z_STREAM_END if the end of the
|
||||
compressed data has been reached and all uncompressed output has been
|
||||
produced, Z_NEED_DICT if a preset dictionary is needed at this point (see
|
||||
inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted,
|
||||
Z_STREAM_ERROR if the stream structure was inconsistent (for example if
|
||||
next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
|
||||
Z_BUF_ERROR if no progress is possible or if there was not enough room in
|
||||
the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the
|
||||
application may then call inflateSync to look for a good compression block.
|
||||
In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the
|
||||
dictionary chosen by the compressor.
|
||||
If a preset dictionary is needed at this point (see inflateSetDictionary
|
||||
below), inflate sets strm-adler to the adler32 checksum of the
|
||||
dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
|
||||
it sets strm->adler to the adler32 checksum of all output produced
|
||||
so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
|
||||
an error code as described below. At the end of the stream, inflate()
|
||||
checks that its computed adler32 checksum is equal to that saved by the
|
||||
compressor and returns Z_STREAM_END only if the checksum is correct.
|
||||
|
||||
inflate() returns Z_OK if some progress has been made (more input processed
|
||||
or more output produced), Z_STREAM_END if the end of the compressed data has
|
||||
been reached and all uncompressed output has been produced, Z_NEED_DICT if a
|
||||
preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
|
||||
corrupted (input stream not conforming to the zlib format or incorrect
|
||||
adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
|
||||
(for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if no progress is possible or if there was not
|
||||
enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
|
||||
case, the application may then call inflateSync to look for a good
|
||||
compression block.
|
||||
*/
|
||||
|
||||
|
||||
extern int EXPORT inflateEnd OF((z_streamp strm));
|
||||
extern int ZEXPORT inflateEnd OF((z_streamp strm));
|
||||
/*
|
||||
All dynamically allocated data structures for this stream are freed.
|
||||
This function discards any unprocessed input and does not flush any
|
||||
@ -370,26 +397,25 @@ extern int EXPORT inflateEnd OF((z_streamp strm));
|
||||
*/
|
||||
|
||||
/*
|
||||
extern int EXPORT deflateInit2 OF((z_streamp strm,
|
||||
int level,
|
||||
int method,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy));
|
||||
extern int ZEXPORT deflateInit2 OF((z_streamp strm,
|
||||
int level,
|
||||
int method,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy));
|
||||
|
||||
This is another version of deflateInit with more compression options. The
|
||||
fields next_in, zalloc, zfree and opaque must be initialized before by
|
||||
the caller.
|
||||
|
||||
The method parameter is the compression method. It must be Z_DEFLATED in
|
||||
this version of the library. (Method 9 will allow a 64K history buffer and
|
||||
partial block flushes.)
|
||||
this version of the library.
|
||||
|
||||
The windowBits parameter is the base two logarithm of the window size
|
||||
(the size of the history buffer). It should be in the range 8..15 for this
|
||||
version of the library (the value 16 will be allowed for method 9). Larger
|
||||
values of this parameter result in better compression at the expense of
|
||||
memory usage. The default value is 15 if deflateInit is used instead.
|
||||
version of the library. Larger values of this parameter result in better
|
||||
compression at the expense of memory usage. The default value is 15 if
|
||||
deflateInit is used instead.
|
||||
|
||||
The memLevel parameter specifies how much memory should be allocated
|
||||
for the internal compression state. memLevel=1 uses minimum memory but
|
||||
@ -408,42 +434,35 @@ extern int EXPORT deflateInit2 OF((z_streamp strm,
|
||||
the compression ratio but not the correctness of the compressed output even
|
||||
if it is not set appropriately.
|
||||
|
||||
If next_in is not null, the library will use this buffer to hold also
|
||||
some history information; the buffer must either hold the entire input
|
||||
data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
|
||||
is null, the library will allocate its own history buffer (and leave next_in
|
||||
null). next_out need not be provided here but must be provided by the
|
||||
application for the next call of deflate().
|
||||
|
||||
If the history buffer is provided by the application, next_in must
|
||||
must never be changed by the application since the compressor maintains
|
||||
information inside this buffer from call to call; the application
|
||||
must provide more input only by increasing avail_in. next_in is always
|
||||
reset by the library in this case.
|
||||
|
||||
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
|
||||
not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
|
||||
an invalid method). msg is set to null if there is no error message.
|
||||
deflateInit2 does not perform any compression: this will be done by
|
||||
deflate().
|
||||
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
|
||||
method). msg is set to null if there is no error message. deflateInit2 does
|
||||
not perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
extern int EXPORT deflateSetDictionary OF((z_streamp strm,
|
||||
const Bytef *dictionary,
|
||||
uInt dictLength));
|
||||
extern int ZEXPORT deflateSetDictionary OF((z_streamp strm,
|
||||
const Bytef *dictionary,
|
||||
uInt dictLength));
|
||||
/*
|
||||
Initializes the compression dictionary (history buffer) from the given
|
||||
byte sequence without producing any compressed output. This function must
|
||||
be called immediately after deflateInit or deflateInit2, before any call
|
||||
of deflate. The compressor and decompressor must use exactly the same
|
||||
Initializes the compression dictionary from the given byte sequence
|
||||
without producing any compressed output. This function must be called
|
||||
immediately after deflateInit or deflateInit2, before any call of
|
||||
deflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see inflateSetDictionary).
|
||||
|
||||
The dictionary should consist of strings (byte sequences) that are likely
|
||||
to be encountered later in the data to be compressed, with the most commonly
|
||||
used strings preferably put towards the end of the dictionary. Using a
|
||||
dictionary is most useful when the data to be compressed is short and
|
||||
can be predicted with good accuracy; the data can then be compressed better
|
||||
than with the default empty dictionary. In this version of the library,
|
||||
only the last 32K bytes of the dictionary are used.
|
||||
dictionary is most useful when the data to be compressed is short and can be
|
||||
predicted with good accuracy; the data can then be compressed better than
|
||||
with the default empty dictionary.
|
||||
|
||||
Depending on the size of the compression data structures selected by
|
||||
deflateInit or deflateInit2, a part of the dictionary may in effect be
|
||||
discarded, for example if the dictionary is larger than the window size in
|
||||
deflate or deflate2. Thus the strings most likely to be useful should be
|
||||
put at the end of the dictionary, not at the front.
|
||||
|
||||
Upon return of this function, strm->adler is set to the Adler32 value
|
||||
of the dictionary; the decompressor may later use this value to determine
|
||||
which dictionary has been used by the compressor. (The Adler32 value
|
||||
@ -451,21 +470,16 @@ extern int EXPORT deflateSetDictionary OF((z_streamp strm,
|
||||
actually used by the compressor.)
|
||||
|
||||
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
|
||||
parameter is invalid (such as NULL dictionary) or the stream state
|
||||
is inconsistent (for example if deflate has already been called for this
|
||||
stream). deflateSetDictionary does not perform any compression: this will
|
||||
be done by deflate().
|
||||
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||
inconsistent (for example if deflate has already been called for this stream
|
||||
or if the compression method is bsort). deflateSetDictionary does not
|
||||
perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
extern int EXPORT deflateCopy OF((z_streamp dest,
|
||||
z_streamp source));
|
||||
extern int ZEXPORT deflateCopy OF((z_streamp dest,
|
||||
z_streamp source));
|
||||
/*
|
||||
Sets the destination stream as a complete copy of the source stream. If
|
||||
the source stream is using an application-supplied history buffer, a new
|
||||
buffer is allocated for the destination stream. The compressed output
|
||||
buffer is always application-supplied. It's the responsibility of the
|
||||
application to provide the correct values of next_out and avail_out for the
|
||||
next call of deflate.
|
||||
Sets the destination stream as a complete copy of the source stream.
|
||||
|
||||
This function can be useful when several compression strategies will be
|
||||
tried, for example when there are several ways of pre-processing the input
|
||||
@ -480,7 +494,7 @@ extern int EXPORT deflateCopy OF((z_streamp dest,
|
||||
destination.
|
||||
*/
|
||||
|
||||
extern int EXPORT deflateReset OF((z_streamp strm));
|
||||
extern int ZEXPORT deflateReset OF((z_streamp strm));
|
||||
/*
|
||||
This function is equivalent to deflateEnd followed by deflateInit,
|
||||
but does not free and reallocate all the internal compression state.
|
||||
@ -491,14 +505,15 @@ extern int EXPORT deflateReset OF((z_streamp strm));
|
||||
stream state was inconsistent (such as zalloc or state being NULL).
|
||||
*/
|
||||
|
||||
extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy));
|
||||
extern int ZEXPORT deflateParams OF((z_streamp strm, int level, int strategy));
|
||||
/*
|
||||
Dynamically update the compression level and compression strategy.
|
||||
This can be used to switch between compression and straight copy of
|
||||
the input data, or to switch to a different kind of input data requiring
|
||||
a different strategy. If the compression level is changed, the input
|
||||
available so far is compressed with the old level (and may be flushed);
|
||||
the new level will take effect only at the next call of deflate().
|
||||
Dynamically update the compression level and compression strategy. The
|
||||
interpretation of level and strategy is as in deflateInit2. This can be
|
||||
used to switch between compression and straight copy of the input data, or
|
||||
to switch to a different kind of input data requiring a different
|
||||
strategy. If the compression level is changed, the input available so far
|
||||
is compressed with the old level (and may be flushed); the new level will
|
||||
take effect only at the next call of deflate().
|
||||
|
||||
Before the call of deflateParams, the stream state must be set as for
|
||||
a call of deflate(), since the currently available input may have to
|
||||
@ -510,49 +525,37 @@ extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy));
|
||||
*/
|
||||
|
||||
/*
|
||||
extern int EXPORT inflateInit2 OF((z_streamp strm,
|
||||
int windowBits));
|
||||
extern int ZEXPORT inflateInit2 OF((z_streamp strm,
|
||||
int windowBits));
|
||||
|
||||
This is another version of inflateInit with more compression options. The
|
||||
fields next_out, zalloc, zfree and opaque must be initialized before by
|
||||
the caller.
|
||||
This is another version of inflateInit with an extra parameter. The
|
||||
fields next_in, avail_in, zalloc, zfree and opaque must be initialized
|
||||
before by the caller.
|
||||
|
||||
The windowBits parameter is the base two logarithm of the maximum window
|
||||
size (the size of the history buffer). It should be in the range 8..15 for
|
||||
this version of the library (the value 16 will be allowed soon). The
|
||||
default value is 15 if inflateInit is used instead. If a compressed stream
|
||||
with a larger window size is given as input, inflate() will return with
|
||||
the error code Z_DATA_ERROR instead of trying to allocate a larger window.
|
||||
this version of the library. The default value is 15 if inflateInit is used
|
||||
instead. If a compressed stream with a larger window size is given as
|
||||
input, inflate() will return with the error code Z_DATA_ERROR instead of
|
||||
trying to allocate a larger window.
|
||||
|
||||
If next_out is not null, the library will use this buffer for the history
|
||||
buffer; the buffer must either be large enough to hold the entire output
|
||||
data, or have at least 1<<windowBits bytes. If next_out is null, the
|
||||
library will allocate its own buffer (and leave next_out null). next_in
|
||||
need not be provided here but must be provided by the application for the
|
||||
next call of inflate().
|
||||
|
||||
If the history buffer is provided by the application, next_out must
|
||||
never be changed by the application since the decompressor maintains
|
||||
history information inside this buffer from call to call; the application
|
||||
can only reset next_out to the beginning of the history buffer when
|
||||
avail_out is zero and all output has been consumed.
|
||||
|
||||
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
|
||||
not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
|
||||
windowBits < 8). msg is set to null if there is no error message.
|
||||
inflateInit2 does not perform any decompression: this will be done by
|
||||
inflate().
|
||||
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
|
||||
memLevel). msg is set to null if there is no error message. inflateInit2
|
||||
does not perform any decompression apart from reading the zlib header if
|
||||
present: this will be done by inflate(). (So next_in and avail_in may be
|
||||
modified, but next_out and avail_out are unchanged.)
|
||||
*/
|
||||
|
||||
extern int EXPORT inflateSetDictionary OF((z_streamp strm,
|
||||
const Bytef *dictionary,
|
||||
uInt dictLength));
|
||||
extern int ZEXPORT inflateSetDictionary OF((z_streamp strm,
|
||||
const Bytef *dictionary,
|
||||
uInt dictLength));
|
||||
/*
|
||||
Initializes the decompression dictionary (history buffer) from the given
|
||||
uncompressed byte sequence. This function must be called immediately after
|
||||
a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen
|
||||
by the compressor can be determined from the Adler32 value returned by this
|
||||
call of inflate. The compressor and decompressor must use exactly the same
|
||||
Initializes the decompression dictionary from the given uncompressed byte
|
||||
sequence. This function must be called immediately after a call of inflate
|
||||
if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
|
||||
can be determined from the Adler32 value returned by this call of
|
||||
inflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see deflateSetDictionary).
|
||||
|
||||
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
||||
@ -563,14 +566,14 @@ extern int EXPORT inflateSetDictionary OF((z_streamp strm,
|
||||
inflate().
|
||||
*/
|
||||
|
||||
extern int EXPORT inflateSync OF((z_streamp strm));
|
||||
extern int ZEXPORT inflateSync OF((z_streamp strm));
|
||||
/*
|
||||
Skips invalid compressed data until the special marker (see deflate()
|
||||
above) can be found, or until all available input is skipped. No output
|
||||
is provided.
|
||||
Skips invalid compressed data until a full flush point (see above the
|
||||
description of deflate with Z_FULL_FLUSH) can be found, or until all
|
||||
available input is skipped. No output is provided.
|
||||
|
||||
inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
|
||||
if no more input was provided, Z_DATA_ERROR if no marker has been found,
|
||||
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
|
||||
if no more input was provided, Z_DATA_ERROR if no flush point has been found,
|
||||
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
|
||||
case, the application may save the current current value of total_in which
|
||||
indicates where valid compressed data was found. In the error case, the
|
||||
@ -578,7 +581,7 @@ extern int EXPORT inflateSync OF((z_streamp strm));
|
||||
until success or end of the input data.
|
||||
*/
|
||||
|
||||
extern int EXPORT inflateReset OF((z_streamp strm));
|
||||
extern int ZEXPORT inflateReset OF((z_streamp strm));
|
||||
/*
|
||||
This function is equivalent to inflateEnd followed by inflateInit,
|
||||
but does not free and reallocate all the internal decompression state.
|
||||
@ -594,13 +597,13 @@ extern int EXPORT inflateReset OF((z_streamp strm));
|
||||
/*
|
||||
The following utility functions are implemented on top of the
|
||||
basic stream-oriented functions. To simplify the interface, some
|
||||
default options are assumed (compression level, window size,
|
||||
default options are assumed (compression level and memory usage,
|
||||
standard memory allocation functions). The source code of these
|
||||
utility functions can easily be modified if you need special options.
|
||||
*/
|
||||
|
||||
extern int EXPORT compress OF((Bytef *dest, uLongf *destLen,
|
||||
const Bytef *source, uLong sourceLen));
|
||||
extern int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
|
||||
const Bytef *source, uLong sourceLen));
|
||||
/*
|
||||
Compresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
@ -614,8 +617,23 @@ extern int EXPORT compress OF((Bytef *dest, uLongf *destLen,
|
||||
buffer.
|
||||
*/
|
||||
|
||||
extern int EXPORT uncompress OF((Bytef *dest, uLongf *destLen,
|
||||
const Bytef *source, uLong sourceLen));
|
||||
extern int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
|
||||
const Bytef *source, uLong sourceLen,
|
||||
int level));
|
||||
/*
|
||||
Compresses the source buffer into the destination buffer. The level
|
||||
parameter has the same meaning as in deflateInit. sourceLen is the byte
|
||||
length of the source buffer. Upon entry, destLen is the total size of the
|
||||
destination buffer, which must be at least 0.1% larger than sourceLen plus
|
||||
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
|
||||
|
||||
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
||||
Z_STREAM_ERROR if the level parameter is invalid.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
|
||||
const Bytef *source, uLong sourceLen));
|
||||
/*
|
||||
Decompresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
@ -635,19 +653,23 @@ extern int EXPORT uncompress OF((Bytef *dest, uLongf *destLen,
|
||||
|
||||
typedef voidp gzFile;
|
||||
|
||||
extern gzFile EXPORT gzopen OF((const char *path, const char *mode));
|
||||
extern gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
|
||||
/*
|
||||
Opens a gzip (.gz) file for reading or writing. The mode parameter
|
||||
is as in fopen ("rb" or "wb") but can also include a compression level
|
||||
("wb9"). gzopen can be used to read a file which is not in gzip format;
|
||||
in this case gzread will directly read from the file without decompression.
|
||||
("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
|
||||
Huffman only compression as in "wb1h". (See the description
|
||||
of deflateInit2 for more information about the strategy parameter.)
|
||||
|
||||
gzopen can be used to read a file which is not in gzip format; in this
|
||||
case gzread will directly read from the file without decompression.
|
||||
|
||||
gzopen returns NULL if the file could not be opened or if there was
|
||||
insufficient memory to allocate the (de)compression state; errno
|
||||
can be checked to distinguish the two cases (if errno is zero, the
|
||||
zlib error is Z_MEM_ERROR).
|
||||
*/
|
||||
zlib error is Z_MEM_ERROR). */
|
||||
|
||||
extern gzFile EXPORT gzdopen OF((int fd, const char *mode));
|
||||
extern gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
|
||||
/*
|
||||
gzdopen() associates a gzFile with the file descriptor fd. File
|
||||
descriptors are obtained from calls like open, dup, creat, pipe or
|
||||
@ -660,7 +682,15 @@ extern gzFile EXPORT gzdopen OF((int fd, const char *mode));
|
||||
the (de)compression state.
|
||||
*/
|
||||
|
||||
extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len));
|
||||
extern int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
|
||||
/*
|
||||
Dynamically update the compression level or strategy. See the description
|
||||
of deflateInit2 for the meaning of these parameters.
|
||||
gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
|
||||
opened for writing.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
|
||||
/*
|
||||
Reads the given number of uncompressed bytes from the compressed file.
|
||||
If the input file was not in gzip format, gzread copies the given number
|
||||
@ -668,14 +698,49 @@ extern int EXPORT gzread OF((gzFile file, voidp buf, unsigned len));
|
||||
gzread returns the number of uncompressed bytes actually read (0 for
|
||||
end of file, -1 for error). */
|
||||
|
||||
extern int EXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len));
|
||||
extern int ZEXPORT gzwrite OF((gzFile file, const voidp buf, unsigned len));
|
||||
/*
|
||||
Writes the given number of uncompressed bytes into the compressed file.
|
||||
gzwrite returns the number of uncompressed bytes actually written
|
||||
(0 in case of error).
|
||||
*/
|
||||
|
||||
extern int EXPORT gzflush OF((gzFile file, int flush));
|
||||
extern int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
|
||||
/*
|
||||
Converts, formats, and writes the args to the compressed file under
|
||||
control of the format string, as in fprintf. gzprintf returns the number of
|
||||
uncompressed bytes actually written (0 in case of error).
|
||||
*/
|
||||
|
||||
extern int ZEXPORT gzputs OF((gzFile file, const char *s));
|
||||
/*
|
||||
Writes the given null-terminated string to the compressed file, excluding
|
||||
the terminating null character.
|
||||
gzputs returns the number of characters written, or -1 in case of error.
|
||||
*/
|
||||
|
||||
extern char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
|
||||
/*
|
||||
Reads bytes from the compressed file until len-1 characters are read, or
|
||||
a newline character is read and transferred to buf, or an end-of-file
|
||||
condition is encountered. The string is then terminated with a null
|
||||
character.
|
||||
gzgets returns buf, or Z_NULL in case of error.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT gzputc OF((gzFile file, int c));
|
||||
/*
|
||||
Writes c, converted to an unsigned char, into the compressed file.
|
||||
gzputc returns the value that was written, or -1 in case of error.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT gzgetc OF((gzFile file));
|
||||
/*
|
||||
Reads one byte from the compressed file. gzgetc returns this byte
|
||||
or -1 in case of end of file or error.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT gzflush OF((gzFile file, int flush));
|
||||
/*
|
||||
Flushes all pending output into the compressed file. The parameter
|
||||
flush is as in the deflate() function. The return value is the zlib
|
||||
@ -685,14 +750,53 @@ extern int EXPORT gzflush OF((gzFile file, int flush));
|
||||
degrade compression.
|
||||
*/
|
||||
|
||||
extern int EXPORT gzclose OF((gzFile file));
|
||||
extern z_off_t ZEXPORT gzseek OF((gzFile file, z_off_t offset, int whence));
|
||||
/*
|
||||
Sets the starting position for the next gzread or gzwrite on the given
|
||||
compressed file. The offset represents a number of bytes in the
|
||||
uncompressed data stream. The whence parameter is defined as in lseek(2);
|
||||
the value SEEK_END is not supported.
|
||||
If the file is opened for reading, this function is emulated but can be
|
||||
extremely slow. If the file is opened for writing, only forward seeks are
|
||||
supported; gzseek then compresses a sequence of zeroes up to the new
|
||||
starting position.
|
||||
|
||||
gzseek returns the resulting offset location as measured in bytes from
|
||||
the beginning of the uncompressed stream, or -1 in case of error, in
|
||||
particular if the file is opened for writing and the new starting position
|
||||
would be before the current position.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT gzrewind OF((gzFile file));
|
||||
/*
|
||||
Rewinds the given file. This function is supported only for reading.
|
||||
|
||||
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
|
||||
*/
|
||||
|
||||
extern z_off_t ZEXPORT gztell OF((gzFile file));
|
||||
/*
|
||||
Returns the starting position for the next gzread or gzwrite on the
|
||||
given compressed file. This position represents a number of bytes in the
|
||||
uncompressed data stream.
|
||||
|
||||
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT gzeof OF((gzFile file));
|
||||
/*
|
||||
Returns 1 when EOF has previously been detected reading the given
|
||||
input stream, otherwise zero.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT gzclose OF((gzFile file));
|
||||
/*
|
||||
Flushes all pending output if necessary, closes the compressed file
|
||||
and deallocates all the (de)compression state. The return value is the zlib
|
||||
error number (see function gzerror below).
|
||||
*/
|
||||
|
||||
extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
|
||||
extern const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
|
||||
/*
|
||||
Returns the error message for the last error which occurred on the
|
||||
given compressed file. errnum is set to zlib error number. If an
|
||||
@ -709,7 +813,7 @@ extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
|
||||
compression library.
|
||||
*/
|
||||
|
||||
extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||
extern uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||
|
||||
/*
|
||||
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
|
||||
@ -726,7 +830,7 @@ extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||
if (adler != original_adler) error();
|
||||
*/
|
||||
|
||||
extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||
extern uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||
/*
|
||||
Update a running crc with the bytes buf[0..len-1] and return the updated
|
||||
crc. If buf is NULL, this function returns the required initial value
|
||||
@ -748,30 +852,34 @@ extern uLong EXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
|
||||
/* deflateInit and inflateInit are macros to allow checking the zlib version
|
||||
* and the compiler's view of z_stream:
|
||||
*/
|
||||
extern int EXPORT deflateInit_ OF((z_streamp strm, int level,
|
||||
const char *version, int stream_size));
|
||||
extern int EXPORT inflateInit_ OF((z_streamp strm,
|
||||
const char *version, int stream_size));
|
||||
extern int EXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
|
||||
int windowBits, int memLevel, int strategy,
|
||||
const char *version, int stream_size));
|
||||
extern int EXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
|
||||
const char *version, int stream_size));
|
||||
extern int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
|
||||
const char *version, int stream_size));
|
||||
extern int ZEXPORT inflateInit_ OF((z_streamp strm,
|
||||
const char *version, int stream_size));
|
||||
extern int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
|
||||
int windowBits, int memLevel,
|
||||
int strategy, const char *version,
|
||||
int stream_size));
|
||||
extern int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
|
||||
const char *version, int stream_size));
|
||||
#define deflateInit(strm, level) \
|
||||
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define inflateInit(strm) \
|
||||
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
|
||||
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
|
||||
(strategy), ZLIB_VERSION, sizeof(z_stream))
|
||||
(strategy), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define inflateInit2(strm, windowBits) \
|
||||
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
|
||||
|
||||
|
||||
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
|
||||
struct internal_state {int dummy;}; /* hack for buggy compilers */
|
||||
#endif
|
||||
|
||||
uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */
|
||||
extern const char * ZEXPORT zError OF((int err));
|
||||
extern int ZEXPORT inflateSyncPoint OF((z_streamp z));
|
||||
extern const uLongf * ZEXPORT get_crc_table OF((void));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user