Creating an MD5 Hash of A ZipFile
<p>I want to create an MD5 hash of a <code>ZipFile</code>, not of one of the files inside it. However, <code>ZipFile</code> objects aren't easily convertible to streams.</p>

<pre><code>from hashlib import md5
from zipfile import ZipFile

zipped = ZipFile(r'/Foo/Bar/Filename.zip')
hasher = md5()
hasher.update(zipped)

return hasher.hexdigest()
</code></pre>

<p>The above code generates the error :<code>TypeError: must be convertible to a buffer, not ZipFile</code>. </p>

<p>Is there a straightforward way to turn a <code>ZipFile</code> into a stream?</p>

<p>There's no security issues here, I just need a quick an easy way to determine if I've seen a file before. <code>hash(zipped)</code> works fine, but I'd like something a little more robust if possible.</p>

<p>Just open the ZipFile as a regular file. Following code works on my machine.</p>

<pre><code>from hashlib import md5
m = md5()
with open("/Foo/Bar/Filename.zip", "rb") as f:
    data = f.read() #read file in chunk and call update on each chunk if file is large.
    m.update(data)
    print m.hexdigest()
</code></pre>

python