Is it possible to create a TarFile object in memory using a buffer containing the tar data without having to write the TarFile to disk and open it up again? We get the bytes
Sure, something like this:
import io
io_bytes = io.BytesIO(byte_array)
tar = tarfile.open(fileobj=io_bytes, mode='r')
(Adjust mode to fit the format of your tar file, e.g. possibly `mode='r:gz', etc.)
BytesIO() from IO module does exactly what you need.
import tarfile, io
byte_array = client.read_bytes()
file_like_object = io.BytesIO(byte_array)
tar = tarfile.open(fileobj=file_like_object)
# use "tar" as a regular TarFile object
for member in tar.getmembers():
f = tar.extractfile(member)
print(f)