Exception
3 years ago
AppendStream.php
3 years ago
BufferStream.php
3 years ago
CachingStream.php
3 years ago
DroppingStream.php
3 years ago
FnStream.php
3 years ago
Header.php
3 years ago
HttpFactory.php
3 years ago
InflateStream.php
3 years ago
LazyOpenStream.php
3 years ago
LimitStream.php
3 years ago
Message.php
3 years ago
MessageTrait.php
3 years ago
MimeType.php
3 years ago
MultipartStream.php
3 years ago
NoSeekStream.php
3 years ago
PumpStream.php
3 years ago
Query.php
3 years ago
Request.php
3 years ago
Response.php
3 years ago
Rfc7230.php
3 years ago
ServerRequest.php
3 years ago
Stream.php
3 years ago
StreamDecoratorTrait.php
3 years ago
StreamWrapper.php
3 years ago
UploadedFile.php
3 years ago
Uri.php
3 years ago
UriComparator.php
3 years ago
UriNormalizer.php
3 years ago
UriResolver.php
3 years ago
Utils.php
3 years ago
InflateStream.php
38 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace GuzzleHttp\Psr7; |
| 6 | |
| 7 | use Psr\Http\Message\StreamInterface; |
| 8 | |
| 9 | /** |
| 10 | * Uses PHP's zlib.inflate filter to inflate zlib (HTTP deflate, RFC1950) or gzipped (RFC1952) content. |
| 11 | * |
| 12 | * This stream decorator converts the provided stream to a PHP stream resource, |
| 13 | * then appends the zlib.inflate filter. The stream is then converted back |
| 14 | * to a Guzzle stream resource to be used as a Guzzle stream. |
| 15 | * |
| 16 | * @link http://tools.ietf.org/html/rfc1950 |
| 17 | * @link http://tools.ietf.org/html/rfc1952 |
| 18 | * @link http://php.net/manual/en/filters.compression.php |
| 19 | */ |
| 20 | final class InflateStream implements StreamInterface |
| 21 | { |
| 22 | use StreamDecoratorTrait; |
| 23 | |
| 24 | /** @var StreamInterface */ |
| 25 | private $stream; |
| 26 | |
| 27 | public function __construct(StreamInterface $stream) |
| 28 | { |
| 29 | $resource = StreamWrapper::getResource($stream); |
| 30 | // Specify window=15+32, so zlib will use header detection to both gzip (with header) and zlib data |
| 31 | // See http://www.zlib.net/manual.html#Advanced definition of inflateInit2 |
| 32 | // "Add 32 to windowBits to enable zlib and gzip decoding with automatic header detection" |
| 33 | // Default window size is 15. |
| 34 | stream_filter_append($resource, 'zlib.inflate', STREAM_FILTER_READ, ['window' => 15 + 32]); |
| 35 | $this->stream = $stream->isSeekable() ? new Stream($resource) : new NoSeekStream(new Stream($resource)); |
| 36 | } |
| 37 | } |
| 38 |