lib/magento/Archive/Tar.php
protected function _extractFileHeader()
    {
        $archiveReader = $this->_getReader();

        $headerBlock = $archiveReader->read(self::TAR_BLOCK_SIZE);

        if (strlen($headerBlock) < self::TAR_BLOCK_SIZE) {
            return false;
        }

        $header = unpack(self::_getFormatParseHeader(), $headerBlock);

        $header['mode']     = octdec($header['mode']);
        $header['uid']      = octdec($header['uid']);
        $header['gid']      = octdec($header['gid']);
        $header['size']     = octdec($header['size']);
        $header['mtime']    = octdec($header['mtime']);
        $header['checksum'] = octdec($header['checksum']);

        if ($header['type'] == "5") {
            $header['size'] = 0;
        }

        $checksum = 0;
        $headerBlock = substr_replace($headerBlock, '        ', 148, 8);

        for ($i = 0; $i < 512; $i++) {
            $checksum += ord(substr($headerBlock, $i, 1));
        }

        $checksumOk = $header['checksum'] == $checksum;
        if (isset($header['name']) && $checksumOk) {

            if (!($header['name'] == '././@LongLink' && $header['type'] == 'L')) {
                $header['name'] = trim($header['name']);
                return $header;
            }

            $realNameBlockSize = floor(($header['size'] + self::TAR_BLOCK_SIZE - 1) / self::TAR_BLOCK_SIZE)
                * self::TAR_BLOCK_SIZE;
            $realNameBlock = $archiveReader->read($realNameBlockSize);
            $realName = substr($realNameBlock, 0, $header['size']);

            $headerMain = $this->_extractFileHeader();
            $headerMain['name'] = trim($realName);
            return $headerMain;
        }

        return false;
    }
protected function _extractFileHeader()
    {
        $archiveReader = $this->_getReader();

        $headerBlock = $archiveReader->read(self::TAR_BLOCK_SIZE);

        if (strlen($headerBlock) < self::TAR_BLOCK_SIZE) {
            return false;
        }

        $header = unpack(self::_getFormatParseHeader(), $headerBlock);

        $header['mode']     = octdec($header['mode']);
        $header['uid']      = octdec($header['uid']);
        $header['gid']      = octdec($header['gid']);
        $header['size']     = octdec($header['size']);
        $header['mtime']    = octdec($header['mtime']);
        $header['checksum'] = octdec($header['checksum']);

        if ($header['type'] == "5") {
            $header['size'] = 0;
        }

        $checksum = 0;
        $headerBlock = substr_replace($headerBlock, '        ', 148, 8);

        for ($i = 0; $i < 512; $i++) {
            $checksum += ord(substr($headerBlock, $i, 1));
        }

        $checksumOk = $header['checksum'] == $checksum;
        if (isset($header['name']) && $checksumOk) {

            if (!($header['name'] == '././@LongLink' && $header['type'] == 'L')) {
                $header['name'] = trim($header['name']);
                return $header;
            }

            $realNameBlockSize = floor(($header['size'] + self::TAR_BLOCK_SIZE - 1) / self::TAR_BLOCK_SIZE)
                * self::TAR_BLOCK_SIZE;
            $realNameBlock = $archiveReader->read($realNameBlockSize);
            $realName = substr($realNameBlock, 0, $header['size']);

            $headerMain = $this->_extractFileHeader();
            $headerMain['name'] = trim($realName);
            return $headerMain;
        }

        return false;
    }
protected function _extractFileHeader ( ) { $ archiveReader = $ this -> _getReader ( ) ; $ headerBlock = $ archiveReader -> read ( self :: TAR_BLOCK_SIZE ) ; if ( strlen ( $ headerBlock ) < self :: TAR_BLOCK_SIZE ) { return false ; } $ header = unpack ( self :: _getFormatParseHeader ( ) , $ headerBlock ) ; $ header [ 'mode' ] = octdec ( $ header [ 'mode' ] ) ; $ header [ 'uid' ] = octdec ( $ header [ 'uid' ] ) ; $ header [ 'gid' ] = octdec ( $ header [ 'gid' ] ) ; $ header [ 'size' ] = octdec ( $ header [ 'size' ] ) ; $ header [ 'mtime' ] = octdec ( $ header [ 'mtime' ] ) ; $ header [ 'checksum' ] = octdec ( $ header [ 'checksum' ] ) ; if ( $ header [ 'type' ] == "5" ) { $ header [ 'size' ] = 0 ; } $ checksum = 0 ; $ headerBlock = substr_replace ( $ headerBlock , '        ' , 148 , 8 ) ; for ( $ i = 0 ; $ i < 512 ; $ i ++ ) { $ checksum += ord ( substr ( $ headerBlock , $ i , 1 ) ) ; } $ checksumOk = $ header [ 'checksum' ] == $ checksum ; if ( isset ( $ header [ 'name' ] ) && $ checksumOk ) { if ( ! ( $ header [ 'name' ] == '././@LongLink' && $ header [ 'type' ] == 'L' ) ) { $ header [ 'name' ] = trim ( $ header [ 'name' ] ) ; return $ header ; } $ realNameBlockSize = floor ( ( $ header [ 'size' ] + self :: TAR_BLOCK_SIZE - 1 ) / self :: TAR_BLOCK_SIZE ) * self :: TAR_BLOCK_SIZE ; $ realNameBlock = $ archiveReader -> read ( $ realNameBlockSize ) ; $ realName = substr ( $ realNameBlock , 0 , $ header [ 'size' ] ) ; $ headerMain = $ this -> _extractFileHeader ( ) ; $ headerMain [ 'name' ] = trim ( $ realName ) ; return $ headerMain ; } return false ; }
Read and decode file header information from tarball

@return array|boolean
Read and decode file header information from tarball