PHP code example of mitmelon / compress

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

    

mitmelon / compress example snippets


composer 



// Initialize library class
$compress = new Compress\Compress();


/**
 * @param String $filePath
 * File location to be compressed
 * @param String $storePath
 * Path to output compressed binary file to
 * @param Mixed $options ["removeMeta" => false, "encrypt" => false, "key" => "password", "scanFile" => ["token" => $token, "service" => $service, "csp" => $csp, "region" => $region]]
 * Options to remove meta, encrypt file and scan content for reputations
 */
$compress::compressFile($filePath, $storePath, $options = []);

//Compress Image file
$compress::compressFile(__DIR__.'/image.png', __DIR__.'/image.txt');

// Compress PDF
$compress::compressFile(__DIR__.'/file.pdf', __DIR__.'/file.txt');


$options = array("scanFile" => array("token" => "{File_Intel_API_Token}", "service" => 'file-intel', "csp" => 'aws', "region" => 'us'));
$compress::compressFile(__DIR__.'/file.pdf', __DIR__.'/file.txt', $options);


/**
 * UnCompress Image file [Get original file back from stored binary]
 * @param String $storePath
 * Path containing binary file which was compressed
 * @param String $fileOutputPath
 * Path to output original file to
 * @param String $encrypt_key
 * If your file was encrypted then provide the key for decryption as third argument
 */
$compress::uncompressFile($storePath, $fileOutputPath, $encrypt_key = null);

//Uncompress Image
$compress::uncompressFile(__DIR__.'/image.txt', __DIR__.'/image.png');

// Uncompress PDF
$compress::uncompressFile( __DIR__.'/file.txt', __DIR__.'/file.pdf')


    /**
     * Encryption block chunk size
     *
     * @param Int $block
     */
    public int $block = 1024;
    /**
     * Compression and Uncompression chunk size
     *
     * @param Int $compress_chunk_size
     */
    public int $compress_chunk_size = 100 * 1024 * 1024; // 100 MB
    /**
     * Encryption cipher
     *
     * @default aes-256-cbc
     */
    public string $cipher = 'aes-256-cbc';