4

How do I get the binary representation of a tarfile object in Python? Right now I am doing the following, but this involves "copying":

with BytesIO() as out_buffer:
    with tarfile.open(fileobj=out_buffer, mode='w') as newtar:
        for member in data:
            newtar.addfile(member, data.extractfile(member))
    tar_binary = out_buffer.getvalue()
Elazar
  • 20,415
  • 4
  • 46
  • 67
Alex Rothberg
  • 10,243
  • 13
  • 60
  • 120

0 Answers0