How can I read tarfile from generator?

Create a zip file from a generator in Python? describes a solution for writing .zip to disk from a bunch of files.

I have a similar problem in the opposite direction. I am given a generator:

stream = attachment.iter_bytes()
print type(stream)

and I would like to pass it to a file like the tarzipip file:

b = io.BytesIO(stream)
f = tarfile.open(mode='r:gz', fileobj = b)
f.list()

But I can not:

<type 'generator'>
Error: 'generator' does not have the buffer interface

I can solve this in a shell like this:

$ curl --options http://URL | tar zxf - ./path/to/interesting_file

How can I do the same in Python under given conditions?

+4
source share

Source: https://habr.com/ru/post/1652533/


All Articles