Discussion Locked

Zip compression

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
My questions are about zip compression and it's inner workings. How exactly does zip compression work? Why do some files get compressed smaller than other programs? What files can and cannot be compressed? Can a compressed file be compressed again even smaller?

9 replies

by timthetoolman

Hi,

The following link is to a site that has absolutely everything you wanted to know about the ZIP format and algorithms. It has pseudo-code examples of the algorithms used and is very informative - if very technical...

http://www.dogma.net/DataCompression/Zip.shtml

(remove spaces from above URL)

Here is an extract from the link from that page entitled... "Zip File Format".

let Last-Character <- 0.
loop until done
if the follower set S(Last-Character) is empty then read 8 bits from the input stream, and copy this
value to the output stream.
otherwise if the follower set S(Last-Character) is non-empty then
read 1 bit from the input stream.
if this bit is not zero then read 8 bits from the input stream, and copy this
value to the output stream.
otherwise if this bit is zero then
read B(N(Last-Character)) bits from the input
stream, and assign this value to I. Copy the value of S(Last-Character)[I] to the
output stream.

assign the last value placed on the output stream to
Last-Character.
end loop

...as you can see, there's no simple english answer to how the algorithmworks other than to say it manipulates the bit patterns in the file in a predictable, reversible manner...

There are theories surrounding "Maximum lossless compression" - I'm sure you'll find some on that site - hence there is a limit beyond which no practical further compression can be performed.

Again there is no easy English way to describe why some files can compress better than others except to say that some files respond to the algorithms better than others.

Hope this helps,
Cheers,
Tim.

by timthetoolman

TecgRepublic seems to have lost the indentation in that algoritm example and makes it quite hard to read. The full thing - along with the decompression pseudo-code its available on the site I mentioned, though.

by thechas

In simplist terms, zip programs work by analyzing the data in the file, and eliminating blank spaces and redundant data.
They then create a key to re-create these spaces and redundant data when the file is extracted.

Files that are tight and compact, or allready compresed (jpegs are one) may actually zip larger than the original file.

by shanghai sam

Short and simple (who needs to know the actual workings)

files that are already compressed connot be compressed further: ZIP ACE RAR CAB some EXE many more. WINZIP its self is compressed before you install it

You can put any unused file into a ZIP Archive, which is a good way to keep stuff in catogies ie word docs in YMWORD.zip, freeware games in GAMES.ZIP

word doc compress well because repetitive data from the, page setup,margins, font and so on.

if you made a txt file containing 100,000 0s you would get a 100k (1character => 1byte) file, if you were to compress it, you'ld be left with a file a only a few kb's

If you made a txt file containing 100,000 charactors which were ramdom with no sequences repeted you would still get a 100k file, but if you compressed it it would be slightly larger

****YOU DO NOT**** want to compress files to save space which are in use by windows or that are going to be used next time you boot up,

*****************DO NOT TRY***********************
If you were to compress AUTOEXEC.BAT then remove it leaving AUTOEXEC.ZIP, when you reboot , windows goes to look for AUTOEXEC.BAT but cannot find it or read AUTOEXEC.ZIP because WinZIP needs windows to run, on some systems this may cause the system not to run
**************************************************

This discussion is closed to new replies.