mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
ZlibCompressor: use libdeflate if available
I may make libdeflate mandatory later on, but right now we haven't been able to ship it on all platforms yet.
This commit is contained in:
parent
eabfd2a37b
commit
03837c1b71
@ -24,6 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\network\mcpe\compression;
|
||||
|
||||
use pocketmine\utils\SingletonTrait;
|
||||
use function function_exists;
|
||||
use function libdeflate_deflate_compress;
|
||||
use function strlen;
|
||||
use function zlib_decode;
|
||||
use function zlib_encode;
|
||||
@ -72,6 +74,11 @@ final class ZlibCompressor implements Compressor{
|
||||
}
|
||||
|
||||
public function compress(string $payload) : string{
|
||||
if(function_exists('libdeflate_deflate_compress')){
|
||||
return $this->willCompress($payload) ?
|
||||
libdeflate_deflate_compress($payload, $this->level) :
|
||||
zlib_encode($payload, ZLIB_ENCODING_RAW, 0);
|
||||
}
|
||||
return zlib_encode($payload, ZLIB_ENCODING_RAW, $this->willCompress($payload) ? $this->level : 0);
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,10 @@ declare(strict_types=1);
|
||||
|
||||
define('pocketmine\_PHPSTAN_ANALYSIS', true);
|
||||
|
||||
if(!extension_loaded('libdeflate')){
|
||||
function libdeflate_deflate_compress(string $data, int $level = 6) : string{}
|
||||
}
|
||||
|
||||
//TODO: these need to be defined properly or removed
|
||||
define('pocketmine\COMPOSER_AUTOLOADER_PATH', dirname(__DIR__, 2) . '/vendor/autoload.php');
|
||||
define('pocketmine\PLUGIN_PATH', '');
|
||||
|
Loading…
x
Reference in New Issue
Block a user