Home > OS >  How to skip detection of random data when attempting to compress?
How to skip detection of random data when attempting to compress?

Time:08-29

Do popular compressors such as gzip, 7z, or others using deflate, detect random data strings and skip attempting to compress said strings for sake of speed?

If so, can I switch off this setting?

Otherwise, how can I implement deflate to attempt to compress a random data string?

I've found zlib deflate, and it does not mention the word "random" in the source, however, I'm concerned that higher up in zlib that it detects a random block of bits/bytes and skips over it, overriding deflate.

How can I be sure that a compressor, such as zlib, attempts to compress a block of random data?

Can you give an example command-line expression or code?

CodePudding user response:

Unless you request level 0 (no compression), zlib always attempts to compress the data. For a every deflate block, it compares the size of that block using dynamic codes, static codes, and stored (no compression), and emits the smallest of the three. That is all.

There is no detection of "random" data, even if such a thing were possible. (It's not possible, of course. For example, encrypted data is definitely not random, but is indistinguishable from random data if you don't know how to decrypt it.)

  • Related