public static function findOffset(Reader $reader)
    {
        $reader->seek(0);

        $offset = 0;

        while (!$reader->isEndOfFile()) {
            if (strtolower($reader->read(1)) === self::$sequence[$offset]) {
                $offset++;
            } else {
                $offset = 0;
            }

            if (!isset(self::$sequence[$offset + 1])) {
                break;
            }
        }

        $reader->seek(1, SEEK_CUR);

        if ($offset === (count(self::$sequence) - 1)) {
            $position = $reader->getPosition();

            if ("\r\n" === $reader->read(2)) {
                return $position + 2;
            }

            return $position;
        }

        return null;
    }
public static function findOffset(Reader $reader)
    {
        $reader->seek(0);

        $offset = 0;

        while (!$reader->isEndOfFile()) {
            if (strtolower($reader->read(1)) === self::$sequence[$offset]) {
                $offset++;
            } else {
                $offset = 0;
            }

            if (!isset(self::$sequence[$offset + 1])) {
                break;
            }
        }

        $reader->seek(1, SEEK_CUR);

        if ($offset === (count(self::$sequence) - 1)) {
            $position = $reader->getPosition();

            if ("\r\n" === $reader->read(2)) {
                return $position + 2;
            }

            return $position;
        }

        return null;
    }
public static function findOffset ( Reader $ reader ) { $ reader -> seek ( 0 ) ; $ offset = 0 ; while ( ! $ reader -> isEndOfFile ( ) ) { if ( strtolower ( $ reader -> read ( 1 ) ) === self :: $ sequence [ $ offset ] ) { $ offset ++ ; } else { $ offset = 0 ; } if ( ! isset ( self :: $ sequence [ $ offset + 1 ] ) ) { break ; } } $ reader -> seek ( 1 , SEEK_CUR ) ; if ( $ offset === ( count ( self :: $ sequence ) - 1 ) ) { $ position = $ reader -> getPosition ( ) ; if ( "\r\n" === $ reader -> read ( 2 ) ) { return $ position + 2 ; } return $ position ; } return null ; }
Finds the data offset of an archive.

This method will scan the entire archive for a specific sequence of
characters that denotes the end of the archive's stub. In an archive
file using the phar file format, the data follows the end of the stub.
If the sequence is located, the offset for the data will be returned.
If the sequence could not be found, nothing (`null`) is returned.

use Phine\Phar\File\Reader;
use Phine\Phar\Archive;

$reader = new Reader('example.phar');
$offset = Archive::findOffset($reader);

@link http://us1.php.net/manual/en/phar.fileformat.phar.php File Format

@param Reader $reader The archive file reader.

@return integer If the archive offset is found, it is returned. If a
archive offset is not found, `null` is returned.

@api
Finds the data offset of an archive .