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

read() 공개 메소드

public read ( $length )
    public function read($length)
    {
        if ($this->limit == -1) {
            return $this->stream->read($length);
        }
        // Check if the current position is less than the total allowed
        // bytes + original offset
        $remaining = $this->offset + $this->limit - $this->stream->tell();
        if ($remaining > 0) {
            // Only return the amount of requested data, ensuring that the byte
            // limit is not exceeded
            return $this->stream->read(min($remaining, $length));
        }
        return '';
    }

Usage Example

예제 #1
0
 public function testClaimsConsumedWhenReadLimitIsReached()
 {
     $this->assertFalse($this->body->eof());
     $this->body->read(1000);
     $this->assertTrue($this->body->eof());
 }