PHP code example of esplora / decompresso

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

    

esplora / decompresso example snippets


use Esplora\Decompresso\Extractor;
use Esplora\Decompresso\Adapters\ZipArchiveAdapter;
use Esplora\Decompresso\Adapters\GzipArchiveAdapter;

// Create a new Extractor instance to manage the extraction process
$extractor = new Extractor();

// Specify which archive handlers will be used
$extractor->withAdapters([
    new ZipArchiveAdapter(),
    new GzipArchiveAdapter(),
]);

// Returns a boolean depending on the outcome of the extraction process
$extractor->extract('/path/to/your/archive.zip', '/path/to/extract/to');

use Esplora\Decompresso\Extractor;
use Esplora\Decompresso\Adapters\ZipArchiveAdapter;
use Esplora\Decompresso\Adapters\GzipArchiveAdapter;
use Esplora\Decompresso\Providers\ArrayPasswordProvider;

$extractor = new Extractor();

$extractor
    ->withPasswords(new ArrayPasswordProvider([
        'qwerty',
        'xxx123',
    ]))
    ->withAdapters([
        new ZipArchiveAdapter(),
        new GzipArchiveAdapter(),
    ]);

// Returns a boolean depending on the outcome of the extraction process
$extractor->extract('/path/to/your/archive.zip', '/path/to/extract/to');

use Esplora\Decompresso\Extractor;
use Esplora\Decompresso\Handlers\ZipArchiveHandler;
use Esplora\Decompresso\Handlers\GzipArchiveHandler;
use Esplora\Decompresso\Providers\ArrayPasswordProvider;

$extractor = new Extractor();

$extractor
    ->withPasswords(new ArrayPasswordProvider([
        'qwerty',
        'xxx123',
    ]))
    ->withAdapters([
        new ZipArchiveAdapter(),
        new GzipArchiveAdapter(),
    ])
    
    // Define logic to execute on successful extraction
    ->onSuccess(fn() => true)
    
    // Handle cases where extraction fails due to an incorrect password
    ->onPasswordFailure(fn() => false)
    
    // Handle any other errors encountered during extraction
    ->onFailure(fn() => false)

// Extracts the archive and returns the result of the closure
$extractor->extract('/path/to/your/archive.zip', '/path/to/extract/to');