1 \section{Standard Module
\module{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
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
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.
45 \seemodule{zlib
}{the basic data compression module
}