1
0
mirror of https://github.com/danog/byte-stream.git synced 2024-12-04 02:07:49 +01:00
byte-stream/examples/gzip-compress.php

20 lines
424 B
PHP
Raw Normal View History

2017-05-25 17:51:25 +02:00
<?php
use Amp\ByteStream\ZlibOutputStream;
use Amp\Loop;
use function Amp\ByteStream\getStdin;
use function Amp\ByteStream\getStdout;
2017-05-25 17:51:25 +02:00
require __DIR__."/../vendor/autoload.php";
2017-05-25 17:51:25 +02:00
Loop::run(function () {
$stdin = getStdin();
$stdout = getStdout();
2017-05-25 17:51:25 +02:00
$gzout = new ZlibOutputStream($stdout, ZLIB_ENCODING_GZIP);
while (($chunk = yield $stdin->read()) !== null) {
yield $gzout->write($chunk);
}
});