[Python-ideas] Add a .pop() method to ZipFile

Masklinn masklinn at masklinn.net
Fri May 10 15:22:08 CEST 2013


On 2013-05-10, at 15:01 , Antoine Pitrou wrote:

> Le Fri, 10 May 2013 08:32:17 -0400,
> Daniel Holth <dholth at gmail.com> a écrit :
>> Check out this efficient way to remove the last file from any
>> ordinary zip file.
> 
> But why would you care such an operation? A generic remove() operation
> would sound more useful.

Guessing it's because a generic `remove()` is less trivial to implement,
which would also be why the suggestion is for .pop() but not
.pop([index]): removing files at the end means you can just truncate the
archive and append the central directory[0], removing files in the middle
means either zeroing and leaving a hole or moving all following files.

Although technically it's only simple if you assume file content and
central directory entries are in the same order, which is unwarranted.

So, guessing it's because you can do a half-assed job at implementing
pop(), it will usually work (and will silently corrupt your archive
when it does not)

[0] you may also need to rewrite all offsets in the central directory, I
don't remember if they are offset from file start or central directory
record start.


More information about the Python-ideas mailing list