gzip

[解压缩gzip 删除原文件]

    #压缩gzip
    import gzip
    f_in = open('file.log', 'rb')
    f_out = gzip.open('file.log.gz', 'wb')
    f_out.writelines(f_in)
    f_out.close()
    f_in.close()

    #压缩gzip
    File = 'xuesong_18.log'
    g = gzip.GzipFile(filename="", mode='wb', compresslevel=9, fileobj=open((r'%s.gz' %File),'wb'))
    g.write(open(r'%s' %File).read())
    g.close()

    #解压gzip
    g = gzip.GzipFile(mode='rb', fileobj=open((r'xuesong_18.log.gz'),'rb'))
    open((r'xuesong_18.log'),'wb').write(g.read())
文档更新时间: 2018-11-21 17:26   作者:RuM