How does file compression work?

2010-08-30 4:19 pm
Do I always have to save the compressed folder to be able to view the files contained in it? That's what I am having to do now, is that the way it's supposed to work?

How does file compression work? I can understand compressing video or imaging, you get a lower resolution or smaller pictures but what about documents. There has to be a trade off similar to speed and torque, they are inversely proportional. One goes up and the other goes down.

回答 (5)

2010-08-30 4:48 pm
✔ 最佳答案
There are two kinds of compression - lossy and lossless.

As you noted, most videos and images are compressed using lossy compression algorithms. This means that we physically lose information when we compress the files. This loss of data is why the resolution goes down, or "artifacts" appear in the images. Quite literally, the compressed file and the original file are different, and you cannot get back the original file (exactly) from the compressed file. For lossy compression, as you noted, the tradeoff is that you can obtain a better compression ratio (smaller file size) in exchange for lower resolution / quality.

However, for files that aren't videos and images, you really cannot afford to have the compressed file be different from the original file. (For instance, if you compressed a text file, you'd really like to have the original text back; absolutely no changes in the text may occur.) Lossless compression is able to take the original file and compress it such that when you uncompress the file, you get back the original file (exactly, bit-for-bit identical). In general, lossless compression cannot obtain as good a compression ratio as lossy compression -- of course, this is because lossless compression cannot destroy information -- the original file is recreated exactly. You can losslessly compress images and videos too; for instance, the .png file format is lossless.

So why aren't all files losslessly compressed? It takes time to uncompress files, so if you stored all files in compressed format, opening and reading the files will take longer. In Windows Vista and 7, you can actually view and load stuff inside zipped (compressed) folders without explicitly unzipping (uncompressing) them, but this does take longer than if the files weren't compressed to begin with. For almost all cases though, the time difference is not noticable.


Zipped folders (i.e. compressed folders) actually serve two functions. The first, as you noted, is that it compresses the files inside, which usually makes the file size smaller. The second functionality is that it takes the folder and all the files inside, and turns them into a single file (just for convenience). So if I wanted to email 1000 files to someone else, I'd zip them up first, so I need to attach only a single file, rather than 1000. So a .zip file is a single file, but it stores the information of an entire folder(s) and all the files inside.
2016-10-05 2:31 am
How Does File Compression Work
2016-09-14 6:22 pm
Many valid answers already for this
2016-08-07 6:15 am
This has already been answered
2010-08-30 11:12 pm
Light Cloud is right on the money. Lossless compression's easier to understand than you might think - we humans do it all the time. Here's another way to understand lossless compression: it's much faster to write "one million zeroes" than it is to actually write them out. Lossless compression works in much the same way: in a simple "byte-run compression", the computer writes the number of repetitions of a byte or pattern and then the byte or pattern itself.


收錄日期: 2021-05-01 13:21:30
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20100830081912AAVNGJ9

檢視 Wayback Machine 備份