GuzzleHttp\Psr7\LimitStream::setOffset PHP 메소드

setOffset() 공개 메소드

Set the offset to start limiting from
public setOffset ( integer $offset )
$offset integer Offset to seek to and begin byte limiting from
    public function setOffset($offset)
    {
        $current = $this->stream->tell();
        if ($current !== $offset) {
            // If the stream cannot seek to the offset position, then read to it
            if ($this->stream->isSeekable()) {
                $this->stream->seek($offset);
            } elseif ($current > $offset) {
                throw new \RuntimeException("Could not seek to stream offset {$offset}");
            } else {
                $this->stream->read($offset - $current);
            }
        }
        $this->offset = $offset;
    }

Usage Example

예제 #1
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Could not seek to stream offset 2
  */
 public function testThrowsWhenCurrentGreaterThanOffsetSeek()
 {
     $a = Psr7\stream_for('foo_bar');
     $b = new NoSeekStream($a);
     $c = new LimitStream($b);
     $a->getContents();
     $c->setOffset(2);
 }