Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the fastest way to access files in a zip file?

What is the fastest way to read individual files (in a random fashion) from a zip file?

As I understand it, zip files have a directory that stores the individual file entries, and I could scan this directory to build an external index. Are there any standardized ways (i.e. existing libraries) that already do that? Or could I use a specialized type of zip file?

like image 613
Tony the Pony Avatar asked Dec 19 '25 22:12

Tony the Pony


1 Answers

Scanning the directory and building the index is the fastest and best way to provide random access to the compressed entries archived in a zip file. The directory is usually small and lies at the end of the archive. If you have seekable media, then this is what you want.

The zip format is documented pretty well; it's not too hard to do. The devil is in the details, though. If your zip files use ZIP64 extensions, encryption, split archives.. that's when it gets tricky. For simple zip files, doing what you imagine is not so difficult.

Still it would be easier to use an external library.

like image 91
Cheeso Avatar answered Dec 22 '25 13:12

Cheeso



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!