piwik/decompress

此包已被废弃,不再维护。作者建议使用 matomo/decompress 包。

2.1.0 2020-01-11 23:34 UTC

This package is auto-updated.

Last update: 2024-07-29 08:22:45 UTC


README

提供多个文件解压缩适配器的组件。

PHPUnit

支持以下压缩格式:

  • Zip
  • Gzip
  • Bzip
  • Tar (gzip 或 bzip)

以下适配器:

  • PclZip,基于 PclZip 库
  • ZipArchive,基于 PHP 的 Zip 扩展
  • Gzip,基于 PHP 的原生 Gzip 函数
  • Bzip,基于 PHP 的原生 Bzip 函数
  • Tar,基于 PEAR 的 Archive_Tar 库

安装

使用 Composer

{
    "require": {
        "matomo/decompress": "^2.1"
    }
}

使用方法

所有适配器都实现了相同的 API,因为它们实现了 Matomo\Decompress\DecompressInterface

// Extracting Gzip file
$extractor = new \Matomo\Decompress\Gzip('file.gz');

$extractedFiles = $extractor->extract('some/directory');

if ($extractedFiles === 0) {
    echo $extractor->errorInfo();
}

// Extracting Bzip file
$extractor = new \Matomo\Decompress\Bzip('file.bz');

$extractedFiles = $extractor->extract('some/directory');

if ($extractedFiles === 0) {
    echo $extractor->errorInfo();
}

// Extracting Zip file with ZipArchive
$extractor = new \Matomo\Decompress\ZipArchive('file.zip');

$extractedFiles = $extractor->extract('some/directory');

if ($extractedFiles === 0) {
    echo $extractor->errorInfo();
}

// Extracting Zip file with PclZip
$extractor = new \Matomo\Decompress\PclZip('file.zip');

$extractedFiles = $extractor->extract('some/directory');

if ($extractedFiles === 0) {
    echo $extractor->errorInfo();
}

// Extracting .tar.bz2 file
$extractor = new \Matomo\Decompress\Tar('file.tar.bz2', 'bz2');

$extractedFiles = $extractor->extract('some/directory');

if ($extractedFiles === 0) {
    echo $extractor->errorInfo();
}

// Extracting .tar.gz file
$extractor = new \Matomo\Decompress\Tar('file.tar.gz', 'gz');

$extractedFiles = $extractor->extract('some/directory');

if ($extractedFiles === 0) {
    echo $extractor->errorInfo();
}

许可

Decompress 组件在 LGPL v3.0 许可下发布。