PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 2.5.0
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v2.5.0
3.7.2 3.7.1 3.7.0 3.6.0 3.6.1 3.5.2 trunk 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.6.0 2.6.1 All 73 releases
stockpack / vendor / guzzlehttp / psr7 / src / InflateStream.php

InflateStream.php in StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more 2.5.0, at vendor/guzzlehttp/psr7/src/InflateStream.php

53 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace GuzzleHttp\Psr7;
3
4 use Psr\Http\Message\StreamInterface;
5
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 class InflateStream implements StreamInterface
18 {
19 use StreamDecoratorTrait;
20
21 public function __construct(StreamInterface $stream)
22 {
23 // read the first 10 bytes, ie. gzip header
24 $header = $stream->read(10);
25 $filenameHeaderLength = $this->getLengthOfPossibleFilenameHeader($stream, $header);
26 // Skip the header, that is 10 + length of filename + 1 (nil) bytes
27 $stream = new LimitStream($stream, -1, 10 + $filenameHeaderLength);
28 $resource = StreamWrapper::getResource($stream);
29 stream_filter_append($resource, 'zlib.inflate', STREAM_FILTER_READ);
30 $this->stream = $stream->isSeekable() ? new Stream($resource) : new NoSeekStream(new Stream($resource));
31 }
32
33 /**
34 * @param StreamInterface $stream
35 * @param $header
36 * @return int
37 */
38 private function getLengthOfPossibleFilenameHeader(StreamInterface $stream, $header)
39 {
40 $filename_header_length = 0;
41
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
50 return $filename_header_length;
51 }
52 }
53