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


Comments 2 comments

jim.sheng profile image

jim.sheng 4 years ago from UK Author

mp3 itself is a kind of compression format which reduces the quality of sound that are considered to be out of the human hearing ability, for example some very high pitch noises.

Image compression are similar, higher compression rate, less accurate are the images. The loss of fidelity are acceptable to human eyes. for example image colour may be reduced by compression, but imperceptible to human visual ability.


Franklin 4 years ago

nice....

then how does a non text file like video mp3 and images compressed...

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working