zipfile.is_zipfile() and string buffers
gagsl-py2 at yahoo.com.ar
Tue Dec 16 17:59:36 CET 2008
En Tue, 16 Dec 2008 12:28:00 -0200, Brendan <brendandetracey at yahoo.com>
> I would like zipfile.is_zipfile(), to operate on a cStringIO.StringIO
> string buffer, but is seems only to accept file names as arguments.
> Should it not be able to handle string buffers too?
A version of zipfile.is_zipfile() accepting both file names and file
return True # file has correct magic number
"""Quickly see if file is a ZIP file by checking the magic number."""
result = False
if hasattr(filename, "read"):
result = _check_zipfile(fp=filename)
with open(filename, "rb") as fp:
result = _check_zipfile(fp)
More information about the Python-list