The php code is
”’
$input_file = "a.txt";
$source = file_get_contents($input_file);
$source = gzcompress($source);
file_put_contents("php.txt",$source)
”’
The python code is
”’
testFile = "a.txt"
content = None
with open(testFile,"rb") as f:
content = f.read()
outContent = zlib.compress(content)
with open("py.txt","wb") as f:
f.write(outContent)
”’
The python3 version is [Python 3.6.9] The php version is [PHP 7.2.17]
I need the same result for same md5.
2
Answers
I find the solution. The code is
The python zlib provide a interface "zlib.compressobj",which returns a compressobj,and the parameters decide the result. You can adjust parameters to make sure the python's result is same with php's
The problem is not in PHP or Python, but rather in your "need". You cannot expect to get the same result, unless the two environments happen to be using the same version of the same compression code with the same settings. Since you do not have control of the version of code being used, your "need" can never be guaranteed to be met.
You should instead be doing your md5 on the decompressed data, not the compressed data.