Back to StreamString class

Method stream_seek

public bool
stream_seek
(mixed $offset, mixed $whence)
Stream offset
Parameters
  • int $offset The starting offset.
  • int $whence SEEK_SET, SEEK_CUR, SEEK_END
Returns
  • bool True on success.
Since
  • 1.7.0
Class: StreamString
Project: Joomla

Method stream_seek - Source code

/**
 * Stream offset
 *
 * @param   integer  $offset  The starting offset.
 * @param   integer  $whence  SEEK_SET, SEEK_CUR, SEEK_END
 *
 * @return  boolean  True on success.
 *
 * @since   1.7.0
 */
public function stream_seek($offset, $whence)
{
    // $whence: SEEK_SET, SEEK_CUR, SEEK_END
    if ($offset > $this->len) {
        // We can't seek beyond our len.
        return false;
    }
    switch ($whence) {
        case SEEK_SET:
            $this->pos = $offset;
            break;
        case SEEK_CUR:
            if ($this->pos + $offset < $this->len) {
                $this->pos += $offset;
            } else {
                return false;
            }
            break;
        case SEEK_END:
            $this->pos = $this->len - $offset;
            break;
    }
    return true;
}