Xah Lee, 2005-08-30
Here is a example of how to decompress a gzip file using Python.
# Python import gzip inF = gzip.GzipFile("/Users/t/access_log.1.gz", 'rb'); s=inF.read() inF.close() outF = file("/Users/t/access_log.1", 'wb'); outF.write(s) outF.close()
Here is a example of compressing a gzip file using Python.
# Python import gzip inF = file("x.txt", 'rb'); s=inF.read() inF.close() outF = gzip.GzipFile("x.txt.gz", 'wb'); outF.write(s) outF.close()
For more detail, see http://python.org/doc/2.4.1/lib/module-gzip.html
Perl does not come with a gzip module bundled, but one can easily call the unix gzip with qx. (assuming you are on unix)
# perl qx(gzip x.txt); qx(gzip -d x.txt.gz);
Several module are available online to do compression. IO::Zlib, PerlIO::gzip.
See also:
Page created: 2005-08. © 2005 by Xah Lee.