PHP code example of belisoful / prado-compression

1. Go to this page and download the library: Download belisoful/prado-compression 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/ */

    

belisoful / prado-compression example snippets


use Prado\IO\Compression\TXzFallbackCompressor;

if (TXzFallbackCompressor::isAvailable()) {
    $packed = TXzFallbackCompressor::compress($data);
    $data   = TXzFallbackCompressor::decompress($packed);
}

use Prado\IO\Compression\TFallbackCompressorMode;
use Prado\IO\Compression\TGzipFallbackCompressor;

TGzipFallbackCompressor::setBackendMode(TFallbackCompressorMode::CliFirst);
TGzipFallbackCompressor::getBackendMode();     // 'CliFirst'
TGzipFallbackCompressor::setBackendMode(null); // restores the default, PhpFirst

   TXzFallbackCompressor::setTempDirectory('/var/lib/myapp/tmp');
   TXzFallbackCompressor::getTempDirectory();     // the canonical path
   TXzFallbackCompressor::setTempDirectory(null); // restores the system directory
   

   class TSystemXzCompressor extends TXzFallbackCompressor
   {
       protected static function commands(): array
       {
           return ['/usr/bin/xz'];
       }
   }
   

   TXzFallbackCompressor::setMaxOutputSize(64 * 1024 * 1024);
   

   TZstdFallbackCompressor::setBackendMode(TFallbackCompressorMode::PhpOnly);
   

use Prado\Exceptions\TException;
use Prado\Prado;

$config = __DIR__ . '/vendor/belisoful/prado-compression/config';
Prado::registerClassMap(json_decode(file_get_contents($config . '/classMap.json'), true));
TException::addMessageFile($config . '/errorMessages.txt');