[Python-Dev] Request for Pronouncement: PEP 441 (original) (raw)
[Python-Dev] Request for Pronouncement: PEP 441 - Improving Python ZIP Application Support
Thomas Wouters thomas at python.org
Mon Feb 23 21:00:38 CET 2015
- Previous message: [Python-Dev] Request for Pronouncement: PEP 441 - Improving Python ZIP Application Support
- Next message: [Python-Dev] Request for Pronouncement: PEP 441 - Improving Python ZIP Application Support
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Feb 23, 2015 at 8:24 PM, Paul Moore <p.f.moore at gmail.com> wrote:
On 23 February 2015 at 19:01, Daniel Holth <dholth at gmail.com> wrote: > Sounds reasonable. It could be done by just reading the entire file > contents after the shebang and re-writing them with the necessary > offset all in RAM, truncating the file if necessary, without involving > the zipfile module very much; the shebang could have some amount of > padding by default; the file could just be re-compressed in memory > depending on your appetite for complexity.
The biggest problem with that is finding the end of the prefix data. Frankly it's easier just to write a new prefix then use the zipfile module to rewrite all of the content. That's what the current code does writing to a new file.
I don't think you need to rewrite all of the contents, if you don't mind poking into zipfile internals:
endrec = zipfile._EndRecData(f) prefix_length = endrec[zipfile._ECD_LOCATION] - endrec[zipfile._ECD_SIZE] - endrec[zipfile._ECD_OFFSET]
I do something similar to get at the prefix, although I need the zipfile opened anyway, so I use:
endrec = zipfile._EndRecData(f) # pylint: disable=protected-access zf = zipfile.ZipFile(f)
endrec is None if reading it failed, but then ZipFile should have
raised an exception...
assert endrec prefix_len = zf.start_dir - endrec[zipfile._ECD_OFFSET] # pylint: disable=protected-access
Paul
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/thomas%40python.org
-- Thomas Wouters <thomas at python.org>
Hi! I'm an email virus! Think twice before sending your email to help me spread! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20150223/1da40a10/attachment.html>
- Previous message: [Python-Dev] Request for Pronouncement: PEP 441 - Improving Python ZIP Application Support
- Next message: [Python-Dev] Request for Pronouncement: PEP 441 - Improving Python ZIP Application Support
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]