How Does File Compression Work?
Have you ever tried to compress a file with a size of only one byte? Open notepad, type one letter and save it as file.txt, then compress the file as file.zip, you will see the .zip file size is 123 bytes; then compress the file as .rar, you will see the .rar file size is 77. The ‘compressed’ file actually is much bigger than the original file. That means, .zip file format need 122 bytes for itself to record the compression information, while rar file format 76.
Now you open the .zip in the Notepad, among the jumbled texts, you can recognize the file name which occurs twice; PK at the beginning, and if you compress several files, ‘PK’ occurs again and again. That’s because the .zip format was originally created in 1989 by Phil Katz for PKZIP. A ZIP file has a central directory located at the end of the file. The directory stores a list of the names of the entries (files or directories, here we only have one file.) stored in the ZIP file, along with other metadata about the entry, and an offset into the ZIP file, pointing to the actual entry data.
Now open .rar file, you can recognize RAR at the beginning and a file name.
Enough experiment, now let see how file compression works in general.
Different types of flies require different compression techniques. One technique for compressing text is based on the use of a document-specific dictionary that contains only the words found in that file. Each word in the dictionary is indexed by a number, and the original document is encoded as a list of indices that represent those dictionary entries. For a medium-sized document, the space needed to store the dictionary and the index list will be less than the space needed to store the ASCII-text encoding of the original document. A very long text file that contains many instances of repeated words might be reduced by as much as 50-60% of its original size.
But it's not worth to 'compress' a very small file, you may get a compressed file bigger than original file.
More by this Author
I use Virgin Media (VM) for my broadband, TV, and Telephone. I use a wireless router for my home network. I have three laptops. In this article, I will share with you some of my knowledge that I have learnt through...
Frost is a p2p app that works on top of Freenet. You need to have Freenet working to use Frost. Freenet is an Network over the Internet which provides true anonymity. With starting Freenet on your machine you are...
Learn why your gas fire keeps going out even when it still seems on and how to fix this.