How do I read a tarfile from a generator?
<p><a href="https://stackoverflow.com/questions/297345">Create a zip file from a generator in Python?</a> describes a solution for writing a .zip to disk from a bunch of files.</p>

<p>I have a similar problem in the opposite direction. I am being given a generator:</p>

<pre><code>stream = attachment.iter_bytes()
print type(stream)
</code></pre>

<p>and I would love to pipe it to a tar gunzip file-like object:</p>

<pre><code>b = io.BytesIO(stream)
f = tarfile.open(mode='r:gz', fileobj = b)
f.list()
</code></pre>

<p>But I can't:</p>

<pre><code>&lt;type 'generator'&gt;
Error: 'generator' does not have the buffer interface
</code></pre>

<p>I can solve this in the shell like so:</p>

<pre><code>$ curl --options http://URL | tar zxf - ./path/to/interesting_file
</code></pre>

<p>How can I do the same in Python under the given conditions?</p>