InflateStream.php 942 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace GuzzleHttp\Stream;
  3. /**
  4. * Uses PHP's zlib.inflate filter to inflate deflate or gzipped content.
  5. *
  6. * This stream decorator skips the first 10 bytes of the given stream to remove
  7. * the gzip header, converts the provided stream to a PHP stream resource,
  8. * then appends the zlib.inflate filter. The stream is then converted back
  9. * to a Guzzle stream resource to be used as a Guzzle stream.
  10. *
  11. * @link http://tools.ietf.org/html/rfc1952
  12. * @link http://php.net/manual/en/filters.compression.php
  13. */
  14. class InflateStream implements StreamInterface
  15. {
  16. use StreamDecoratorTrait;
  17. public function __construct(StreamInterface $stream)
  18. {
  19. // Skip the first 10 bytes
  20. $stream = new LimitStream($stream, -1, 10);
  21. $resource = GuzzleStreamWrapper::getResource($stream);
  22. stream_filter_append($resource, 'zlib.inflate', STREAM_FILTER_READ);
  23. $this->stream = new Stream($resource);
  24. }
  25. }