public static function extractFile(Entry $entry)
    {
        if (null === self::$compression) {
            self::$compression = array(
                'bzip2' => function_exists('bzdecompress'),
                'gzip' => function_exists('gzinflate'),
            );
        }

        $reader = $entry->getArchive()->getReader();

        $reader->seek($entry->getOffset());

        $contents = $reader->read($entry->getCompressedSize());

        if ($entry->isCompressed(Entry::BZ2)) {
            if (!self::$compression['bzip2']) {
                throw FileException::createUsingFormat(
                    'The "bz2" extension is required to decompress "%s".',
                    $entry->getName()
                );
            }

            $contents = bzdecompress($contents);
        } elseif ($entry->isCompressed(Entry::GZ)) {
            if (!self::$compression['gzip']) {
                throw FileException::createUsingFormat(
                    'The "zlib" extension is required to decompress "%s".',
                    $entry->getName()
                );
            }

            $contents = gzinflate($contents);
        }

        return $contents;
    }
public static function extractFile(Entry $entry)
    {
        if (null === self::$compression) {
            self::$compression = array(
                'bzip2' => function_exists('bzdecompress'),
                'gzip' => function_exists('gzinflate'),
            );
        }

        $reader = $entry->getArchive()->getReader();

        $reader->seek($entry->getOffset());

        $contents = $reader->read($entry->getCompressedSize());

        if ($entry->isCompressed(Entry::BZ2)) {
            if (!self::$compression['bzip2']) {
                throw FileException::createUsingFormat(
                    'The "bz2" extension is required to decompress "%s".',
                    $entry->getName()
                );
            }

            $contents = bzdecompress($contents);
        } elseif ($entry->isCompressed(Entry::GZ)) {
            if (!self::$compression['gzip']) {
                throw FileException::createUsingFormat(
                    'The "zlib" extension is required to decompress "%s".',
                    $entry->getName()
                );
            }

            $contents = gzinflate($contents);
        }

        return $contents;
    }
public static function extractFile ( Entry $ entry ) { if ( null === self :: $ compression ) { self :: $ compression = array ( 'bzip2' => function_exists ( 'bzdecompress' ) , 'gzip' => function_exists ( 'gzinflate' ) , ) ; } $ reader = $ entry -> getArchive ( ) -> getReader ( ) ; $ reader -> seek ( $ entry -> getOffset ( ) ) ; $ contents = $ reader -> read ( $ entry -> getCompressedSize ( ) ) ; if ( $ entry -> isCompressed ( Entry :: BZ2 ) ) { if ( ! self :: $ compression [ 'bzip2' ] ) { throw FileException :: createUsingFormat ( 'The "bz2" extension is required to decompress "%s".' , $ entry -> getName ( ) ) ; } $ contents = bzdecompress ( $ contents ) ; } elseif ( $ entry -> isCompressed ( Entry :: GZ ) ) { if ( ! self :: $ compression [ 'gzip' ] ) { throw FileException :: createUsingFormat ( 'The "zlib" extension is required to decompress "%s".' , $ entry -> getName ( ) ) ; } $ contents = gzinflate ( $ contents ) ; } return $ contents ; }
Returns the contents of a file from an archive.

Uses an instance of `Entry` to extract and decompress (if necessary)
the contents of a file from an archive. Note that an extension may be
required (`bz2` or `zlib`) to extract the file.

use Phine\Phar\Extract;

$contents = Extract::extractFile($entry);

@param Entry $entry The file information from the archive.

@return string The decompressed file contents.

@throws Exception
@throws FileException If the file could not be decompressed.

@api
Returns the contents of a file from an archive .