kny00/lzutf8-php

Lzutf8 implementation for php

dev-master 2020-05-15 19:44 UTC

This package is auto-updated.

Last update: 2025-08-07 23:51:29 UTC


README

License License License codecov

lzutf8-php

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.

Compatibility

Code was tested on PHP 7.2 and 7.3

PHPUnit 8.5 test requires PHP >= 7.2

Getting started

Set Up

Via Composer

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 update

Via Include

This is a one class script, so you can simply include it to your current project

include "kny00/lzutf8/src/Lzutf8/Lzutf8.php"

Use it

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 chars

License

Copyright (c) 2020, KNY <kny.contact@gmail.com>.