PHPackages                             clue/zlib-react - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. clue/zlib-react

ActiveLibrary

clue/zlib-react
===============

Streaming zlib compressor and decompressor for ReactPHP, supporting compression and decompression of GZIP, ZLIB and raw DEFLATE formats.

v1.2.0(2y ago)3165.6k↓43.8%53MITPHPPHP &gt;=7.0CI passing

Since Nov 12Pushed 7mo ago4 watchersCompare

[ Source](https://github.com/clue/reactphp-zlib)[ Packagist](https://packagist.org/packages/clue/zlib-react)[ Docs](https://github.com/clue/reactphp-zlib)[ Fund](https://clue.engineering/support)[ GitHub Sponsors](https://github.com/clue)[ RSS](/packages/clue-zlib-react/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (7)Dependencies (3)Versions (10)Used By (3)

clue/reactphp-zlib
==================

[](#cluereactphp-zlib)

[![CI status](https://github.com/clue/reactphp-zlib/actions/workflows/ci.yml/badge.svg)](https://github.com/clue/reactphp-zlib/actions)[![installs on Packagist](https://camo.githubusercontent.com/89b05a6f96c7b4cf3633dc0a317c05b9e4a42d44719adae07bcb7b99ea53073f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636c75652f7a6c69622d72656163743f636f6c6f723d626c7565266c6162656c3d696e7374616c6c732532306f6e2532305061636b6167697374)](https://packagist.org/packages/clue/zlib-react)

Streaming zlib compressor and decompressor for [ReactPHP](https://reactphp.org/), supporting compression and decompression of GZIP, ZLIB and raw DEFLATE formats.

**Table of contents**

- [Support us](#support-us)
- [Quickstart example](#quickstart-example)
- [Formats](#formats)
    - [GZIP format](#gzip-format)
    - [Raw DEFLATE format](#raw-deflate-format)
    - [ZLIB format](#zlib-format)
- [Usage](#usage)
    - [Compressor](#compressor)
    - [Decompressor](#decompressor)
- [Install](#install)
- [Tests](#tests)
- [License](#license)
- [More](#more)

Support us
----------

[](#support-us)

We invest a lot of time developing, maintaining and updating our awesome open-source projects. You can help us sustain this high-quality of our work by [becoming a sponsor on GitHub](https://github.com/sponsors/clue). Sponsors get numerous benefits in return, see our [sponsoring page](https://github.com/sponsors/clue)for details.

Let's take these projects to the next level together! 🚀

Quickstart example
------------------

[](#quickstart-example)

Once [installed](#install), you can use the following code to pipe a readable gzip file stream into an decompressor which emits decompressed data events for each individual log file chunk:

```
$stream = new React\Stream\ReadableResourceStream(fopen('access.log.gz', 'r'));

$decompressor = new Clue\React\Zlib\Decompressor(ZLIB_ENCODING_GZIP);
$stream->pipe($decompressor);

$decompressor->on('data', function ($data) {
    echo $data; // chunk of decompressed log data
});
```

See also the [examples](examples).

Formats
-------

[](#formats)

This library is a lightweight wrapper around the underlying zlib library. The zlib library offers a number of different formats (sometimes referred to as *encodings*) detailed below.

### GZIP format

[](#gzip-format)

This library supports the GZIP compression format as defined in [RFC 1952](https://tools.ietf.org/html/rfc1952). This is one of the more common compression formats and is used in several places:

- PHP: `ZLIB_ENCODING_GZIP` (PHP 5.4+ only)
- PHP: `gzdecode()` (PHP 5.4+ only) and `gzencode()`
- Files with `.gz` file extension, e.g. `.tar.gz` or `.tgz` archives (also known as "tarballs")
- `gzip` and `gunzip` (and family) command line tools
- [HTTP compression](https://en.wikipedia.org/wiki/HTTP_compression) with `Content-Encoding: gzip` header
- Java: `GZIPOutputStream`

Technically, this format uses [raw DEFLATE compression](#raw-deflate-format) wrapped in a GZIP header and footer:

```
10 bytes header (+ optional headers) + raw DEFLATE body + 8 bytes footer

```

### Raw DEFLATE format

[](#raw-deflate-format)

This library supports the raw DEFLATE compression format as defined in [RFC 1951](https://tools.ietf.org/html/rfc1951). The DEFLATE compression algorithm returns what we refer to as "raw DEFLATE format". This raw DEFLATE format is commonly wrapped in container formats instead of being used directly:

- PHP: `ZLIB_ENCODING_RAW` (PHP 5.4+ only)
- PHP: `gzdeflate()` and `gzinflate()`
- Wrapped in [GZIP format](#gzip-format)
- Wrapped in [ZLIB format](#zlib-format)

> Note: This format is not to be confused with what some people call "deflate format" or "deflate encoding". These names are commonly used to refer to what we call [ZLIB format](#zlib-format).

### ZLIB format

[](#zlib-format)

This library supports the ZLIB compression format as defined in [RFC 1950](https://tools.ietf.org/html/rfc1950). This format is commonly used in a streaming context:

- PHP: `ZLIB_ENCODING_DEFLATE` (PHP 5.4+ only)
- PHP: `gzcompress()` and `gzuncompress()`
- [HTTP compression](https://en.wikipedia.org/wiki/HTTP_compression) with `Content-Encoding: deflate` header
- Java: `DeflaterOutputStream`
- Qt's [`qCompress()`](https://doc.qt.io/archives/qt-4.8/qbytearray.html#qCompress)and [`qUncompress()`](https://doc.qt.io/archives/qt-4.8/qbytearray.html#qUncompress)uses the ZLIB format prefixed with the uncompressed length (as `UINT32BE`).

Technically, this format uses [raw DEFLATE compression](#raw-deflate-format) wrapped in a ZLIB header and footer:

```
2 bytes header (+ optional headers) + raw DEFLATE body + 4 bytes footer

```

> Note: This format is often referred to as the "deflate format" or "deflate encoding". This documentation avoids this name in order to avoid confusion with the [raw DEFLATE format](#raw-deflate-format).

Usage
-----

[](#usage)

All classes use the `Clue\React\Zlib` namespace.

### Compressor

[](#compressor)

The `Compressor` class can be used to compress a stream of data.

It implements the [`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface)and accepts uncompressed data on its writable side and emits compressed data on its readable side.

```
$encoding = ZLIB_ENCODING_GZIP; // or ZLIB_ENCODING_RAW or ZLIB_ENCODING_DEFLATE
$compressor = new Clue\React\Zlib\Compressor($encoding);

$compressor->on('data', function ($data) {
    echo $data; // compressed binary data chunk
});

$compressor->write($uncompressed); // write uncompressed data chunk
```

This is particularly useful in a piping context:

```
$input->pipe($filterBadWords)->pipe($compressor)->pipe($output);
```

For more details, see ReactPHP's [`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface).

### Decompressor

[](#decompressor)

The `Decompressor` class can be used to decompress a stream of data.

It implements the [`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface)and accepts compressed data on its writable side and emits decompressed data on its readable side.

```
$encoding = ZLIB_ENCODING_GZIP; // or ZLIB_ENCODING_RAW or ZLIB_ENCODING_DEFLATE
$decompressor = new Clue\React\Zlib\Decompressor($encoding);

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

$decompressor->write($compressed); // write compressed binary data chunk
```

This is particularly useful in a piping context:

```
$input->pipe($decompressor)->pipe($filterBadWords)->pipe($output);
```

For more details, see ReactPHP's [`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface).

Install
-------

[](#install)

The recommended way to install this library is [through Composer](https://getcomposer.org/). [New to Composer?](https://getcomposer.org/doc/00-intro.md)

This project follows [SemVer](https://semver.org/). This will install the latest supported version:

```
composer require clue/zlib-react:^1.2
```

See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP extensions besides `ext-zlib` and supports running on PHP 7 through current PHP 8+. It's *highly recommended to use the latest supported PHP version* for this project.

The `ext-zlib` extension is required for handling the underlying data compression and decompression. This extension is already installed as part of many PHP distributions out-of-the-box, e.g. it ships with Debian/Ubuntu-based PHP installations and Windows-based builds by default. If you're building PHP from source, you may have to [manually enable](https://www.php.net/manual/en/zlib.installation.php) it.

We're committed to providing a smooth upgrade path for legacy setups. If you need to support legacy PHP versions and legacy HHVM, you may want to check out the legacy `v0.2.x` release branch. This legacy release branch also provides an installation candidate that does not require `ext-zlib` during installation but uses runtime checks instead. In this case, you can install this project like this:

```
composer require "clue/zlib-react:^1.0||^0.2.2"
```

Tests
-----

[](#tests)

To run the test suite, you first need to clone this repo and then install all dependencies [through Composer](https://getcomposer.org/):

```
composer install
```

To run the test suite, go to the project root and run:

```
vendor/bin/phpunit
```

License
-------

[](#license)

This project is released under the permissive [MIT license](LICENSE).

> Did you know that I offer custom development services and issuing invoices for sponsorships of releases and for contributions? Contact me (@clue) for details.

More
----

[](#more)

- If you want to learn more about processing streams of data, refer to the documentation of the underlying [react/stream](https://github.com/reactphp/stream) component.
- If you want to process compressed tarballs (`.tar.gz` and `.tgz` file extension), you may want to use [clue/reactphp-tar](https://github.com/clue/reactphp-tar) on the decompressed stream.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance44

Moderate activity, may be stable

Popularity41

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 89.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~451 days

Recently: every ~498 days

Total

9

Last Release

227d ago

Major Versions

v0.2.x-dev → v1.0.02020-05-28

PHP version history (2 changes)v0.1.0PHP &gt;=5.3

v1.0.0PHP &gt;=7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/776829?v=4)[Christian Lück](/maintainers/clue)[@clue](https://github.com/clue)

---

Top Contributors

[![clue](https://avatars.githubusercontent.com/u/776829?v=4)](https://github.com/clue "clue (78 commits)")[![SimonFrings](https://avatars.githubusercontent.com/u/44357440?v=4)](https://github.com/SimonFrings "SimonFrings (8 commits)")[![PaulRotmann](https://avatars.githubusercontent.com/u/85174210?v=4)](https://github.com/PaulRotmann "PaulRotmann (1 commits)")

---

Tags

compressionreactphpgzipdeflatedecompressiongzinflatezlibRFC 1950RFC 1951RFC 1952

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/clue-zlib-react/health.svg)

```
[![Health](https://phpackages.com/badges/clue-zlib-react/health.svg)](https://phpackages.com/packages/clue-zlib-react)
```

###  Alternatives

[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78026.4M414](/packages/react-http)[wapmorgan/unified-archive

UnifiedArchive - an archive manager with unified interface of working with all popular archive formats (zip/7z/rar/gz/bz2/xz/cab/tar/tar.gz/tar.bz2/tar.x/tar.Z/...) for PHP with ability for listing, reading, extracting and creation + built-in console archive manager.

2791.6M7](/packages/wapmorgan-unified-archive)[raulfraile/distill

Smart compressed files extractor

228190.4k9](/packages/raulfraile-distill)[clue/docker-react

Async, event-driven access to the Docker Engine API, built on top of ReactPHP.

113154.9k1](/packages/clue-docker-react)[konstantin-kuklin/assetic-static-gzip-bundle

Provide static gzip compression for css,js files via AsseticBundle

149.2k1](/packages/konstantin-kuklin-assetic-static-gzip-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
