rest25/library/gzip.rst => rest262/library/gzip.rst
n1- 
2:mod:`gzip` --- Support for :program:`gzip` files
3=================================================
4
5.. module:: gzip
6   :synopsis: Interfaces for gzip compression and decompression using file objects.
7
n7+This module provides a simple interface to compress and decompress files just
8+like the GNU programs :program:`gzip` and :program:`gunzip` would.
8
n9-The data compression provided by the ``zlib`` module is compatible with that
n10+The data compression is provided by the :mod:`zlib` module.
10-used by the GNU compression program :program:`gzip`. Accordingly, the
11+ 
11-:mod:`gzip` module provides the :class:`GzipFile` class to read and write
12+The :mod:`gzip` module provides the :class:`GzipFile` class which is modeled
13+after Python's File Object. The :class:`GzipFile` class reads and writes
12:program:`gzip`\ -format files, automatically compressing or decompressing the
n13-data so it looks like an ordinary file object.  Note that additional file
n15+data so that it looks like an ordinary file object.
14-formats which can be decompressed by the :program:`gzip` and :program:`gunzip`
16+ 
15-programs, such  as those produced by :program:`compress` and :program:`pack`,
17+Note that additional file formats which can be decompressed by the
16-are not supported by this module.
18+:program:`gzip` and :program:`gunzip` programs, such  as those produced by
19+:program:`compress` and :program:`pack`, are not supported by this module.
20+ 
21+For other archive formats, see the :mod:`bz2`, :mod:`zipfile`, and
22+:mod:`tarfile` modules.
17
18The module defines the following items:
19
20
21.. class:: GzipFile([filename[, mode[, compresslevel[, fileobj]]]])
22
23   Constructor for the :class:`GzipFile` class, which simulates most of the methods
24   of a file object, with the exception of the :meth:`readinto` and
55
56.. function:: open(filename[, mode[, compresslevel]])
57
58   This is a shorthand for ``GzipFile(filename,`` ``mode,`` ``compresslevel)``.
59   The *filename* argument is required; *mode* defaults to ``'rb'`` and
60   *compresslevel* defaults to ``9``.
61
62
t69+.. _gzip-usage-examples:
70+ 
71+Examples of usage
72+-----------------
73+ 
74+Example of how to read a compressed file::
75+ 
76+   import gzip
77+   f = gzip.open('/home/joe/file.txt.gz', 'rb')
78+   file_content = f.read()
79+   f.close()
80+ 
81+Example of how to create a compressed GZIP file::
82+ 
83+   import gzip
84+   content = "Lots of content here"
85+   f = gzip.open('/home/joe/file.txt.gz', 'wb')
86+   f.write(content)
87+   f.close()
88+ 
89+Example of how to GZIP compress an existing file::
90+ 
91+   import gzip
92+   f_in = open('/home/joe/file.txt', 'rb')
93+   f_out = gzip.open('/home/joe/file.txt.gz', 'wb')
94+   f_out.writelines(f_in)
95+   f_out.close()
96+   f_in.close()
97+ 
98+ 
63.. seealso::
64
65   Module :mod:`zlib`
66      The basic data compression module needed to support the :program:`gzip` file
67      format.
68
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op