northrook / compressor
A PHP compression library.
Installs: 13
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/northrook/compressor
Requires
- php: >=8
 - ext-zlib: *
 
Requires (Dev)
- northrook/dev-env: dev-main
 
This package is auto-updated.
Last update: 2025-10-20 15:53:30 UTC
README
A lossless data compression library using PHP zlib.
Important
This package is still in development.
While it is considered MVP and stable, it may still undergo breaking changes.
Installation
composer require northrook/compressor
Usage
Compressing
Compress data using the Compressor::compress() function, it has two arguments:
mixed $datato compress. It is type-checked, and serialized using the native\serializefunction if it us not a string,int $levelof compression, from 0 to 9, defaulting to 9.
$example = \Northrook\Compressor::compress( $_SERVER ) : Compressor; $example->data; // Resulting compressed string $example->report // "Compressed data array, from 3.54kB to 1.41kB, saving 60.17%."
Decompressing
To decompress the data, use the decompress static function, it has two arguments:
string $datato decompress. Unserialized by default.bool $rawReturns the decompressed data as-is.
$server_array = \Northrook\Compressor::decompress( $example ) : mixed; $server_array //
Tip
Greater compression may be achieved by pre-serializing the data in some cases.
Just don't forget to set decompress( $data, true ), and apply the appropriate deserializer externally.
Arrays of HTML-like strings typically benefit from using json_encode, typically ~2% smaller than serialize.
Notes
The Compressor class is \Stringable, but also provides the readonly data property for unambiguous access.