Is there a character that never appears in the output of zlib.compress?

Richard Damon Richard at Damon-Family.org
Wed Jan 29 07:31:17 EST 2020


On 1/29/20 12:09 AM, Peng Yu wrote:
> Hi,
>
> I'd like to tell what part is zlib.compress data in an input stream.
> One way is to use some characters that never appear in zlib.compress
> output to denote the boundary. Are there such characters? Thanks.
>
A compression routine that avoid one byte value would be less efficient 
at compression then one that uses all the values.

An alternative might be to precede the compressed data with a byte count 
of how much data will follow (as well as whatever file code you use to 
indicate that the next data IS compressed data.

A second method would be to take some byte value, (like FF) and where 
ever it occurs in the compressed data, replace it with a doubled value 
FF FF, and then add a single FF to the end.

-- 
Richard Damon



More information about the Python-list mailing list