In python 3 (3.6.8) I want to read a gzipped tar file and list its content.
I found this solution which yields an error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
Searching for this error in found this suggestion so I tried the following code snippet:
with open(out_file) as fd:
gzip_fd = gzip.GzipFile(fileobj=fd)
tar = tarfile.open(gzip_fd.read())
which yields the same error!
So how to do it right?
Even when looking at the actual documentation here I came up with the following code:
tar = tarfile.open(out_file, "w:gz")
for member in tar.getnames():
print(tar.extractfile(member).read())
which finally worked without errors - but did not print any content of the tar archive on the screen!
The tar file is well formatted and contains folders and files. (I need to try to share this file)