Python tarfile
库不会检测到损坏的tar。
user@host$ wc -c good.tar
143360 good.tar
user@host$ head -c 130000 good.tar > cut.tar
user@host$ tar -tf cut.tar
...
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
非常好,命令行工具可以识别意外的EOF。
user@host$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
>>> import tarfile
>>> tar=tarfile.open('cut.tar')
>>> tar.extractall()
这可不好。Python库对文件进行解码,但不会引发异常。
如何用Python库检测意外的EOF?我想避免使用subprocess
模块。
参数errorlevel
没有帮助。我试过errorlevel=1和errorlevel=2。
https://stackoverflow.com/questions/30302204
复制相似问题