Create a zip file from a generator in Python? describes a solution for writing a .zip to disk from a bunch of files.
I have a similar problem in the opposite direction. I am being given a generator:
stream = attachment.iter_bytes()
print type(stream)
and I would love to pipe it to a tar gunzip file-like object:
b = io.BytesIO(stream)
f = tarfile.open(mode='r:gz', fileobj = b)
f.list()
But I can't:
<type 'generator'>
Error: 'generator' does not have the buffer interface
I can solve this in the shell like so:
$ curl --options http://URL | tar zxf - ./path/to/interesting_file
How can I do the same in Python under the given conditions?