本文介绍了Python tarfile 进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将文件添加到 python 中的 tar 存档时,是否有任何库可以显示进度,或者可以扩展 tarfile 模块的功能来执行此操作?

Is there any library to show progress when adding files to a tar archive in python or alternativly would be be possible to extend the functionality of the tarfile module to do this?

在理想的世界中,我想展示 tar 创建的整体进度以及何时完成的预计到达时间.

In an ideal world I would like to show the overall progress of the tar creation as well as an ETA as to when it will be complete.

对此的任何帮助将不胜感激.

Any help on this would be really appreciated.

推荐答案

好像可以使用 tarfile.add()

with tarfile.open(<tarball path>, 'w') as tarball:
   tarball.add(<some file>, filter = my_filter)

def my_filter(tarinfo):
   #increment some count
   #add tarinfo.size to some byte counter
   return tarinfo

您可以从 TarInfo 对象获得的所有信息都可供您使用.

All information you can get from a TarInfo object is available to you.

这篇关于Python tarfile 进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 15:44