PHP code example of kjdev / zstd

1. Go to this page and download the library: Download kjdev/zstd library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kjdev / zstd example snippets


// Using functions
$data = zstd_compress('test');
zstd_uncompress($data);

// Using namespaced functions
$data = \Zstd\compress('test');
\Zstd\uncompress($data);

// Using streams
file_put_contents("compress.zstd:///path/to/data.zstd", $data);
readfile("compress.zstd:///path/to/data.zstd");

// Providing level of compression, when using streams 
$context = stream_context_create([
    'zstd' => [
            'level' => ZSTD_COMPRESS_LEVEL_MIN,
            // 'dict' => $dict,
        ],
    ],
);

file_put_contents("compress.zstd:///path/to/data.zstd", $data, context: $context);
readfile("compress.zstd:///path/to/data.zstd", context: $context);
 bash
dnf install php-zstd
 bash
yum install php-zstd
 php
zstd_compress ( string $data, int $level = ZSTD_COMPRESS_LEVEL_DEFAULT, ?string $dict = null ): string|false
 php
zstd_uncompress ( string $data, ?string $dict = null ): string|false
 php
zstd_compress_dict ( string $data , string $dict, int $level = ZSTD_COMPRESS_LEVEL_DEFAULT ): string|false
 php
zstd_uncompress_dict ( string $data , string $dict ): string|false
 php
zstd_compress_init ( int $level = ZSTD_COMPRESS_LEVEL_DEFAULT, ?string $dict = null ): Zstd\Compress\Context|false
 php
zstd_compress_add ( Zstd\Compress\Context $context, string $data, bool $end = false ): string|false
 php
zstd_uncompress_init ( ?string $dict = null ): Zstd\UnCompress\Context|false
 php
zstd_uncompress_add ( Zstd\UnCompress\Context $context, string $data ): string|false
 php
Namespace Zstd;

function compress( string $data, int $level = ZSTD_COMPRESS_LEVEL_DEFAULT ): string|false {}
function uncompress( string $data ): string|false {}
function compress_dict ( string $data, string $dict, int $level = ZSTD_COMPRESS_LEVEL_DEFAULT ): string|false {}
function uncompress_dict ( string $data, string $dict ): string|false {}
function compress_init ( int $level = ZSTD_COMPRESS_LEVEL_DEFAULT ): \Zstd\Compress\Context|false {}
function compress_add ( \Zstd\Compress\Context $context, string $data, bool $end = false ): string|false {}
function uncompress_init (): \Zstd\UnCompress\Context|false {}
function uncompress_add ( \Zstd\UnCompress\Context $context, string $data ): string|false
 php
ini_set('zstd.output_compression', 'On');
// OR
// ob_start('ob_zstd_handler');

echo ...;