定制 northrook/compressor 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 $data to compress. It is type-checked, and serialized using the native \serialize function if it us not a string,
  • int $level of 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 $data to decompress. Unserialized by default.
  • bool $raw Returns 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

MIT

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-17