[Python-Dev] PEP 441 - Improving Python ZIP Application Support

Paul Moore p.f.moore at gmail.com
Sun Feb 15 17:27:10 CET 2015


On 15 February 2015 at 16:00, Serhiy Storchaka <storchaka at gmail.com> wrote:
>> Would it be reasonable to add methods to the
>> ZipFile class to read and write the prefix data?
>
>
> But the stdlib zipfile module supports this.
>
> with open(filename, 'wb') as f:
>     f.write(shebang)
>     with zipfile.PyZipFile(f, 'a') as zf:

Good point.

It's not quite as easy to read the prefix data. I think you can do it
by reopening the file, and reading the bytes up to byte
min(i.header_offset for i in zf.infolist()). You need to reopen the
file, though, and that calculation doesn't work for an empty zipfile
(where you need to read to the start of the central directory
instead). But it's sort of possible, and it's a pretty specialised
requirement anyway (I only really needed it for testing).

Thanks,
Paul


More information about the Python-Dev mailing list