Compressed Files
Although storage space and transmission bandwidth are increasingly cheap and abundant, in many cases you can save such resources, at the expense of some computational effort, by using compression. Since computational power grows cheaper and more abundant even faster than other resources, such as bandwidth, compression’s popularity keeps growing. Python makes it easy for your programs to support compression by supplying dedicated modules for compression as part of every Python distribution.
The gzip Module
The gzip module lets
you read and write files compatible with those handled by the
powerful GNU compression programs gzip and
gunzip. The GNU programs support several
compression formats, but module gzip supports only
the highly effective native gzip format,
normally denoted by appending the extension .gz
to a filename. Module gzip supplies the
GzipFile class and an open
factory function.
The zipfile Module
The zipfile module
lets you read and write ZIP files (i.e., archive files compatible
with those handled by popular compression programs
zip and unzip,
pkzip and pkunzip,
WinZip, and so on). Detailed information on the
formats and capabilities of ZIP files can be found at http://www.pkware.com/appnote.html and
http://www.info-zip.org/pub/infozip/. You
need to study this detailed information in order to perform advanced
ZIP file handing with module
zipfile.
Module zipfile can’t handle ZIP
files with appended comments, multidisk ZIP files, or
.zip archive ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access