Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / html / python / lib / module-gzip.html
CommitLineData
920dae64
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="lib.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="lib.html" title='Python Library Reference' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="next" href="module-bz2.html" />
13<link rel="prev" href="module-zlib.html" />
14<link rel="parent" href="someos.html" />
15<link rel="next" href="module-bz2.html" />
16<meta name='aesop' content='information' />
17<title>7.16 gzip -- Support for gzip files</title>
18</head>
19<body>
20<DIV CLASS="navigation">
21<div id='top-navigation-panel' xml:id='top-navigation-panel'>
22<table align="center" width="100%" cellpadding="0" cellspacing="2">
23<tr>
24<td class='online-navigation'><a rel="prev" title="7.15 zlib "
25 href="module-zlib.html"><img src='../icons/previous.png'
26 border='0' height='32' alt='Previous Page' width='32' /></A></td>
27<td class='online-navigation'><a rel="parent" title="7. Optional Operating System"
28 href="someos.html"><img src='../icons/up.png'
29 border='0' height='32' alt='Up One Level' width='32' /></A></td>
30<td class='online-navigation'><a rel="next" title="7.17 bz2 "
31 href="module-bz2.html"><img src='../icons/next.png'
32 border='0' height='32' alt='Next Page' width='32' /></A></td>
33<td align="center" width="100%">Python Library Reference</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="contents.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
38 border='0' height='32' alt='Module Index' width='32' /></a></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="genindex.html"><img src='../icons/index.png'
41 border='0' height='32' alt='Index' width='32' /></A></td>
42</tr></table>
43<div class='online-navigation'>
44<b class="navlabel">Previous:</b>
45<a class="sectref" rel="prev" href="module-zlib.html">7.15 zlib </A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="someos.html">7. Optional Operating System</A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="module-bz2.html">7.17 bz2 </A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H1><A NAME="SECTION0091600000000000000000">
567.16 <tt class="module">gzip</tt> --
57 Support for <b class="program">gzip</b> files</A>
58</H1>
59
60<P>
61<A NAME="module-gzip"></A>
62
63<P>
64The data compression provided by the <code>zlib</code> module is compatible
65with that used by the GNU compression program <b class="program">gzip</b>.
66Accordingly, the <tt class="module">gzip</tt> module provides the <tt class="class">GzipFile</tt>
67class to read and write <b class="program">gzip</b>-format files, automatically
68compressing or decompressing the data so it looks like an ordinary
69file object. Note that additional file formats which can be
70decompressed by the <b class="program">gzip</b> and <b class="program">gunzip</b> programs, such
71as those produced by <b class="program">compress</b> and <b class="program">pack</b>, are not
72supported by this module.
73
74<P>
75The module defines the following items:
76
77<P>
78<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
79 <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-2830' xml:id='l2h-2830' class="class">GzipFile</tt></b>(</nobr></td>
80 <td><var></var><big>[</big><var>filename</var><big>[</big><var>, mode</var><big>[</big><var>,
81 compresslevel</var><big>[</big><var>, fileobj</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
82<dd>
83Constructor for the <tt class="class">GzipFile</tt> class, which simulates most of
84the methods of a file object, with the exception of the <tt class="method">readinto()</tt>
85and <tt class="method">truncate()</tt> methods. At least one of
86<var>fileobj</var> and <var>filename</var> must be given a non-trivial value.
87
88<P>
89The new class instance is based on <var>fileobj</var>, which can be a
90regular file, a <tt class="class">StringIO</tt> object, or any other object which
91simulates a file. It defaults to <code>None</code>, in which case
92<var>filename</var> is opened to provide a file object.
93
94<P>
95When <var>fileobj</var> is not <code>None</code>, the <var>filename</var> argument is
96only used to be included in the <b class="program">gzip</b> file header, which may
97includes the original filename of the uncompressed file. It defaults
98to the filename of <var>fileobj</var>, if discernible; otherwise, it
99defaults to the empty string, and in this case the original filename
100is not included in the header.
101
102<P>
103The <var>mode</var> argument can be any of <code>'r'</code>, <code>'rb'</code>,
104<code>'a'</code>, <code>'ab'</code>, <code>'w'</code>, or <code>'wb'</code>, depending on
105whether the file will be read or written. The default is the mode of
106<var>fileobj</var> if discernible; otherwise, the default is <code>'rb'</code>.
107If not given, the 'b' flag will be added to the mode to ensure the
108file is opened in binary mode for cross-platform portability.
109
110<P>
111The <var>compresslevel</var> argument is an integer from <code>1</code> to
112<code>9</code> controlling the level of compression; <code>1</code> is fastest and
113produces the least compression, and <code>9</code> is slowest and produces
114the most compression. The default is <code>9</code>.
115
116<P>
117Calling a <tt class="class">GzipFile</tt> object's <tt class="method">close()</tt> method does not
118close <var>fileobj</var>, since you might wish to append more material
119after the compressed data. This also allows you to pass a
120<tt class="class">StringIO</tt> object opened for writing as <var>fileobj</var>, and
121retrieve the resulting memory buffer using the <tt class="class">StringIO</tt>
122object's <tt class="method">getvalue()</tt> method.
123</dl>
124
125<P>
126<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
127 <td><nobr><b><tt id='l2h-2831' xml:id='l2h-2831' class="function">open</tt></b>(</nobr></td>
128 <td><var>filename</var><big>[</big><var>, mode</var><big>[</big><var>, compresslevel</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
129<dd>
130This is a shorthand for <code>GzipFile(<var>filename</var>,</code>
131<code><var>mode</var>,</code> <code><var>compresslevel</var>)</code>. The <var>filename</var>
132argument is required; <var>mode</var> defaults to <code>'rb'</code> and
133<var>compresslevel</var> defaults to <code>9</code>.
134</dl>
135
136<P>
137<div class="seealso">
138 <p class="heading">See Also:</p>
139
140 <dl compact="compact" class="seemodule">
141 <dt>Module <b><tt class="module"><a href="module-zlib.html">zlib</a></tt>:</b>
142 <dd>The basic data compression module needed to support
143 the <b class="program">gzip</b> file format.
144 </dl>
145</div>
146
147<DIV CLASS="navigation">
148<div class='online-navigation'>
149<p></p><hr />
150<table align="center" width="100%" cellpadding="0" cellspacing="2">
151<tr>
152<td class='online-navigation'><a rel="prev" title="7.15 zlib "
153 href="module-zlib.html"><img src='../icons/previous.png'
154 border='0' height='32' alt='Previous Page' width='32' /></A></td>
155<td class='online-navigation'><a rel="parent" title="7. Optional Operating System"
156 href="someos.html"><img src='../icons/up.png'
157 border='0' height='32' alt='Up One Level' width='32' /></A></td>
158<td class='online-navigation'><a rel="next" title="7.17 bz2 "
159 href="module-bz2.html"><img src='../icons/next.png'
160 border='0' height='32' alt='Next Page' width='32' /></A></td>
161<td align="center" width="100%">Python Library Reference</td>
162<td class='online-navigation'><a rel="contents" title="Table of Contents"
163 href="contents.html"><img src='../icons/contents.png'
164 border='0' height='32' alt='Contents' width='32' /></A></td>
165<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
166 border='0' height='32' alt='Module Index' width='32' /></a></td>
167<td class='online-navigation'><a rel="index" title="Index"
168 href="genindex.html"><img src='../icons/index.png'
169 border='0' height='32' alt='Index' width='32' /></A></td>
170</tr></table>
171<div class='online-navigation'>
172<b class="navlabel">Previous:</b>
173<a class="sectref" rel="prev" href="module-zlib.html">7.15 zlib </A>
174<b class="navlabel">Up:</b>
175<a class="sectref" rel="parent" href="someos.html">7. Optional Operating System</A>
176<b class="navlabel">Next:</b>
177<a class="sectref" rel="next" href="module-bz2.html">7.17 bz2 </A>
178</div>
179</div>
180<hr />
181<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
182</DIV>
183<!--End of Navigation Panel-->
184<ADDRESS>
185See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
186</ADDRESS>
187</BODY>
188</HTML>