[issue6818] remove/delete method for zipfile/tarfile objects

Troy Potts report at bugs.python.org
Sat Jul 3 07:26:42 CEST 2010


Troy Potts <troy.potts at gmail.com> added the comment:

I have attempted to implement a ZipFile.remove function.  It seems to work fine.  I have submitted a patch.

The method of implementation is: find the file's index in the file list, then sum the lengths of the file entries before it to find its location in the archive.  Then simply read in all the bytes after it, write them out at that location, and truncate the file x bytes shorter, where x is the length of the record.  This works because the directory listing is created when the file is closed, so there's no harm in truncating.

I've also made it truncate the zip file after reading in the existing files upon creation, because the directory information is not used after this point.

This could use some testing on large files.

This is my first patch, so let me know if I've done anything wrong.

----------
keywords: +patch
nosy: +chroipahtz
Added file: http://bugs.python.org/file17847/zipfile_remove.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6818>
_______________________________________


More information about the Python-bugs-list mailing list