GuzzleHttpPsr7DroppingStream

Stream decorator that begins dropping data once the size of the underlying stream becomes too full.

Defined (1)

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

/lib/Azure/GuzzleHttp/Psr7/DroppingStream.php  
  1. class DroppingStream implements StreamInterface 
  2. use StreamDecoratorTrait; 
  3.  
  4. private $maxLength; 
  5.  
  6. /** 
  7. * @param StreamInterface $stream Underlying stream to decorate. 
  8. * @param int $maxLength Maximum size before dropping data. 
  9. */ 
  10. public function __construct(StreamInterface $stream, $maxLength) 
  11. $this->stream = $stream; 
  12. $this->maxLength = $maxLength; 
  13.  
  14. public function write($string) 
  15. $diff = $this->maxLength - $this->stream->getSize(); 
  16.  
  17. // Begin returning 0 when the underlying stream is too large. 
  18. if ($diff <= 0) { 
  19. return 0; 
  20.  
  21. // Write the stream or a subset of the stream if needed. 
  22. if (strlen($string) < $diff) { 
  23. return $this->stream->write($string); 
  24.  
  25. return $this->stream->write(substr($string, 0, $diff));