1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 
<?php
    /**
     * Copyright (C) Apis Networks, Inc - All Rights Reserved.
     *
     * Unauthorized copying of this file, via any medium, is
     * strictly prohibited without consent. Any dissemination of
     * material herein is prohibited.
     *
     * For licensing inquiries email <licensing@apisnetworks.com>
     *
     * Written by Matt Saladna <matt@apisnetworks.com>, May 2017
     */

    include_once('tar.php');

    /**
     * Provides bzip compression/decompression routines in the file manager
     *
     * @package Compression
     */
    class Bzip_Filter extends Tar_Filter
    {
        public static function extract_files($archive, $destination, array $files = null, array $opts = null)
        {
            $ext = self::$fc->compression_extension($archive);
            $tar = in_array($ext, array('.tbz', '.tbz2', '.tar.bz', '.tar.bz2'));
            $cmd = 'bzip2 ' . (!$tar ? '-d' : '-d -c') . ' %s';
            $proc = parent::exec(
                $cmd,
                $archive,
                array(0),
                array('run' => !$tar)
            );

            if ($tar) {
                return self::extract_files_pipe($archive, $destination, $files, $opts);
            }
            if (!$proc['success']) {
                return false;
            }

            self::$fc->file_delete($archive);

            return true;
        }


        public static function list_files($archive, array $opts = null)
        {
            $ext = self::$fc->compression_extension($archive);
            $tar = in_array($ext, array('.tbz', '.tbz2', '.tar.bz', '.tar.bz2'));
            if ($tar) {
                $cmd = 'bzip2 -d -c %s';
                $proc = parent::exec(
                    $cmd,
                    $archive,
                    array(0),
                    array('run' => 0)
                );

                return self::list_files_pipe($archive,
                    $opts
                );
            }

            $files = array();
            $files[] = array(
                'file_name'   => basename($archive, self::$fc->compression_extension($archive)),
                'file_type'   => 'file',
                'can_read'    => true,
                'can_write'   => true,
                'can_execute' => true,
                'size'        => strlen(file_get_contents('compress.bzip2://' . $archive)),
                'packed_size' => filesize($archive),
                'crc'         => '?',
                'link'        => 0,
                'date'        => filectime($archive)
            );

            return $files;

        }

    }

?>