[New-bugs-announce] [issue10748] zipfile does not write empty ZIP structure if close() called after __init__() as doc suggests
report at bugs.python.org
Tue Dec 21 17:30:28 CET 2010
New submission from Ian Stevens <iancstevens at gmail.com>:
The zipfile documentation (http://docs.python.org/library/zipfile.html) states:
"If the file is created with mode 'a' or 'w' and then close()d without adding any files to the archive, the appropriate ZIP structures for an empty archive will be written to the file."
This is not the case, eg.::
>>> from StringIO import StringIO
>>> import zipfile
>>> s = StringIO()
>>> z = zipfile.ZipFile(s, 'w')
The code for zipfile (http://svn.python.org/projects/python/trunk/Lib/zipfile.py) does not support the documentation either. The ending records are written only if ZipFile._didModify is True, and that attribute is only set to True if writestr() or write() are called.
Either the code should be fixed to support writing the ending records on an empty zip, or the documentation should be changed to reflect the existing behaviour.
Test case (for Lib/test/test_zipfile)::
# Test that close() called on a ZipFile without write creates a valid ZIP.
zf = zipfile.ZipFile(TESTFN, "w")
chk = zipfile.is_zipfile(TESTFN)
assignee: docs at python
components: Documentation, Library (Lib)
nosy: Ian.Stevens, docs at python
title: zipfile does not write empty ZIP structure if close() called after __init__() as doc suggests
versions: Python 2.6
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce