[Python-Dev] Keyword meanings [was: Accept just PEP-0426]

Ronald Oussoren ronaldoussoren at mac.com
Thu Dec 6 16:21:30 CET 2012

On 6 Dec, 2012, at 15:58, Vinay Sajip <vinay_sajip at yahoo.co.uk> wrote:

> Daniel Holth <dholth <at> gmail.com> writes:
>> The wheel implementation makes sure all the metadata (the .dist-info directory)
>> is at the end of the .zip archive. It's possible to read the metadata with a
>> single HTTP partial request for the end of the archive without downloading the
>> entire archive.
> Sounds good, but can you point to any example code which does this? As I
> understand it, for .zip files you have to read the last part of the file to get a
> pointer to the directory, then read that to find where each file in the archive
> is, then seek to a specific position to read the file contents.

Because zipfiles can be appended to other files (for example when creating a self-extracting archive) the zipfile module maintains the file offset of the start of a zipfile. The code in the stdlib doesn't appear to test that the zipfile is at a positive offset in the file, therefore with some luck the following will work: 

* Download the last 10K of the archive (adjust the size to taste, it should be large enough to contain the zipfile directory and the file you are trying to read)

* Create a zipfile.ZipFile

* Read the zipfile member.

If that doesn't work you'll have to create a temporary file of the right size and place the downloaded bit at the end of that file.

BTW. Another (more hacky) alternative is to place the interesting bits of dist-info at the start of the zipfile, then you only need to download the first bit of the archive and can then extract the bits you need by parsing the local file headers (zipfiles contain both a directory at the end of the zipfile and a local header stored just before the file data). 

> Regards,
> Vinay Sajip
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/ronaldoussoren%40mac.com

More information about the Python-Dev mailing list