On 15 February 2015 at 16:00, Serhiy Storchaka <storch...@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
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to