horde/compress 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

horde/compress

Composer 安装命令:

composer require horde/compress

包简介

Compression library

README 文档

README

A PHP library for creating and extracting compressed archives and encoded transport formats. Supports ZIP, TAR, GZIP, RAR (read-only), DBX (read-only) and for handling Microsoft TNEF (winmail.dat) decoding.

Installation

composer require horde/compress

Optional dependencies

Package Purpose
horde/stream_filter CRC32 stream filter for ZIP compression with resource handles
horde/icalendar iCalendar generation from TNEF meeting requests
horde/mapi MAPI property decoding for TNEF attachments
horde/mail RFC 822 address parsing in TNEF messages
ext-zlib Required for Gzip driver

Usage

CompressFactory

use Horde\Compress\CompressFactory;

$factory = new CompressFactory();
$zip = $factory->create('zip');
$tar = $factory->create('tar');
$gzip = $factory->create('gzip');

Pass a PSR-3 logger to the factory for diagnostic output:

$factory = new CompressFactory($logger);
$zip = $factory->create('zip');

Creating a ZIP archive

use Horde\Compress\CompressFactory;
use Horde\Compress\Driver\Zip;

$zip = (new CompressFactory())->create('zip');

$files = [
    ['data' => 'Hello World', 'name' => 'hello.txt', 'time' => time()],
    ['data' => file_get_contents('image.png'), 'name' => 'image.png', 'time' => filemtime('image.png')],
];

$archive = $zip->compress($files);
file_put_contents('archive.zip', $archive);

Extracting a ZIP archive

use Horde\Compress\Driver\Zip;

$zip = (new CompressFactory())->create('zip');
$data = file_get_contents('archive.zip');

// List contents
$listing = $zip->decompress($data, ['action' => Zip::ZIP_LIST]);
foreach ($listing as $entry) {
    echo $entry['name'] . ' (' . $entry['size'] . " bytes)\n";
}

// Extract a specific file by index
$content = $zip->decompress($data, ['action' => Zip::ZIP_DATA, 'info' => $listing, 'key' => 0]);

Creating a TAR archive

use Horde\Compress\CompressFactory;

$tar = (new CompressFactory())->create('tar');

$files = [
    ['data' => 'content', 'name' => 'file.txt', 'time' => time()],
];

$archive = $tar->compress($files);
file_put_contents('archive.tar', $archive);

Compressing a directory

$tar = (new CompressFactory())->create('tar');
$archive = $tar->compressDirectory('/path/to/directory');

Decompressing GZIP data

$gzip = (new CompressFactory())->create('gzip');
$raw = $gzip->decompress(file_get_contents('file.gz'));

Decoding TNEF (winmail.dat)

use Horde\Compress\Tnef\TnefDecoder;

$decoder = new TnefDecoder();
$parts = $decoder->decompress(file_get_contents('winmail.dat'));

foreach ($parts as $part) {
    echo $part['name'] . ' (' . $part['type'] . '/' . $part['subtype'] . ")\n";
}

// Access message metadata
$msgInfo = $decoder->getMsgInfo();
echo 'Subject: ' . $msgInfo->subject . "\n";

Reading RAR archives (listing only)

$rar = (new CompressFactory())->create('rar');
$listing = $rar->decompress(file_get_contents('archive.rar'));

foreach ($listing as $entry) {
    echo $entry['name'] . ' (' . $entry['size'] . " bytes)\n";
}

Architecture

src/
├── Base.php                   # Abstract base class with logger support
├── CompressFactory.php        # Factory — creates driver instances by name
├── CompressorInterface.php    # Contract: compress, decompress, compressFiles, compressDirectory
├── Exception.php              # Library exception
├── Translation.php            # Gettext translation wrapper
├── Driver/
│   ├── Dbx.php                # Outlook Express DBX mailbox extraction
│   ├── Gzip.php               # RFC 1952 gzip decompress
│   ├── Rar.php                # RAR archive listing (read-only)
│   ├── Tar.php                # POSIX tar create/extract, SplFileInfo support
│   └── Zip.php                # ZIP create/extract, stream resource support
└── Tnef/
    ├── BufferReaderTrait.php   # Binary buffer reading (little-endian ints)
    ├── Date.php                # TNEF date attribute → Horde_Date
    ├── File.php                # TNEF file attachment object
    ├── Icalendar.php           # TNEF meeting request → iCalendar
    ├── MessageData.php         # TNEF message envelope (subject, from, date)
    ├── Rtf.php                 # Compressed RTF extraction
    ├── TnefDecoder.php         # Main TNEF parser
    ├── TnefObject.php          # Base TNEF object
    ├── TnefObjectInterface.php # Contract for TNEF attribute handlers
    └── VTodo.php               # TNEF task → vTodo

Upgrading

See doc/UPGRADING.md for the migration guide from the legacy Horde_Compress (PSR-0) API to the modern Horde\Compress (PSR-4) API.

Requirements

  • PHP 8.1+
  • horde/exception ^3
  • horde/mime ^3
  • horde/translation ^3
  • horde/util ^3

License

LGPL-2.1-only. See LICENSE for details.

horde/compress 适用场景与选型建议

horde/compress 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.83k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「zip」 「gzip」 「TNEF」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 horde/compress 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 horde/compress 我们能提供哪些服务?
定制开发 / 二次开发

基于 horde/compress 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.83k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 12
  • 依赖项目数: 8
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 5
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-2.1-only
  • 更新时间: 2023-10-26