is_tarfile() returns True for a blank file
<p><strong>EDIT 1</strong></p>

<p>Hmm, I accept the answers that tar respects an empty file... but on my system:</p>

<pre><code>$ touch emptytar
$ tar -tf emptytar 
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
</code></pre>

<p>Maybe I have a non-canonical version?</p>

<pre><code>$ tar --version
tar (GNU tar) 1.22
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;.
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.
</code></pre>

<p>Hello all,</p>

<p>I am testing some logic to handle a user uploading a TAR file.  When I feed a blank file to <code>tarfile.is_tarfile()</code> it returns <code>True</code>, which is not what I am expecting:</p>

<pre><code>$ touch tartest
$ cat tartest
$ python -c "import tarfile; print tarfile.is_tarfile('tartest')"
True
</code></pre>

<p>If I add some text to the file, it returns <code>False</code>, which I am expecting:</p>

<pre><code>$ echo "not a tar" &gt; tartest
$ python -c "import tarfile; print tarfile.is_tarfile('tartest')"
False
</code></pre>

<p>I could add a check at the beginning to check for a zero-length file, but based on the <a href="http://docs.python.org/library/tarfile.html#tarfile.is_tarfile" rel="nofollow">documentation</a> for <code>tarfile.is_tarfile(name)</code> I think this is unecessary:</p>

<blockquote>
  <p>Return True if name is a tar archive
  file, that the tarfile module can
  read.</p>
</blockquote>

<p>I went so far as to check the source, <a href="http://svn.python.org/projects/python/trunk/Lib/tarfile.py" rel="nofollow" title="tarfile.py">tarfile.py</a>, and I can see that it is checking header blocks but I do not fully understand how it is evaluating those blocks.</p>

<p>Am I misreading the documentation and therefore setting unfair expectations?</p>

<p>Thank you,<br>
Zachary</p>
