annotate Doc/lib/libgzip.tex @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 55ea56ee20f6
children 6f2ab4afa8f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5814
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 \section{Built-in Module \sectcode{gzip}}
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 \label{module-gzip}
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 \bimodindex{gzip}
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 The data compression provided by the \code{zlib} module is compatible
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 with that used by the GNU compression program \file{gzip}.
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 Accordingly, the \code{gzip} module provides the \code{GzipFile} class
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 to read and write \file{gzip}-format files, automatically compressing
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 or decompressing the data so it looks like an ordinary file object.
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 \code{GzipFile} objects simulate most of the methods of a file
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 object, though it's not possible to use the \code{seek()} and
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 \code{tell()} methods to access the file randomly.
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 \renewcommand{\indexsubitem}{(in module gzip)}
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 \begin{funcdesc}{open}{fileobj\optional{\, filename\optional{\, mode\, compresslevel}}}
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 Returns a new \code{GzipFile} object on top of \var{fileobj}, which
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 can be a regular file, a \code{StringIO} object, or any object which
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 simulates a file.
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 The \file{gzip} file format includes the original filename of the
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 uncompressed file; when opening a \code{GzipFile} object for
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 writing, it can be set by the \var{filename} argument. The default
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 value is \code{"GzippedFile"}.
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 \var{mode} can be either \code{'r'} or \code{'w'} depending on
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 whether the file will be read or written. \var{compresslevel} is an
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 integer from 1 to 9 controlling the level of compression; 1 is
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 fastest and produces the least compression, and 9 is slowest and
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 produces the most compression. The default value of
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 \var{compresslevel} is 9.
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 Calling a \code{GzipFile} object's \code{close()} method does not
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 close \var{fileobj}, since you might wish to append more material
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 after the compressed data. This also allows you to pass a
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 \code{StringIO} object opened for writing as \var{fileobj}, and
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 retrieve the resulting memory buffer using the \code{StringIO}
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 object's \code{getvalue()} method.
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 \end{funcdesc}
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 \begin{seealso}
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 \seemodule{zlib}{the basic data compression module}
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 \end{seealso}
55ea56ee20f6 New from AMK
Guido van Rossum <guido@python.org>
parents:
diff changeset
44