1
0
mirror of https://github.com/danog/byte-stream.git synced 2024-11-30 04:19:23 +01:00
byte-stream/examples/gzip-compress.php
2017-05-25 17:51:25 +02:00

20 lines
471 B
PHP

<?php
use Amp\ByteStream\ResourceInputStream;
use Amp\ByteStream\ResourceOutputStream;
use Amp\ByteStream\ZlibOutputStream;
use Amp\Loop;
require __DIR__ . "/../vendor/autoload.php";
Loop::run(function () {
$stdin = new ResourceInputStream(STDIN);
$stdout = new ResourceOutputStream(STDOUT);
$gzout = new ZlibOutputStream($stdout, ZLIB_ENCODING_GZIP);
while (($chunk = yield $stdin->read()) !== null) {
yield $gzout->write($chunk);
}
});