使用Python提取ZipFile,显示进度百分比?

使用Python提取ZipFile,显示进度百分比?,第1张

使用Python提取ZipFile,显示进度百分比

extract方法没有为此提供回调,因此必须使用它

getinfo
来获取e的未压缩大小,然后以块为单位打开从文件中读取的文件,然后将其写入到您要删除的文件中并更新百分比如果需要的话,还必须还原mtime:

import zipfilez = zipfile.ZipFile(some_source)entry_info = z.getinfo(entry_name)i = z.open(entry_name)o = open(target_name, 'w')offset = 0while True:    b = i.read(block_size)    offset += len(b)    set_percentage(float(offset)/float(entry_info.file_size) * 100.)    if b == '':        break    o.write(b)i.close()o.close()set_attributes_from(entry_info)

提取

entry_name
target_name


大部分 *** 作也是通过此 *** 作完成的,

shutil.copyfileobj
但也没有回呼进度

ZipFile.extract
方法调用的源
_extract_member
使用:

source = self.open(member, pwd=pwd)target = file(targetpath, "wb")shutil.copyfileobj(source, target)source.close()target.close()

如果成员不是ZipInfo对象,

getinfo(member)
则该成员已从名称转换为ZipInfo对象



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5674890.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存