src/lib/Herrera/Box/Extract.php
private function extractFile($info)
    {
        if (0 === $info['size']) {
            return '';
        }

        $data = $this->read($info['compressed_size']);

        if ($info['flags'] & self::GZ) {
            if (false === ($data = gzinflate($data))) {
                throw new RuntimeException(
                    sprintf(
                        'The "%s" file could not be inflated (gzip) from "%s".',
                        $info['path'],
                        $this->file
                    )
                );
            }
        } elseif ($info['flags'] & self::BZ2) {
            if (false === ($data = bzdecompress($data))) {
                throw new RuntimeException(
                    sprintf(
                        'The "%s" file could not be inflated (bzip2) from "%s".',
                        $info['path'],
                        $this->file
                    )
                );
            }
        }

        if (($actual = strlen($data)) !== $info['size']) {
            throw new UnexpectedValueException(
                sprintf(
                    'The size of "%s" (%d) did not match what was expected (%d) in "%s".',
                    $info['path'],
                    $actual,
                    $info['size'],
                    $this->file
                )
            );
        }

        $crc32 = sprintf('%u', crc32($data) & 0xffffffff);

        if ($info['crc32'] != $crc32) {
            throw new UnexpectedValueException(
                sprintf(
                    'The crc32 checksum (%s) for "%s" did not match what was expected (%s) in "%s".',
                    $crc32,
                    $info['path'],
                    $info['crc32'],
                    $this->file
                )
            );
        }

        return $data;
    }
private function extractFile($info)
    {
        if (0 === $info['size']) {
            return '';
        }

        $data = $this->read($info['compressed_size']);

        if ($info['flags'] & self::GZ) {
            if (false === ($data = gzinflate($data))) {
                throw new RuntimeException(
                    sprintf(
                        'The "%s" file could not be inflated (gzip) from "%s".',
                        $info['path'],
                        $this->file
                    )
                );
            }
        } elseif ($info['flags'] & self::BZ2) {
            if (false === ($data = bzdecompress($data))) {
                throw new RuntimeException(
                    sprintf(
                        'The "%s" file could not be inflated (bzip2) from "%s".',
                        $info['path'],
                        $this->file
                    )
                );
            }
        }

        if (($actual = strlen($data)) !== $info['size']) {
            throw new UnexpectedValueException(
                sprintf(
                    'The size of "%s" (%d) did not match what was expected (%d) in "%s".',
                    $info['path'],
                    $actual,
                    $info['size'],
                    $this->file
                )
            );
        }

        $crc32 = sprintf('%u', crc32($data) & 0xffffffff);

        if ($info['crc32'] != $crc32) {
            throw new UnexpectedValueException(
                sprintf(
                    'The crc32 checksum (%s) for "%s" did not match what was expected (%s) in "%s".',
                    $crc32,
                    $info['path'],
                    $info['crc32'],
                    $this->file
                )
            );
        }

        return $data;
    }
private function extractFile ( $ info ) { if ( 0 === $ info [ 'size' ] ) { return '' ; } $ data = $ this -> read ( $ info [ 'compressed_size' ] ) ; if ( $ info [ 'flags' ] & self :: GZ ) { if ( false === ( $ data = gzinflate ( $ data ) ) ) { throw new RuntimeException ( sprintf ( 'The "%s" file could not be inflated (gzip) from "%s".' , $ info [ 'path' ] , $ this -> file ) ) ; } } elseif ( $ info [ 'flags' ] & self :: BZ2 ) { if ( false === ( $ data = bzdecompress ( $ data ) ) ) { throw new RuntimeException ( sprintf ( 'The "%s" file could not be inflated (bzip2) from "%s".' , $ info [ 'path' ] , $ this -> file ) ) ; } } if ( ( $ actual = strlen ( $ data ) ) !== $ info [ 'size' ] ) { throw new UnexpectedValueException ( sprintf ( 'The size of "%s" (%d) did not match what was expected (%d) in "%s".' , $ info [ 'path' ] , $ actual , $ info [ 'size' ] , $ this -> file ) ) ; } $ crc32 = sprintf ( '%u' , crc32 ( $ data ) & 0xffffffff ) ; if ( $ info [ 'crc32' ] != $ crc32 ) { throw new UnexpectedValueException ( sprintf ( 'The crc32 checksum (%s) for "%s" did not match what was expected (%s) in "%s".' , $ crc32 , $ info [ 'path' ] , $ info [ 'crc32' ] , $ this -> file ) ) ; } return $ data ; }
Extracts a single file from the phar.

@param array $info The file information.

@return string The file data.

@throws RuntimeException         If the file could not be extracted.
@throws UnexpectedValueException If the crc32 checksum does not
match the expected value.
Extracts a single file from the phar .