GZip: Python - How to get the file name of a particular line using gzip.open
Question: I have a '.tgz' file, I'm reading the content of the '.tgz' file using
gzip.open. What is the fastest way to get the file name of a particular line?

    
    
    with gzip.open('sample.tgz','r') as fin:
        for line in fin:
            error = checkForError(line)
            if error:
                # get the file name in which that particular error line was present
            else:
                pass
    


Answer: This functions but quite how useful it is, is anyone's guess.  
Check <https://en.wikipedia.org/wiki/Tar_%28computing%29#Header> for the
header format.

    
    
    import gzip
    fin = gzip.open("test.txt.tar","r")
    for i in fin:
        if "ustar" in i:
            fname,b = i.split("0",1)
            print fname
        else:
            print i
    fin.close()
    

Note: this is for python 2.7.6 on Linux, assuming the archive was created with
`tar czvf`

