The Python tarfile
library does not detect a broken 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
Very nice, the command line tool recognizes an unexpected EOF.
user@host$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
>>> import tarfile
>>> tar=tarfile.open('cut.tar')
>>> tar.extractall()
Not nice. The Python library decodes the file, but raises no exception.
How to detect unexpected EOF with the Python library? I want to avoid the subprocess
module.
The parameter errorlevel
does not help. I tried errorlevel=1 and errorlevel=2.