Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../vendor/guzzleht.../psr7/src
File: BufferStream.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace GuzzleHttp\Psr7;
[2] Fix | Delete
[3] Fix | Delete
use Psr\Http\Message\StreamInterface;
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Provides a buffer stream that can be written to to fill a buffer, and read
[7] Fix | Delete
* from to remove bytes from the buffer.
[8] Fix | Delete
*
[9] Fix | Delete
* This stream returns a "hwm" metadata value that tells upstream consumers
[10] Fix | Delete
* what the configured high water mark of the stream is, or the maximum
[11] Fix | Delete
* preferred size of the buffer.
[12] Fix | Delete
*
[13] Fix | Delete
* @final
[14] Fix | Delete
*/
[15] Fix | Delete
class BufferStream implements StreamInterface
[16] Fix | Delete
{
[17] Fix | Delete
private $hwm;
[18] Fix | Delete
private $buffer = '';
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* @param int $hwm High water mark, representing the preferred maximum
[22] Fix | Delete
* buffer size. If the size of the buffer exceeds the high
[23] Fix | Delete
* water mark, then calls to write will continue to succeed
[24] Fix | Delete
* but will return false to inform writers to slow down
[25] Fix | Delete
* until the buffer has been drained by reading from it.
[26] Fix | Delete
*/
[27] Fix | Delete
public function __construct($hwm = 16384)
[28] Fix | Delete
{
[29] Fix | Delete
$this->hwm = $hwm;
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
public function __toString()
[33] Fix | Delete
{
[34] Fix | Delete
return $this->getContents();
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
public function getContents()
[38] Fix | Delete
{
[39] Fix | Delete
$buffer = $this->buffer;
[40] Fix | Delete
$this->buffer = '';
[41] Fix | Delete
[42] Fix | Delete
return $buffer;
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
public function close()
[46] Fix | Delete
{
[47] Fix | Delete
$this->buffer = '';
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
public function detach()
[51] Fix | Delete
{
[52] Fix | Delete
$this->close();
[53] Fix | Delete
[54] Fix | Delete
return null;
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
public function getSize()
[58] Fix | Delete
{
[59] Fix | Delete
return strlen($this->buffer);
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
public function isReadable()
[63] Fix | Delete
{
[64] Fix | Delete
return true;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
public function isWritable()
[68] Fix | Delete
{
[69] Fix | Delete
return true;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
public function isSeekable()
[73] Fix | Delete
{
[74] Fix | Delete
return false;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
public function rewind()
[78] Fix | Delete
{
[79] Fix | Delete
$this->seek(0);
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
public function seek($offset, $whence = SEEK_SET)
[83] Fix | Delete
{
[84] Fix | Delete
throw new \RuntimeException('Cannot seek a BufferStream');
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
public function eof()
[88] Fix | Delete
{
[89] Fix | Delete
return strlen($this->buffer) === 0;
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
public function tell()
[93] Fix | Delete
{
[94] Fix | Delete
throw new \RuntimeException('Cannot determine the position of a BufferStream');
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* Reads data from the buffer.
[99] Fix | Delete
*/
[100] Fix | Delete
public function read($length)
[101] Fix | Delete
{
[102] Fix | Delete
$currentLength = strlen($this->buffer);
[103] Fix | Delete
[104] Fix | Delete
if ($length >= $currentLength) {
[105] Fix | Delete
// No need to slice the buffer because we don't have enough data.
[106] Fix | Delete
$result = $this->buffer;
[107] Fix | Delete
$this->buffer = '';
[108] Fix | Delete
} else {
[109] Fix | Delete
// Slice up the result to provide a subset of the buffer.
[110] Fix | Delete
$result = substr($this->buffer, 0, $length);
[111] Fix | Delete
$this->buffer = substr($this->buffer, $length);
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
return $result;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
/**
[118] Fix | Delete
* Writes data to the buffer.
[119] Fix | Delete
*/
[120] Fix | Delete
public function write($string)
[121] Fix | Delete
{
[122] Fix | Delete
$this->buffer .= $string;
[123] Fix | Delete
[124] Fix | Delete
// TODO: What should happen here?
[125] Fix | Delete
if (strlen($this->buffer) >= $this->hwm) {
[126] Fix | Delete
return false;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
return strlen($string);
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
public function getMetadata($key = null)
[133] Fix | Delete
{
[134] Fix | Delete
if ($key == 'hwm') {
[135] Fix | Delete
return $this->hwm;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
return $key ? null : [];
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function