Can zlib-compressed string contain whitespace?
-
22-08-2019 - |
Question
Can zlib-compressed string contain whitespace? By whitespace I mean ' ', \n, \t.
Solution
Yes; it's just a stream of bytes. Any byte value can appear in there (including zero, which is more likely to cause you problems than whitespace characters!)
OTHER TIPS
Any byte can appear in a zlib-compresed string.
In fact, for a long enough properly compressed string, any byte (from 0 to 255) should have a more-or-less equal probability, or else the string could be further compressed.
You can try this yourself -- for example using Python:
>>> z = open('/dev/urandom').read(1000000).encode('zlib') # compress a long string of junk
>>> [z.count(chr(i)) for i in range(256)] # number of occurrences of each byte
[3936, 3861, 3978, 3951, 3858, 3937, 3945, 3828, 3984, 3871, 3985,
3961, 3879, 3924, 3817, 3984, 3963, 3858, 4029, 3903, 3884, 3817,
... yada ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow