一.gzip
import gzip
1.解压缩
a = gzip.open('a.tar.gz')
b = open('a.tar','wb')
b.write(a.read())
a.close()
b.close()
2.压缩文件
b = open('c.tar','rb')
c = gzip.open('c.tar.gz','wb')
c.write(b.read())
b.close(0
c.close(0
二.bz2
bz2的使用方法与gz一样
import bz2
1.解压
a=bz2.BZ2File('fio-2.1.2.tar.bz2')
b = open('fio.tar','wb')
b.write(a.read())
a.close()
b.close()
2.压缩
a=bz2.BZ2File('f.tar.bz2','wb')
b=open('fio.tar','rb')
a.write(b.read())
a.close()
b.close()