反馈后编辑答案
这有点麻烦,但是可以用PHP compression filters来完成。在$params = array('window' => 31);
$fp = fopen('your_data', 'rb');
stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ, $params);
print fread($fp, 1024);
唯一的问题是你需要从一个流中获取压缩数据。。。我不是PHP的人,所以我将把它留给你来解决。在
以下PHP>;=5.4.0的原始答案
简短回答:尝试gzdecode()或{}而不是{}。在
长时间回答…
在python(python 3)中:
^{pr2}$
这意味着数据最初是使用31的窗口大小进行压缩的。在PHP中,大多数zlib函数的默认窗口大小为15,因此gzuncompress()和{}失败。然而,似乎gzdecode()和{}确实起作用了(我实际上不知道为什么):
使用python3压缩>>> import zlib
>>> compressor = zlib.compressobj(wbits=(16+zlib.MAX_WBITS))
>>> compressed = compressor.compress(b'Here is a test string compressed by Python with a window size of 31\n')
>>> compressed += compressor.flush()
>>> compressed
b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\r\xca\xb1\r\x800\x0c\x04\xc0\x9e)~\x05\xc4\x12\x94\xac\x00\xe4!.\x12#\xdb\x92\x15\xa6\x87\xabo\xa5\x11\xe2\xd8\x11\xf4\x80\x87I\xbfqj{\x8c\xee,8\x06\xb6\x11U;R\xa2\xfe/\xa5\x17M\xb8\xbc\x84^X\xe6\xe9\x03\xabEV\xdbD\x00\x00\x00'
>>> open('/tmp/compressed', 'wb').write(compressed)
85
使用PHP解压缩php > $compressed = file_get_contents('/tmp/compressed');
php > print gzuncompress($compressed);
PHP Warning: gzuncompress(): data error in php shell code on line 1
php > print gzinflate($compressed);
PHP Warning: gzinflate(): data error in php shell code on line 1
php > print gzdecode($compressed);
Here is a test string compressed by Python with a window size of 31
php > print zlib_decode($compressed);
Here is a test string compressed by Python with a window size of 31