Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / html / python / lib / module-zlib.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-gzip.html" />
<link rel="prev" href="module-dumbdbm.html" />
<link rel="parent" href="someos.html" />
<link rel="next" href="module-gzip.html" />
<meta name='aesop' content='information' />
<title>7.15 zlib -- Compression compatible with gzip</title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="7.14.1 Dumbdbm Objects"
href="dumbdbm-objects.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="7. Optional Operating System"
href="someos.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="7.16 gzip "
href="module-gzip.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="dumbdbm-objects.html">7.14.1 Dumbdbm Objects</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="someos.html">7. Optional Operating System</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-gzip.html">7.16 gzip </A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0091500000000000000000">
7.15 <tt class="module">zlib</tt> --
Compression compatible with <b class="program">gzip</b></A>
</H1>
<P>
<A NAME="module-zlib"></A>
<P>
For applications that require data compression, the functions in this
module allow compression and decompression, using the zlib library.
The zlib library has its own home page at <a class="url" href="http://www.gzip.org/zlib/">http://www.gzip.org/zlib/</a>.
There are known incompatibilities between the Python module and
versions of the zlib library earlier than 1.1.3; 1.1.3 has a security
vulnerability, so we recommend using 1.1.4 or later.
<P>
The available exception and functions in this module are:
<P>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-2815' xml:id='l2h-2815' class="exception">error</tt></b></dt>
<dd>
Exception raised on compression and decompression errors.
</dd></dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2816' xml:id='l2h-2816' class="function">adler32</tt></b>(</nobr></td>
<td><var>string</var><big>[</big><var>, value</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Computes a Adler-32 checksum of <var>string</var>. (An Adler-32
checksum is almost as reliable as a CRC32 but can be computed much
more quickly.) If <var>value</var> is present, it is used as the
starting value of the checksum; otherwise, a fixed default value is
used. This allows computing a running checksum over the
concatenation of several input strings. The algorithm is not
cryptographically strong, and should not be used for
authentication or digital signatures. Since the algorithm is
designed for use as a checksum algorithm, it is not suitable for
use as a general hash algorithm.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2817' xml:id='l2h-2817' class="function">compress</tt></b>(</nobr></td>
<td><var>string</var><big>[</big><var>, level</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Compresses the data in <var>string</var>, returning a string contained
compressed data. <var>level</var> is an integer from <code>1</code> to
<code>9</code> controlling the level of compression; <code>1</code> is fastest
and produces the least compression, <code>9</code> is slowest and produces
the most. The default value is <code>6</code>. Raises the
<tt class="exception">error</tt> exception if any error occurs.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2818' xml:id='l2h-2818' class="function">compressobj</tt></b>(</nobr></td>
<td><var></var><big>[</big><var>level</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Returns a compression object, to be used for compressing data streams
that won't fit into memory at once. <var>level</var> is an integer from
<code>1</code> to <code>9</code> controlling the level of compression; <code>1</code> is
fastest and produces the least compression, <code>9</code> is slowest and
produces the most. The default value is <code>6</code>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2819' xml:id='l2h-2819' class="function">crc32</tt></b>(</nobr></td>
<td><var>string</var><big>[</big><var>, value</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Computes a CRC (Cyclic Redundancy Check)<a id='l2h-2828' xml:id='l2h-2828'></a>
checksum of <var>string</var>. If
<var>value</var> is present, it is used as the starting value of the
checksum; otherwise, a fixed default value is used. This allows
computing a running checksum over the concatenation of several
input strings. The algorithm is not cryptographically strong, and
should not be used for authentication or digital signatures. Since
the algorithm is designed for use as a checksum algorithm, it is not
suitable for use as a general hash algorithm.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2820' xml:id='l2h-2820' class="function">decompress</tt></b>(</nobr></td>
<td><var>string</var><big>[</big><var>, wbits</var><big>[</big><var>, bufsize</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Decompresses the data in <var>string</var>, returning a string containing
the uncompressed data. The <var>wbits</var> parameter controls the size of
the window buffer. If <var>bufsize</var> is given, it is used as the
initial size of the output buffer. Raises the <tt class="exception">error</tt>
exception if any error occurs.
<P>
The absolute value of <var>wbits</var> is the base two logarithm of the
size of the history buffer (the ``window size'') used when compressing
data. Its absolute value should be between 8 and 15 for the most
recent versions of the zlib library, larger values resulting in better
compression at the expense of greater memory usage. The default value
is 15. When <var>wbits</var> is negative, the standard
<b class="program">gzip</b> header is suppressed; this is an undocumented feature
of the zlib library, used for compatibility with <b class="program">unzip</b>'s
compression file format.
<P>
<var>bufsize</var> is the initial size of the buffer used to hold
decompressed data. If more space is required, the buffer size will be
increased as needed, so you don't have to get this value exactly
right; tuning it will only save a few calls to <tt class="cfunction">malloc()</tt>. The
default size is 16384.
<P>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2821' xml:id='l2h-2821' class="function">decompressobj</tt></b>(</nobr></td>
<td><var></var><big>[</big><var>wbits</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Returns a decompression object, to be used for decompressing data
streams that won't fit into memory at once. The <var>wbits</var>
parameter controls the size of the window buffer.
</dl>
<P>
Compression objects support the following methods:
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2822' xml:id='l2h-2822' class="method">compress</tt></b>(</nobr></td>
<td><var>string</var>)</td></tr></table></dt>
<dd>
Compress <var>string</var>, returning a string containing compressed data
for at least part of the data in <var>string</var>. This data should be
concatenated to the output produced by any preceding calls to the
<tt class="method">compress()</tt> method. Some input may be kept in internal buffers
for later processing.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2823' xml:id='l2h-2823' class="method">flush</tt></b>(</nobr></td>
<td><var></var><big>[</big><var>mode</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
All pending input is processed, and a string containing the remaining
compressed output is returned. <var>mode</var> can be selected from the
constants <tt class="constant">Z_SYNC_FLUSH</tt>, <tt class="constant">Z_FULL_FLUSH</tt>, or
<tt class="constant">Z_FINISH</tt>, defaulting to <tt class="constant">Z_FINISH</tt>. <tt class="constant">Z_SYNC_FLUSH</tt> and
<tt class="constant">Z_FULL_FLUSH</tt> allow compressing further strings of data and
are used to allow partial error recovery on decompression, while
<tt class="constant">Z_FINISH</tt> finishes the compressed stream and
prevents compressing any more data. After calling
<tt class="method">flush()</tt> with <var>mode</var> set to <tt class="constant">Z_FINISH</tt>, the
<tt class="method">compress()</tt> method cannot be called again; the only realistic
action is to delete the object.
</dl>
<P>
Decompression objects support the following methods, and two attributes:
<P>
<dl><dt><b><tt id='l2h-2824' xml:id='l2h-2824' class="member">unused_data</tt></b></dt>
<dd>
A string which contains any bytes past the end of the compressed data.
That is, this remains <code>""</code> until the last byte that contains
compression data is available. If the whole string turned out to
contain compressed data, this is <code>""</code>, the empty string.
<P>
The only way to determine where a string of compressed data ends is by
actually decompressing it. This means that when compressed data is
contained part of a larger file, you can only find the end of it by
reading data and feeding it followed by some non-empty string into a
decompression object's <tt class="method">decompress</tt> method until the
<tt class="member">unused_data</tt> attribute is no longer the empty string.
</dl>
<P>
<dl><dt><b><tt id='l2h-2825' xml:id='l2h-2825' class="member">unconsumed_tail</tt></b></dt>
<dd>
A string that contains any data that was not consumed by the last
<tt class="method">decompress</tt> call because it exceeded the limit for the
uncompressed data buffer. This data has not yet been seen by the zlib
machinery, so you must feed it (possibly with further data
concatenated to it) back to a subsequent <tt class="method">decompress</tt> method
call in order to get correct output.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2826' xml:id='l2h-2826' class="method">decompress</tt></b>(</nobr></td>
<td><var>string</var><big>[</big><var>, max_length</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Decompress <var>string</var>, returning a string containing the
uncompressed data corresponding to at least part of the data in
<var>string</var>. This data should be concatenated to the output produced
by any preceding calls to the
<tt class="method">decompress()</tt> method. Some of the input data may be preserved
in internal buffers for later processing.
<P>
If the optional parameter <var>max_length</var> is supplied then the return value
will be no longer than <var>max_length</var>. This may mean that not all of the
compressed input can be processed; and unconsumed data will be stored
in the attribute <tt class="member">unconsumed_tail</tt>. This string must be passed
to a subsequent call to <tt class="method">decompress()</tt> if decompression is to
continue. If <var>max_length</var> is not supplied then the whole input is
decompressed, and <tt class="member">unconsumed_tail</tt> is an empty string.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2827' xml:id='l2h-2827' class="method">flush</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
All pending input is processed, and a string containing the remaining
uncompressed output is returned. After calling <tt class="method">flush()</tt>, the
<tt class="method">decompress()</tt> method cannot be called again; the only realistic
action is to delete the object.
</dl>
<P>
<div class="seealso">
<p class="heading">See Also:</p>
<dl compact="compact" class="seemodule">
<dt>Module <b><tt class="module"><a href="module-gzip.html">gzip</a></tt>:</b>
<dd>Reading and writing <b class="program">gzip</b>-format files.
</dl>
<dl compact="compact" class="seeurl">
<dt><a href="http://www.gzip.org/zlib/"
class="url">http://www.gzip.org/zlib/</a></dt>
<dd>The zlib library home page.</dd>
</dl>
</div>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="7.14.1 Dumbdbm Objects"
href="dumbdbm-objects.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="7. Optional Operating System"
href="someos.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="7.16 gzip "
href="module-gzip.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="dumbdbm-objects.html">7.14.1 Dumbdbm Objects</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="someos.html">7. Optional Operating System</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-gzip.html">7.16 gzip </A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>