Oops -- Lib/Test should be Lib/test, of course!
[python/dscho.git] / Doc / lib / libgzip.tex
blobfd2bc283901e2af340add4492d9a9f74bd4f0051
1 \section{Standard Module \module{gzip}}
2 \label{module-gzip}
3 \stmodindex{gzip}
5 The data compression provided by the \code{zlib} module is compatible
6 with that used by the GNU compression program \program{gzip}.
7 Accordingly, the \module{gzip} module provides the \class{GzipFile}
8 class to read and write \program{gzip}-format files, automatically
9 compressing or decompressing the data so it looks like an ordinary
10 file object.
12 \class{GzipFile} objects simulate most of the methods of a file
13 object, though it's not possible to use the \method{seek()} and
14 \method{tell()} methods to access the file randomly.
15 \withsubitem{(class in gzip)}{\ttindex{GzipFile}}
18 \begin{funcdesc}{open}{fileobj\optional{, filename\optional{,
19 mode\optional{, compresslevel}}}}
20 Returns a new \class{GzipFile} object on top of \var{fileobj}, which
21 can be a regular file, a \class{StringIO} object, or any object which
22 simulates a file.
24 The \program{gzip} file format includes the original filename of the
25 uncompressed file; when opening a \class{GzipFile} object for
26 writing, it can be set by the \var{filename} argument. The default
27 value is an empty string.
29 \var{mode} can be either \code{'r'} or \code{'w'} depending on
30 whether the file will be read or written. \var{compresslevel} is an
31 integer from \code{1} to \code{9} controlling the level of
32 compression; \code{1} is fastest and produces the least compression,
33 and \code{9} is slowest and produces the most compression. The
34 default value of \var{compresslevel} is \code{9}.
36 Calling a \class{GzipFile} object's \method{close()} method does not
37 close \var{fileobj}, since you might wish to append more material
38 after the compressed data. This also allows you to pass a
39 \class{StringIO} object opened for writing as \var{fileobj}, and
40 retrieve the resulting memory buffer using the \class{StringIO}
41 object's \method{getvalue()} method.
42 \end{funcdesc}
44 \begin{seealso}
45 \seemodule{zlib}{the basic data compression module}
46 \end{seealso}