0

I was wondering whether there are any scenarios which require file(s) to be compressed multiple times with the same or a different algorithm. As far as i can tell the file size can be reduced further by applying further compression dependent on the nuances of a compression algorithm. (what files or data it is optimised for). Perhaps certain technologies expect a certain file type? If you apply multiple rounds of compression could it result in an increasing file size, as information is added to denote that a certain compression encoding has been used?

1

No, usually it doesn't make sense to compress multiple times unless you happen to have different layers trying to do compression (e.g. you have a PNG image, stored in a compressed tar archive (.tar.gz), stored on a filesystem or transferred over a link that does compression).

Multiple compression doesn't do any good, as any general compression algorithm will try to squeeze the actual information to as small a file as possible, essentially making it look as random (high-entropy) as possible. Random data doesn't compress very well, so the later compression layers don't do much. Of course, if the initial compression is trivial (e.g. only run-length encoding), then a more sophisticated algorithm might still be able to compress the data further. But in that case, you'd probably be better off using the better algorithm on the original data.

Multiple rounds of compression will easily increase the file size, exactly because there are usually some headers involved. For file compression, it's useful to know what compression algorithm was used, and e.g. gzip also stores the original file name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.