GuzzleHttpPsr7copy_to_string

Copy the contents of a stream into a string until the given number of bytes have been read.

Description

(string) GuzzleHttp\Psr7\copy_to_string( (StreamInterface) Psr\Http\Message\StreamInterface $stream, (int) $maxLen = -1 ); 

Returns (string)

Parameters (2)

0. $stream (StreamInterface) => Psr\Http\Message\StreamInterface $stream
Stream to read
1. $maxlen (int)
Maximum number of bytes to read. Pass -1 to read the entire stream.

Usage

  1. if ( !function_exists( 'GuzzleHttp\Psr7\copy_to_string' ) ) { 
  2. require_once '/lib/Azure/GuzzleHttp/Psr7/functions.php'; 
  3.  
  4. // Stream to read 
  5. $stream = Psr\Http\Message\StreamInterface $stream; 
  6.  
  7. // Maximum number of bytes to read. Pass -1 
  8. // to read the entire stream. 
  9. $maxlen = -1; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = GuzzleHttp\Psr7\copy_to_string($stream, $maxlen); 
  13.  

Defined (1)

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

/lib/Azure/GuzzleHttp/Psr7/functions.php  
  1. function copy_to_string(StreamInterface $stream, $maxLen = -1) 
  2. $buffer = ''; 
  3.  
  4. if ($maxLen === -1) { 
  5. while (!$stream->eof()) { 
  6. $buf = $stream->read(1048576); 
  7. // Using a loose equality here to match on '' and false. 
  8. if ($buf == null) { 
  9. break; 
  10. $buffer .= $buf; 
  11. return $buffer; 
  12.  
  13. $len = 0; 
  14. while (!$stream->eof() && $len < $maxLen) { 
  15. $buf = $stream->read($maxLen - $len); 
  16. // Using a loose equality here to match on '' and false. 
  17. if ($buf == null) { 
  18. break; 
  19. $buffer .= $buf; 
  20. $len = strlen($buffer); 
  21.  
  22. return $buffer;