Author lars.gustaebel
Recipients lars.gustaebel, markgrandi
Date 2014-08-16.10:53:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Why overcomplicate things?

import io, tarfile

with"foo.tar", mode="w") as tar:
    b = "hello world!".encode("utf-8")

    t = tarfile.TarInfo("helloworld.txt")
    t.size = len(b) # this is crucial
    tar.addfile(t, io.BytesIO(b))

My answer to issue10369 was never supposed to be used as a reference on how to add file-like objects to a TarFile. I posted it as a simpler but equivalent version of the code of the original poster, which is why it looks "hackish".

I think the documentation on TarFile.gettarinfo() is rather clear on how to use it (i.e. that it needs a file object with a valid file descriptor). Also, I think that the code above is intuitive and simple.
Date User Action Args
2014-08-16 10:53:45lars.gustaebelsetrecipients: + lars.gustaebel, markgrandi
2014-08-16 10:53:45lars.gustaebelsetmessageid: <>
2014-08-16 10:53:45lars.gustaebellinkissue22208 messages
2014-08-16 10:53:45lars.gustaebelcreate