GuzzleHttpPsr7BufferStream

Provides a buffer stream that can be written to to fill a buffer, and read from to remove bytes from the buffer.

Defined (1)

The class is defined in the following location(s).

/lib/Azure/GuzzleHttp/Psr7/BufferStream.php  
  1. class BufferStream implements StreamInterface 
  2. private $hwm; 
  3. private $buffer = ''; 
  4.  
  5. /** 
  6. * @param int $hwm High water mark, representing the preferred maximum 
  7. * buffer size. If the size of the buffer exceeds the high 
  8. * water mark, then calls to write will continue to succeed 
  9. * but will return false to inform writers to slow down 
  10. * until the buffer has been drained by reading from it. 
  11. */ 
  12. public function __construct($hwm = 16384) 
  13. $this->hwm = $hwm; 
  14.  
  15. public function __toString() 
  16. return $this->getContents(); 
  17.  
  18. public function getContents() 
  19. $buffer = $this->buffer; 
  20. $this->buffer = ''; 
  21.  
  22. return $buffer; 
  23.  
  24. public function close() 
  25. $this->buffer = ''; 
  26.  
  27. public function detach() 
  28. $this->close(); 
  29.  
  30. public function getSize() 
  31. return strlen($this->buffer); 
  32.  
  33. public function isReadable() 
  34. return true; 
  35.  
  36. public function isWritable() 
  37. return true; 
  38.  
  39. public function isSeekable() 
  40. return false; 
  41.  
  42. public function rewind() 
  43. $this->seek(0); 
  44.  
  45. public function seek($offset, $whence = SEEK_SET) 
  46. throw new \RuntimeException('Cannot seek a BufferStream'); 
  47.  
  48. public function eof() 
  49. return strlen($this->buffer) === 0; 
  50.  
  51. public function tell() 
  52. throw new \RuntimeException('Cannot determine the position of a BufferStream'); 
  53.  
  54. /** 
  55. * Reads data from the buffer. 
  56. */ 
  57. public function read($length) 
  58. $currentLength = strlen($this->buffer); 
  59.  
  60. if ($length >= $currentLength) { 
  61. // No need to slice the buffer because we don't have enough data. 
  62. $result = $this->buffer; 
  63. $this->buffer = ''; 
  64. } else { 
  65. // Slice up the result to provide a subset of the buffer. 
  66. $result = substr($this->buffer, 0, $length); 
  67. $this->buffer = substr($this->buffer, $length); 
  68.  
  69. return $result; 
  70.  
  71. /** 
  72. * Writes data to the buffer. 
  73. */ 
  74. public function write($string) 
  75. $this->buffer .= $string; 
  76.  
  77. // TODO: What should happen here? 
  78. if (strlen($this->buffer) >= $this->hwm) { 
  79. return false; 
  80.  
  81. return strlen($string); 
  82.  
  83. public function getMetadata($key = null) 
  84. if ($key == 'hwm') { 
  85. return $this->hwm; 
  86.  
  87. return $key ? null : [];