3

We commonly know that compression is the reduction in size of data in order to save space or transmission time, I should expect bigger size when I extract compressed file. I have downloaded a file in tar format(95KB) and when I extracted it its size reduced(5.7KB) and under that there were some other files which are even showing 0byte now. What may be the reason of it.

1 Answer 1

7

Tar format is not compressed. But it does add headers at the start of each file or directory in the archive. The headers are used by tar to tell it the name of the file, the timestamp, etc. That information isn't part of the data inside the file but tar needs it to recreate the file. Each header is usually 512 bytes but could be larger if the filename is longer than 100 characters. The end of a tar archive is marked by a blank header. Those headers usually explain any difference in size between the archive and everything extracted from it.

There could also be differences that can't be explained by the size of the tar headers but they're mostly corner cases and hard to diagnose without seeing the tar file or at least a listing of it. One possible explanation for a huge difference, a huge tar file but very little extracted from it, is if the archive contains lots of copies of the same file. This could happen if someone kept adding newer versions onto the end, perhaps as a backup strategy. The tar extraction would simply keep overwriting that same file each time without using more space.

3
  • Thanks, So you are saying those headers get removed when I extract the file ? Sep 30, 2012 at 14:32
  • So to speak. The headers are used by tar to tell it the name of the file, the timestamp, etc. That information isn't part of the data inside the file but tar needs it to recreate the file. Sep 30, 2012 at 15:09
  • I've updated my answer a bit. I hope that's helpful. Thanks for the accept. Feb 8, 2013 at 18:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .