3
namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
5
use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
7
* Provides a buffer stream that can be written to to fill a buffer, and read
8
* from to remove bytes from the buffer.
10
* This stream returns a "hwm" metadata value that tells upstream consumers
11
* what the configured high water mark of the stream is, or the maximum
12
* preferred size of the buffer.
14
class BufferStream implements \YoastSEO_Vendor\Psr\Http\Message\StreamInterface
19
* @param int $hwm High water mark, representing the preferred maximum
20
* buffer size. If the size of the buffer exceeds the high
21
* water mark, then calls to write will continue to succeed
22
* but will return false to inform writers to slow down
23
* until the buffer has been drained by reading from it.
25
public function __construct($hwm = 16384)
29
public function __toString()
31
return $this->getContents();
33
public function getContents()
35
$buffer = $this->buffer;
39
public function close()
43
public function detach()
47
public function getSize()
49
return \strlen($this->buffer);
51
public function isReadable()
55
public function isWritable()
59
public function isSeekable()
63
public function rewind()
67
public function seek($offset, $whence = \SEEK_SET)
69
throw new \RuntimeException('Cannot seek a BufferStream');
73
return \strlen($this->buffer) === 0;
75
public function tell()
77
throw new \RuntimeException('Cannot determine the position of a BufferStream');
80
* Reads data from the buffer.
82
public function read($length)
84
$currentLength = \strlen($this->buffer);
85
if ($length >= $currentLength) {
86
// No need to slice the buffer because we don't have enough data.
87
$result = $this->buffer;
90
// Slice up the result to provide a subset of the buffer.
91
$result = \substr($this->buffer, 0, $length);
92
$this->buffer = \substr($this->buffer, $length);
97
* Writes data to the buffer.
99
public function write($string)
101
$this->buffer .= $string;
102
// TODO: What should happen here?
103
if (\strlen($this->buffer) >= $this->hwm) {
106
return \strlen($string);
108
public function getMetadata($key = null)
113
return $key ? null : [];