[issue6818] remove/delete method for zipfile/tarfile objects
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.
Added file: http://bugs.python.org/file17847/zipfile_remove.patch
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list