cpython/Doc/libgzip.tex

48 lines
2.0 KiB
TeX
Raw Normal View History

1998-03-10 01:41:08 -04:00
\section{Standard Module \sectcode{gzip}}
1997-07-17 13:26:11 -03:00
\label{module-gzip}
1998-03-10 01:41:08 -04:00
\stmodindex{gzip}
1997-07-17 13:26:11 -03:00
The data compression provided by the \code{zlib} module is compatible
1998-03-10 01:41:08 -04:00
with that used by the GNU compression program \program{gzip}.
Accordingly, the \module{gzip} module provides the \class{GzipFile}
class to read and write \program{gzip}-format files, automatically
compressing or decompressing the data so it looks like an ordinary
file object.
\class{GzipFile} objects simulate most of the methods of a file
object, though it's not possible to use the \method{seek()} and
\method{tell()} methods to access the file randomly.
1998-04-03 02:48:16 -04:00
\withsubitem{(class in gzip)}{\ttindex{GzipFile}}
1998-03-10 01:41:08 -04:00
1998-04-03 02:48:16 -04:00
\begin{funcdesc}{open}{fileobj\optional{, filename\optional{,
mode\optional{, compresslevel}}}}
1998-03-10 01:41:08 -04:00
Returns a new \class{GzipFile} object on top of \var{fileobj}, which
can be a regular file, a \class{StringIO} object, or any object which
1997-07-17 13:26:11 -03:00
simulates a file.
1998-03-10 01:41:08 -04:00
The \program{gzip} file format includes the original filename of the
uncompressed file; when opening a \class{GzipFile} object for
1997-07-17 13:26:11 -03:00
writing, it can be set by the \var{filename} argument. The default
value is an empty string.
1997-07-17 13:26:11 -03:00
\var{mode} can be either \code{'r'} or \code{'w'} depending on
whether the file will be read or written. \var{compresslevel} is an
1998-03-10 01:41:08 -04:00
integer from \code{1} to \code{9} controlling the level of
compression; \code{1} is fastest and produces the least compression,
and \code{9} is slowest and produces the most compression. The
default value of \var{compresslevel} is \code{9}.
1997-07-17 13:26:11 -03:00
1998-03-10 01:41:08 -04:00
Calling a \class{GzipFile} object's \method{close()} method does not
1997-07-17 13:26:11 -03:00
close \var{fileobj}, since you might wish to append more material
after the compressed data. This also allows you to pass a
1998-03-10 01:41:08 -04:00
\class{StringIO} object opened for writing as \var{fileobj}, and
retrieve the resulting memory buffer using the \class{StringIO}
object's \method{getvalue()} method.
1997-07-17 13:26:11 -03:00
\end{funcdesc}
\begin{seealso}
\seemodule{zlib}{the basic data compression module}
\end{seealso}