reactphp-legacy/socket-client

Gzip Decompress

Closed this issue · 1 comments

Hi how can i parse gzip compressed response?

clue commented

Thanks for your question @boardmain! Compression and decompression is actually out of scope for this library.

You may want to look into using an additional streaming (de-)compression library. The only such library I'm currently aware of is my clue/zlib-react.

Usage depends on your concrete application protocol, but it may look something like this:

$connector->create('example.com', 1337)->then(function (Stream $stream) {
    $decompressor = \Clue\React\Zlib\ZlibFilterStream::createGzipDecompressor();

    $decompressor->on('data', function ($data) {
        echo $data;
    });

    $stream->pipe($decompressor);
});

If you're looking into processing a decompressed, streaming HTTP body, you may have to wait for reactphp/http-client#37. This will probably handle this similarly internally.

I hope this helps 👍