How to read a 206 MB zip without downloading it
Coquitlam, a city outside Vancouver, publishes its topographic survey as one 206 MB zip on S3. I wanted two files out of it: the spot elevations (1.9 million points) and the contour lines. Downloading 206 MB to read 14 MB is a waste of bandwidth and time, and S3 objects answer HTTP Range requests. So you can read the end of the zip, find the entries you want, and fetch only those bytes. Actual…
To read a 206 MB zip file without downloading the entire archive, one can take advantage of HTTP Range requests supported by S3 objects. This approach allows fetching only the necessary bytes from the zip file, saving bandwidth and time. In the case of Coquitlam's topographic survey, the 206 MB zip contains spot elevations (1.9 million points) and contour lines.
The process involves fetching the tail of the file, parsing the End of Central Directory Record (EOCD), and then fetching the central directory to identify the desired entries. Once the relevant entries are identified, individual local headers are fetched, and each entry is inflated using the deflate compression method. The code provided demonstrates how to implement this process using Python, zlib library for decompression, and urllib for making HTTP requests.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to