I didn't have room for a zip and its files, so I learned how to skip the zip
A while ago I had to unpack a 60 GB zip. The files would have fit on my laptop. The zip plus the files didn't. That's the annoying part of "download it, extract it, delete the zip". For a moment you need room for both.
A while ago I had to unpack a 60 GB zip. The files would have fit on my laptop. The zip plus the files didn't.
That's the annoying part of "download it, extract it, delete the zip". For a moment you need room for both. Usually that's fine. That day it wasn't, and I got stuck on a question: do I actually need the zip on my disk at all?
Turns out, not really.
The trick
A zip file keeps its table of contents at the very end. It's called the central directory, and it lists every file in the archive, how big it is and where exactly it starts inside the zip.
The second piece is something most servers already support: HTTP Range requests. You can ask a server for just a slice of a file, like "give me bytes 1000 to 2000". It's the same thing that lets you skip ahead in a video or resume a download.
Put those together and you get this:
- Ask the server how big the zip is.
- Download only the end of it and read the table of contents.
- Now you know every file and where it lives, so download just the bytes of the files you want.
- Unpack each one as it arrives and write it straight into a folder.
The zip itself never gets saved anywhere.
The numbers
This is the part that still feels a bit like cheating to me.
COCO train2017 is a popular machine learning dataset: an 18.01 GB zip with 118,287 photos. Getting one photo out of it downloaded 12.2 MB in total, and 11.9 MB of that was just the table of contents. It took between 3.7 and 6.8 seconds over four runs.
For a full archive: the Blender 4.2 zip is 365.8 MB with 5,518 files. Extracting all of it wrote 925.6 MB of files with 0 B of zip on disk, in 15 to 22 seconds on my home connection. The normal way, you'd need 1.26 GB free for the zip and the files together.
To be clear, for a whole archive it downloads about the same amount as a normal download. It's not faster magic. You save the space the zip would take, and when you only need part of an archive, you only download that part.
From a script to an extension
It started as a small command line tool in Rust, just for me. You gave it a link and a folder, and it did the rest.
Then I got tired of copying links into a terminal and wanted it on a right-click. So it became a Chrome extension. The catch: an extension can't really write a whole folder tree to your disk on its own. So there's a small Windows helper program, and the extension talks to it through Chrome's native messaging. The extension shows the list and the buttons, the helper does the downloading and writing.
Now it's: right-click a zip link, see what's inside and how much space it needs, pick the files, done.
Things that broke along the way
GitHub doesn't play along. The "Download ZIP" button on GitHub doesn't support Range requests at all, so the whole trick falls apart there. I ended up writing a second mode that reads the zip once from start to finish and unpacks files as they go by. No preview, but still no zip on disk.
Zips can be nasty. A zip can contain a file called CON or NUL.txt, which Windows simply refuses to create. Worse, it can contain paths like ../../something that try to write outside the folder you picked. All of that has to be checked before a single byte gets written.
Every file gets checked. Each file is written under a temporary name first, its checksum and size are compared with what the zip says, and only then does it get its real name. If the connection drops halfway, you don't end up with a half-written file that looks fine.
The Chrome Web Store review. An extension that talks to a native program and can ask for cookies (for downloads that need your login) gets a careful review. Explaining every permission clearly took a while, but it went public this week.
The honest limits
- Windows only for now
- It needs the helper installed (per user, no admin rights)
- No RAR or 7z yet, and no password-protected zips
- The installer isn't code-signed yet, so Windows SmartScreen shows a warning the first time
Try it or read the code
It's free and open source, no account and no tracking. It's called LinkUnzip.
- Code: https://github.com/CincaAlex/LinkUnzip
- Website: https://linkunzip.app
I'm curious whether other people run into this too, or if it's just me. And if you know a zip link it chokes on, I'd really like to hear about it.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.