EDIT 1
Hm, I accept the answers that tar respects an empty file ... but on my system:
$ touch emptytar $ tar -tf emptytar tar: This does not look like a tar archive tar: Exiting with failure status due to previous errors
Maybe I have a non-canonical version?
$ tar --version tar (GNU tar) 1.22 Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by John Gilmore and Jay Fenlason.
Hello to all,
I am testing some logic to handle the user loading the tar file. When I write an empty file in tarfile.is_tarfile() , it returns True , which I do not expect:
$ touch tartest $ cat tartest $ python -c "import tarfile; print tarfile.is_tarfile('tartest')" True
If I add some text to the file, it will return False , which I expect:
$ echo "not a tar" > tartest $ python -c "import tarfile; print tarfile.is_tarfile('tartest')" False
I could add a check at the beginning to check the file with zero length, but based on the documentation for tarfile.is_tarfile(name) I think this is not necessary:
Return True if the name is the tar archive of the file that the tarfile module can use. to read.
I went so far as to check the source, tarfile.py , and I see that it is checking header blocks, but I donβt quite understand how it evaluates these blocks.
Am I misunderstanding the documentation and therefore setting unfair expectations?
Thanks,
Zachary
python
Zachary young
source share