定制 horde/compress 二次开发

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

邮箱: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.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固