我有一个程序可以在工作时将其输出保存到 tar.bz2 文件中。我有一个处理该数据的 python 脚本。
如果第一个程序被中断,我希望能够使用输出 - 或者只是在进程正在进行时针对它运行 python 脚本。
当然,最终的 bzip2 块是未完成的,因此无法读取 - 它实际上已损坏,尽管实际上它只是被截断了。GNU tar 实际上会很高兴地提取到该文件的所有内容 - 就这一点而言,也将bzcat
如此。并且bzip2recover
可以创建修复的块,尽管在这种情况下它确实没有bzcat
.
但我正在尝试使用 Python 的标准tarfile模块。这失败了
File "/usr/lib64/python2.7/tarfile.py", line 2110, in extractfile
tarinfo = self.getmember(member)
File "/usr/lib64/python2.7/tarfile.py", line 1792, in getmember
tarinfo = self._getmember(name)
File "/usr/lib64/python2.7/tarfile.py", line 2361, in _getmember
members = self.getmembers()
File "/usr/lib64/python2.7/tarfile.py", line 1803, in getmembers
self._load() # all members, we first have to
File "/usr/lib64/python2.7/tarfile.py", line 2384, in _load
tarinfo = self.next()
File "/usr/lib64/python2.7/tarfile.py", line 2319, in next
self.fileobj.seek(self.offset)
EOFError: compressed file ended before the logical end-of-stream was detected
当我尝试在我知道开头TarFile.extractfile
的文件上使用时。(将提取它就好了。)tar -xf tarfile.tar.bz2 filename
有什么聪明的方法可以忽略文件的无效结尾并使用我所拥有的吗?
数据集可以变得相当大,并且非常非常可压缩,因此不希望将其保持为未压缩状态。
(我发现现有问题Untar archive in Python with errors,但在这种情况下,用户正在尝试os.system
tar 文件。)