Gzip:
Gzip
suggest changeIntroduction
This module provides a simple interface to compress and decompress files just like the GNU programs gzip and gunzip would.
The data compression is provided by the zlib module.
The gzip module provides the GzipFile class which is modeled after Python’s File Object. The GzipFile class reads and writes gzip-format files, automatically compressing or decompressing the data so that it looks like an ordinary file object.
Read and write GNU zip files
import gzip
import os
outfilename = 'example.txt.gz'
output = gzip.open(outfilename, 'wb')
try:
output.write('Contents of the example file go here.\n')
finally:
output.close()
print outfilename, 'contains', os.stat(outfilename).st_size, 'bytes of compressed data'
os.system('file -b --mime %s' % outfilename)
Save it as 1gzip_write.py1.Run it through terminal.
$ python gzip_write.py
application/x-gzip; charset=binary
example.txt.gz contains 68 bytes of compressed data
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents
3List
22Reduce
27Classes
28Counting
31Set
42Tuple
45Enum
60setup.py
62Sockets
89urllib
92Idioms
104Stack
105Profiling
109Logging
111os module
118Mixins
120ArcPy
123Websockets
126Arrays
128Polymorphism
1322to3 tool
135Unicode
138Neo4j
140Curses
141Templates
145heapq
146tkinter
154Audio
155pyglet
156queue module
157ijson
160Flask
161Groupby
163pygame
165hashlib
166Gzip
167ctypes
170configparser
179sys module
185pyaudio
186shelve
191Contributors