PHP Decompressor for LZ-UTF8
LZ-UTF8 is a string compression library and format. Is an extension to the UTF-8 character encoding, augmenting the UTF-8 bytestream with optional compression based the LZ77 algorithm.
Code was tested on PHP 7.2 and 7.3
PHPUnit 8.5 test requires PHP >= 7.2
Include it to your project via composer.json after adding the folder to your current project.
This package is not available yet on packagist. So you have to install it manually
{
"repositories": [
{
"type": "path",
"url": "kny00/lzutf8-php",
"options": {
"symlink": true
}
}
],
"require": {
"kny00/lzutf8-php": "0.0.1",
"ext-mbstring": "*"
}
}Then update composer
composer updateThis is a one class script, so you can simply include it to your current project
include "kny00/lzutf8/src/Lzutf8/Lzutf8.php"use use Knaya\Lzutf8\Lzutf8 as Lzutf8;
/**
* Creating a compressed 9 chars string
* 2 last bytes contain a codepoint sequence
* [206, 7]
* distance should be equal to 7 and length to 14
*/
$compressedArray = [
65, 66, 67, 68, 69, 70, 71, 206, 7
];
$compressedStr = call_user_func_array(
"pack",
array_merge(array("C*"), $compressedArray)
);
$class = new Lzutf8();
$decompressed = $class->decompress($compressedStr);
// Decompress outputs 21 UTF-8 charsCopyright (c) 2020, KNY <kny.contact@gmail.com>.