Why zlib encoder encodes into different string from python's zlib #432
-
Hey guys I just find a problem working with the lib. I found for a same string, set with same compression level, the encode result from Although all the two string works, and the decoded string is same, I still want to know what is the defualtly different from flate2's encoder and python's zlib encoder. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
GPT says:
Here is a link to all the details. |
Beta Was this translation helpful? Give feedback.
-
The default rust backend is originally a port of miniz which uses some slightly different parameters and algorithms for match searching and block splitting compared to the standard zlib library which results in slightly different results. (Why it was done that way in the original miniz librar I don't know, maybe for ease of implementation or something.) I believe the python function uses the standard c zlib library under the hood. Worth noting that zlib-ng also produces slightly different results compared to normal zlib due to some speed tradeoffs (I believe they use a minimum match size of 4 instead 3 at least as noted here), and some linux distros, notably fedora have moved to swap out standard zlib to zlib-ng in compat mode so even using zlib you aren't guaranteed a reproducible result unless you vendor it. |
Beta Was this translation helpful? Give feedback.
The default rust backend is originally a port of miniz which uses some slightly different parameters and algorithms for match searching and block splitting compared to the standard zlib library which results in slightly different results. (Why it was done that way in the original miniz librar I don't know, maybe for ease of implementation or something.) I believe the python function uses the standard c zlib library under the hood.
Worth noting that zlib-ng also produces slightly different results compared to normal zlib due to some speed tradeoffs (I believe they use a minimum match size of 4 instead 3 at least as noted here), and some linux distros, notably fedora have moved to swap out …