title: python détect if file is tar or tar.gz or zip
body: <p>i have a problem, i need to identify file type (tar, tar.gz or zip) i found a solution in this site :
  <a href="https://stackoverflow.com/questions/13044562/python-mechanism-to-identify-compressed-file-type-and-uncompress">Python - mechanism to identify compressed file type and uncompress</a></p>
  
  <p>but the solution not work for tar file, because tar file have not same start caractere...</p>
  
  <pre><code>magic_dict = {
      "\x1f\x8b\x08": "gz",
      "\x00\x00\x00": "tar",
      "\x50\x4b\x03\x04": "zip"
      }
  
  max_len = max(len(x) for x in magic_dict)
  
  def file_type(filename):
      with open(filename) as f:
          file_start = f.read(max_len)
      for magic, filetype in magic_dict.items():
          if file_start.startswith(magic):
              return filetype
      return "no match"
  </code></pre>
  
  <p>How can i make detect tar file ?</p>