Message225389
Why overcomplicate things?
import io, tarfile
with tarfile.open("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:45 | lars.gustaebel | set | recipients:
+ lars.gustaebel, markgrandi |
| 2014-08-16 10:53:45 | lars.gustaebel | set | messageid: <1408186425.77.0.539187713044.issue22208@psf.upfronthosting.co.za> |
| 2014-08-16 10:53:45 | lars.gustaebel | link | issue22208 messages |
| 2014-08-16 10:53:45 | lars.gustaebel | create | |
|