Skip to content

Commit 7737501

Browse files
Merge pull request #127 from marcoslois/master
Fix InflateStream not preserving isSeekable.
2 parents 99bfec2 + d84767d commit 7737501

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/InflateStream.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(StreamInterface $stream)
2727
$stream = new LimitStream($stream, -1, 10 + $filenameHeaderLength);
2828
$resource = StreamWrapper::getResource($stream);
2929
stream_filter_append($resource, 'zlib.inflate', STREAM_FILTER_READ);
30-
$this->stream = new Stream($resource);
30+
$this->stream = $stream->isSeekable() ? new Stream($resource) : new NoSeekStream(new Stream($resource));
3131
}
3232

3333
/**

tests/InflateStreamTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use GuzzleHttp\Psr7;
55
use GuzzleHttp\Psr7\InflateStream;
6+
use GuzzleHttp\Psr7\NoSeekStream;
67

78
class InflateStreamtest extends \PHPUnit_Framework_TestCase
89
{
@@ -22,6 +23,16 @@ public function testInflatesStreamsWithFilename()
2223
$this->assertEquals('test', (string) $b);
2324
}
2425

26+
public function testInflatesStreamsPreserveSeekable()
27+
{
28+
$content = $this->getGzipStringWithFilename('test');
29+
$seekable = Psr7\stream_for($content);
30+
$nonSeekable = new NoSeekStream(Psr7\stream_for($content));
31+
32+
$this->assertTrue((new InflateStream($seekable))->isSeekable());
33+
$this->assertFalse((new InflateStream($nonSeekable))->isSeekable());
34+
}
35+
2536
private function getGzipStringWithFilename($original_string)
2637
{
2738
$gzipped = bin2hex(gzencode($original_string));

0 commit comments

Comments
 (0)