BufferStream.php in Zircon Profile 8.0
File
vendor/guzzlehttp/psr7/src/BufferStream.php
View source
<?php
namespace GuzzleHttp\Psr7;
use Psr\Http\Message\StreamInterface;
class BufferStream implements StreamInterface {
private $hwm;
private $buffer = '';
public function __construct($hwm = 16384) {
$this->hwm = $hwm;
}
public function __toString() {
return $this
->getContents();
}
public function getContents() {
$buffer = $this->buffer;
$this->buffer = '';
return $buffer;
}
public function close() {
$this->buffer = '';
}
public function detach() {
$this
->close();
}
public function getSize() {
return strlen($this->buffer);
}
public function isReadable() {
return true;
}
public function isWritable() {
return true;
}
public function isSeekable() {
return false;
}
public function rewind() {
$this
->seek(0);
}
public function seek($offset, $whence = SEEK_SET) {
throw new \RuntimeException('Cannot seek a BufferStream');
}
public function eof() {
return strlen($this->buffer) === 0;
}
public function tell() {
throw new \RuntimeException('Cannot determine the position of a BufferStream');
}
public function read($length) {
$currentLength = strlen($this->buffer);
if ($length >= $currentLength) {
$result = $this->buffer;
$this->buffer = '';
}
else {
$result = substr($this->buffer, 0, $length);
$this->buffer = substr($this->buffer, $length);
}
return $result;
}
public function write($string) {
$this->buffer .= $string;
if (strlen($this->buffer) >= $this->hwm) {
return false;
}
return strlen($string);
}
public function getMetadata($key = null) {
if ($key == 'hwm') {
return $this->hwm;
}
return $key ? null : [];
}
}
Classes
Name |
Description |
BufferStream |
Provides a buffer stream that can be written to to fill a buffer, and read
from to remove bytes from the buffer. |