GuzzleHttpPsr7InflateStream

Uses PHP's zlib.inflate filter to inflate deflate or gzipped content.

Defined (1)

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

/lib/Azure/GuzzleHttp/Psr7/InflateStream.php  
  1. class InflateStream implements StreamInterface 
  2. use StreamDecoratorTrait; 
  3.  
  4. public function __construct(StreamInterface $stream) 
  5. // read the first 10 bytes, ie. gzip header 
  6. $header = $stream->read(10); 
  7. $filenameHeaderLength = $this->getLengthOfPossibleFilenameHeader($stream, $header); 
  8. // Skip the header, that is 10 + length of filename + 1 (nil) bytes 
  9. $stream = new LimitStream($stream, -1, 10 + $filenameHeaderLength); 
  10. $resource = StreamWrapper::getResource($stream); 
  11. stream_filter_append($resource, 'zlib.inflate', STREAM_FILTER_READ); 
  12. $this->stream = new Stream($resource); 
  13.  
  14. /** 
  15. * @param StreamInterface $stream 
  16. * @param $header 
  17. * @return int 
  18. */ 
  19. private function getLengthOfPossibleFilenameHeader(StreamInterface $stream, $header) 
  20. $filename_header_length = 0; 
  21.  
  22. if (substr(bin2hex($header), 6, 2) === '08') { 
  23. // we have a filename, read until nil 
  24. $filename_header_length = 1; 
  25. while ($stream->read(1) !== chr(0)) { 
  26. $filename_header_length++; 
  27.  
  28. return $filename_header_length;