Here is a example of how to decompress a gzip file using Python.
# -*- coding: utf-8 -*- # 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.
# -*- coding: utf-8 -*- # 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)
# -*- coding: utf-8 -*- # perl qx(gzip x.txt); qx(gzip -d x.txt.gz);
Several module are available online to do compression. IO::Zlib, PerlIO::gzip.
blog comments powered by Disqus