summaryrefslogtreecommitdiffstats
path: root/Doc/libgzip.tex
blob: a56e573e356c54c5c8759be0055efc78b788c4e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
\section{Standard Module \sectcode{gzip}}
\label{module-gzip}
\stmodindex{gzip}

The data compression provided by the \code{zlib} module is compatible
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.
\withsubitem{(class in gzip)}{\ttindex{GzipFile}}


\begin{funcdesc}{open}{fileobj\optional{, filename\optional{,
                       mode\optional{, compresslevel}}}}
  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
  simulates a file.

  The \program{gzip} file format includes the original filename of the
  uncompressed file; when opening a \class{GzipFile} object for
  writing, it can be set by the \var{filename} argument.  The default
  value is an empty string.

  \var{mode} can be either \code{'r'} or \code{'w'} depending on
  whether the file will be read or written.  \var{compresslevel} is an
  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}.

  Calling a \class{GzipFile} object's \method{close()} method does not
  close \var{fileobj}, since you might wish to append more material
  after the compressed data.  This also allows you to pass a
  \class{StringIO} object opened for writing as \var{fileobj}, and
  retrieve the resulting memory buffer using the \class{StringIO}
  object's \method{getvalue()} method.
\end{funcdesc}

\begin{seealso}
\seemodule{zlib}{the basic data compression module}
\end{seealso}