Tries to seek a stream.

@param resource $stream The stream.
@param int      $offset The offset.
@param int      $whence One of SEEK_SET, SEEK_CUR, SEEK_END.

@return bool True on success, false on failure.

@see fseek()
480962
public static function trySeek($stream, $offset, $whence = SEEK_SET)
    {
        $offset = (int) $offset;

        // If SEEK_SET, we can avoid a seek if we're at the right location.
        if ($whence === SEEK_SET && ftell($stream) === $offset) {
            return true;
        }

        return static::isSeekable($stream) && fseek($stream, $offset, $whence) === 0;
    }
46682
function _stream_seek($offset, $whence)
    {
        switch ($whence) {
            case SEEK_SET:
                if ($offset >= $this->size || $offset < 0) {
                    return false;
                }
                break;
            case SEEK_CUR:
                $offset+= $this->pos;
                break;
            case SEEK_END:
                $offset+= $this->size;
        }

        $this->pos = $offset;
        $this->eof = false;
        return true;
    }
1238565
public function stream_seek($offset, $whence)
    {
        $oldpos = $this->_position;
        $this->_ateof = false;

        switch ($whence) {
        case SEEK_SET:
            $offset = $offset;
            break;

        case SEEK_CUR:
            $offset = $this->_position + $offset;
            break;

        case SEEK_END:
            $offset = $this->_length + $offset;
            break;

        default:
            return false;
        }

        $count = $this->_position = min($this->_length, $offset);

        foreach ($this->_data as $key => $val) {
            if ($count < $val['l']) {
                $this->_datapos = $key;
                $val['p'] = $count;
                fseek($val['fp'], $count, SEEK_SET);
                break;
            }
            $count -= $val['l'];
        }

        return ($oldpos != $this->_position);
    }
705203
public function seek($offset){
		$this->performed || $this->run();
		$seek = $this->connection->getDriver()->seek($this->resultSet, $offset);
		if($seek)
			return $seek;
		throw new NeevoException("Cannot seek to offset $offset.");
	}
683650
public function seek($offset, $whence = SEEK_SET)
    {
        if (!is_int($offset) && !is_numeric($offset)) {
            return false;
        }

        $offset = (int) $offset;
        if ($offset < 0) {
            return false;
        }

        $key = $this->iterator->key();
        if (!is_int($key) && !is_numeric($key)) {
            $key = 0;
            $this->iterator->rewind();
        }

        if ($key >= $offset) {
            $key = 0;
            $this->iterator->rewind();
        }

        while ($this->iterator->valid() && $key < $offset) {
            $this->iterator->next();
            ++$key;
        }

        $this->position = $key;

        return true;
    }
522417
public function stream_seek($offset, $whence)
    {
        switch ( $whence ) {
            case SEEK_SET:
                if ( ( $offset < $this->length ) &&
                     ( $offset >= 0 ) )
                {
                     $this->position = $offset;
                     return true;
                }
                else
                {
                     return false;
                }
                break;

            case SEEK_CUR:
                if ( $offset >= 0 )
                {
                     $this->position += $offset;
                     return true;
                }
                else
                {
                     return false;
                }
                break;

            case SEEK_END:
                if ( ( $this->length + $offset ) >= 0 )
                {
                     $this->position = $this->length + $offset;
                     return true;
                }
                else
                {
                     return false;
                }
                break;

            default:
                return false;
        }
    }
221930
public function seek($offset, $whence) {
    if ($whence == SEEK_END) {
      if (isset($this->object_total_length)) {
        $whence = SEEK_SET;
        $offset = $this->object_total_length + $offset;
      } else {
        trigger_error("Unable to seek from end for objects with unknown size",
                      E_USER_WARNING);
        return false;
      }
    }

    if ($whence != SEEK_SET) {
      trigger_error(sprintf("Unsupported seek mode: %d", $whence),
                    E_USER_WARNING);
      return false;
    }
    // If we know the size, then make sure they are only seeking within it.
    if (isset($this->object_total_length) &&
        $offset >= $this->object_total_length) {
      return false;
    }
    if ($offset < 0) {
      return false;
    }
    // Clear EOF and work it out next time they read.
    $this->eof = false;

    // Check if we can seek inside the current buffer
    $block_start = $this->object_block_start_position;
    $buffer_end = $block_start + strlen($this->read_buffer);
    if ($block_start <= $offset && $offset < $buffer_end) {
      $this->buffer_read_position = $offset - $block_start;
    } else {
      $this->read_buffer = "";
      $this->buffer_read_position = 0;
      $this->next_read_position = $offset;
    }
    return true;
  }
254455
public function seek($offset, $whence = SEEK_SET)
    {
        if ($whence == SEEK_SET) {
            $byte = $offset;
        } elseif ($whence == SEEK_CUR) {
            $byte = $offset + $this->ftell();
        } else {
            throw new RuntimeException(__CLASS__ . ' supports only SEEK_SET and SEEK_CUR seek operations');
        }

        // You cannot skip ahead past where you've read from the remote stream
        if ($byte > $this->body->getSize()) {
            throw new RuntimeException(
                "Cannot seek to byte {$byte} when the buffered stream only contains {$this->body->getSize()} bytes"
            );
        }

        return $this->body->seek($byte);
    }
991653
public function seek($offset, $whence = SEEK_SET){
        if(!is_int($offset)){
            throw new \InvalidArgumentException();
        }

        if(!in_array($whence, [SEEK_SET, SEEK_CUR, SEEK_END])){
            throw new \InvalidArgumentException();
        }

        if(null === $this->resource){
            throw new Exception\StreamUnavailableException(
                static::EXCEPTION_MSG_UNAVAILABLE
            );
        }

        if(!$this->isSeekable()){
            throw new Exception\StreamUnseekableException(
                static::EXCEPTION_MSG_UNSEEKABLE
            );
        }

        if(0 !== fseek($this->resource, $offset, $whence)){
            throw new \RuntimeException("Failed to seek file pointer.");
        }

        return $this;
    }
532799
public function stream_seek(int $offset, int $whence = SEEK_SET): bool
    {
        $body = $this->response->getBody();
        if (!$body->isSeekable()) {
            return false;
        }

        try {
            $body->seek($offset, $whence);

            return true;
        } catch (\RuntimeException $exception) {
            return false;
        }
    }
227982
public function setStream($stream)
    {
        // streams have to be cached to file first
        $meta = @stream_get_meta_data($stream);
        if (!$meta || !$meta['mode'] || !in_array($meta['mode'], self::$readableModes, true) || $meta['eof']) {
            throw new Exception(
                'setStream() expects parameter stream to be readable stream resource.'
            );
        }

        /** @var resource $tmp_fp */
        $tmp_fp = tmpfile();
        if ($tmp_fp) {
            while (!feof($stream)) {
                fwrite($tmp_fp, fread($stream, 2028));
            }

            if (fread($tmp_fp, 1) != "\n") {
                fwrite($tmp_fp, PHP_EOL);
            }

            fseek($tmp_fp, 0);
            $this->stream = &$tmp_fp;
        } else {
            throw new Exception(
                'Could not create temporary files for attachments. Your tmp directory may be unwritable by PHP.'
            );
        }
        fclose($stream);

        $this->resource = mailparse_msg_create();
        // parses the message incrementally (low memory usage but slower)
        while (!feof($this->stream)) {
            mailparse_msg_parse($this->resource, fread($this->stream, 2082));
        }
        $this->parse();

        return $this;
    }
1090136
public function seek($position)
    {
        if ($position > $this->getStream()->getSize()) {
            throw new OutOfBoundsException('Invalid seek position ('.$position.')');
        }

        $this->getStream()->seek($position, SEEK_SET);
    }
969367
public function FromBytes($stream, $offset) // ret <= 0 - error
	{
		$moved = 0;
		$vi = 0;
		$moved += $parsed = ProtoBuf_Bytes2Varint($stream, $offset + $moved, $vi);
		if ($parsed <= 0)
			return $parsed;

		//echo "vi $vi\n";
		$this->wt = ($vi & 0x07);
		$this->fn = ($vi >> 3);
		//echo "field wt " . $this->wt . " fn " . $this->fn . "\n";

		switch ($this->wt)
		{
			case ProtoBuf_Field::ProtoBuf_WireType_Varint: // TODO: in case we need this information, create get function
				$this->data = 0;
				$moved += $parsed = ProtoBuf_Bytes2Varint($stream, $offset + $moved, $this->data);
				break;
			case ProtoBuf_Field::ProtoBuf_WireType_64bit:
				$this->data = substr($stream, $offset + $moved, 8);
				$high4 = ProtoBuf_Bytes2Fixed(substr($this->data, 4), 4);
				if ($high4 == 0)
				{
					$this->fixed64_is_32bit = true;
					$this->data = ProtoBuf_Bytes2Fixed($this->data, 4);
				}
				else
				{
					$this->fixed64_is_32bit = false;
					$this->data = ProtoBuf_Bytes2Fixed($this->data, 8);
				}
				$moved += 8;
				break;
			case ProtoBuf_Field::ProtoBuf_WireType_LengthDelimited:
				$moved += $parsed = ProtoBuf_Bytes2Varint($stream, $offset + $moved, $vi);
				if ($parsed <= 0)
					return $parsed;
				$this->data = substr($stream, $offset + $moved, $vi);
				$moved += $vi;
				break;
			/*case ProtoBuf_Field::ProtoBuf_WireType_StartGroup: // TODO: in case we need this information, create get function
				break;
			case ProtoBuf_Field::ProtoBuf_WireType_EndGroup: // TODO: in case we need this information, create get function
				break;*/
			case ProtoBuf_Field::ProtoBuf_WireType_32bit:
				$this->data = substr($stream, $offset + $moved, 4);
				$this->data = ProtoBuf_Bytes2Fixed($this->data, 4);
				$moved += 4;
				break;
			default:
				die("[lib_protobuf.inc] Unrecognized protobuf wire type '" . $this->wt . "'\n");
				break;
		}

		return $moved;
	}
41380
protected function seekRow(int $offset)
    {
        foreach ($this->getDocument() as $index => $record) {
            if ($offset === $index) {
                return $record;
            }
        }

        return false;
    }
447426
private function drain($stream, $dest)
    {
        if (is_resource($stream)) {
            if (!is_resource($dest)) {
                $stream = Stream::factory($stream);
            } else {
                stream_copy_to_stream($stream, $dest);
                fclose($stream);
                rewind($dest);
                return $dest;
            }
        }

        // Stream the response into the destination stream
        $dest = is_string($dest)
            ? new Stream(Utils::open($dest, 'r+'))
            : Stream::factory($dest);

        Utils::copyToStream($stream, $dest);
        $dest->seek(0);
        $stream->close();

        return $dest;
    }
508045
public function seek(int $offset, int $whence = \SEEK_SET): int
    {
        if (-1 === fseek($this->handle, $offset, $whence)) {
            $message = 'Could not move file pointer.';
            if ($error = error_get_last()) {
                $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
            }
            throw new FileException($message);
        }

        $position = ftell($this->handle);

        if (false === $position) {
            $message = 'Could not get the file pointer position.';
            if ($error = error_get_last()) {
                $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
            }
            throw new FileException($message);
        }

        return $position;
    }
30524
public function seek($offset, $whence = \SEEK_SET) : void
	{
		if (! \is_resource($this->resource))
		{
			throw new Exception\UnseekableStreamException('Stream is not resourceable');
		}

		if (! $this->isSeekable())
		{
			throw new Exception\UnseekableStreamException('Stream is not seekable');
		}

		$result = \fseek($this->resource, $offset, $whence);

		if (! (0 === $result))
		{
			throw new Exception\UnseekableStreamException('Unable to move the stream pointer to the given position');
		}
	}