How does file compression/ZIP files work?

350 viewsEngineeringOther

I understand it’s to save file space, but like…how?

Follow-up: If you have to compress a photo to save on file size (when emailing, for example) couldn’t it just send essentially a text file on how to uncompress it back to its original size and quality? (ex. “Set the resolution to XxY and add X color at Y pixels”)

Thank you!

In: Engineering

9 Answers

Anonymous 0 Comments

When you compress a ZIP file, you can choose to compress the file using the DEFLATE method. The compressed data for each file is added to the ZIP archive, and the location of each file in the archive is checked.

Once all the files are added, a directory called Central Directory is created at the end of the collection. This directory contains information about each compressed file, such as its name and location in the archive. Finally, the End of Central Directory record is written to the end of the file to help locate the Central Directory.

When you open a ZIP file to view or extract its contents, the first step is to locate the End of Central Directory at the end of the file. This gives you the information you need to find the Central Directory, with a record of every file in the directory. Each record tells you where to find the corresponding compressed file data in the archive.

Interestingly, all pointers in the ZIP file are relative. For example, instead of saying, “Go to byte 500,” it might say, “So go back to byte 100.” This option allows you to attach ZIP files to other files such as executable programs, and provides archive extraction. Using such a program can scan and extract the attached ZIP data.

You are viewing 1 out of 9 answers, click here to view all answers.