您好,欢迎来到华拓科技网。
搜索
您的当前位置:首页【Python】zlib压缩文件

【Python】zlib压缩文件

来源:华拓科技网
import zlib
import os
 
ss = 's' * 1024 * 1024
 
#写入原始文件
file = open("src.dat", "wb")
file.write(ss.encode())
file.close()
 
#读取上一步原始的文件
file = open("src.dat", "rb")
sss = file.read(os.path.getsize("src.dat"))     #获取文件大小
file.close()
 
#压缩文件
compress = zlib.compress(sss)
 
#写入压缩文件
file = open("compress.dat", "wb")
file.write(compress)
file.close()
 
#读取上一步的压缩文件
file = open("compress.dat", 'rb')
sss = file.read(os.path.getsize("compress.dat"))
file.close()
 
decompress = zlib.decompress(sss)
 
#写入还原文件
file = open("decompress.dat", "wb")
file.write(decompress)
file.close()
 
print(len(ss))
print(len(compress))
print(len(decompress))

 

转载于:https://www.cnblogs.com/tiandsp/p/8504214.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo6.cn 版权所有 赣ICP备2024042791号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务