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

20 lines
424 B
PHP

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