public function LimitStream::read in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/guzzlehttp/psr7/src/LimitStream.php \GuzzleHttp\Psr7\LimitStream::read()
Read data from the stream.
Parameters
int $length Read up to $length bytes from the object and return: them. Fewer than $length bytes may be returned if underlying stream call returns fewer bytes.
Return value
string Returns the data read from the stream, or an empty string if no bytes are available.
Throws
\RuntimeException if an error occurs.
Overrides StreamDecoratorTrait::read
File
- vendor/
guzzlehttp/ psr7/ src/ LimitStream.php, line 138
Class
- LimitStream
- Decorator used to return only a subset of a stream
Namespace
GuzzleHttp\Psr7Code
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 '';
}