PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.2
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.2
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / vendor_prefixed / guzzlehttp / psr7 / src / InflateStream.php

InflateStream.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.2, at vendor_prefixed/guzzlehttp/psr7/src/InflateStream.php

52 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
4
5 use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
6 /**
7 * Uses PHP's zlib.inflate filter to inflate deflate or gzipped content.
8 *
9 * This stream decorator skips the first 10 bytes of the given stream to remove
10 * the gzip header, converts the provided stream to a PHP stream resource,
11 * then appends the zlib.inflate filter. The stream is then converted back
12 * to a Guzzle stream resource to be used as a Guzzle stream.
13 *
14 * @link http://tools.ietf.org/html/rfc1952
15 * @link http://php.net/manual/en/filters.compression.php
16 *
17 * @final
18 */
19 class InflateStream implements \YoastSEO_Vendor\Psr\Http\Message\StreamInterface
20 {
21 use StreamDecoratorTrait;
22 public function __construct(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream)
23 {
24 // read the first 10 bytes, ie. gzip header
25 $header = $stream->read(10);
26 $filenameHeaderLength = $this->getLengthOfPossibleFilenameHeader($stream, $header);
27 // Skip the header, that is 10 + length of filename + 1 (nil) bytes
28 $stream = new \YoastSEO_Vendor\GuzzleHttp\Psr7\LimitStream($stream, -1, 10 + $filenameHeaderLength);
29 $resource = \YoastSEO_Vendor\GuzzleHttp\Psr7\StreamWrapper::getResource($stream);
30 \stream_filter_append($resource, 'zlib.inflate', \STREAM_FILTER_READ);
31 $this->stream = $stream->isSeekable() ? new \YoastSEO_Vendor\GuzzleHttp\Psr7\Stream($resource) : new \YoastSEO_Vendor\GuzzleHttp\Psr7\NoSeekStream(new \YoastSEO_Vendor\GuzzleHttp\Psr7\Stream($resource));
32 }
33 /**
34 * @param StreamInterface $stream
35 * @param $header
36 *
37 * @return int
38 */
39 private function getLengthOfPossibleFilenameHeader(\YoastSEO_Vendor\Psr\Http\Message\StreamInterface $stream, $header)
40 {
41 $filename_header_length = 0;
42 if (\substr(\bin2hex($header), 6, 2) === '08') {
43 // we have a filename, read until nil
44 $filename_header_length = 1;
45 while ($stream->read(1) !== \chr(0)) {
46 $filename_header_length++;
47 }
48 }
49 return $filename_header_length;
50 }
51 }
52