1
0
mirror of https://github.com/danog/byte-stream.git synced 2024-11-26 20:04:51 +01:00
byte-stream/test/ZlibInputStreamTest.php

45 lines
1.2 KiB
PHP

<?php
namespace Amp\ByteStream\Test;
use Amp\ByteStream\InMemoryStream;
use Amp\ByteStream\IteratorStream;
use Amp\ByteStream\StreamException;
use Amp\ByteStream\ZlibInputStream;
use Amp\Loop;
use Amp\PHPUnit\TestCase;
use Amp\Producer;
class ZlibInputStreamTest extends TestCase {
public function testRead() {
Loop::run(function () {
$file1 = __DIR__ . "/fixtures/foobar.txt";
$file2 = __DIR__ . "/fixtures/foobar.txt.gz";
$stream = new IteratorStream(new Producer(function (callable $emit) use ($file2) {
$content = \file_get_contents($file2);
while ($content !== "") {
yield $emit($content[0]);
$content = \substr($content, 1);
}
}));
$gzStream = new ZlibInputStream($stream, \ZLIB_ENCODING_GZIP);
$buffer = "";
while (($chunk = yield $gzStream->read()) !== null) {
$buffer .= $chunk;
}
$this->assertSame(\file_get_contents($file1), $buffer);
});
}
public function testInvalidEncoding() {
$this->expectException(StreamException::class);
new ZlibInputStream(new InMemoryStream(""), 1337);
}
}