northrook/compressor
Composer 安装命令:
composer require northrook/compressor
包简介
A PHP compression library.
README 文档
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.
License
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-17