I am on working on a Python script which is supposed to process a tarball and output new one, trying to keep the format of the original. Thus, I am looking for a way to lookup the compression method used in an open tarball to open the new one with same compression.
AFAICS TarFile
class doesn't provide any public interface to get the needed information directly. And I would like to avoid reading the file independently of the tarfile module.
I am currently considering looking up the class of the underlying file object (t.fileobj.__class__
) or trying to open the input file in all possible modes and choosing the correct format basing on which one succeeds.