gbeushausen / distill
智能压缩文件提取器
0.9.11
2019-11-10 05:32 UTC
Requires
- php: >=7.2.0
- pimple/pimple: ~3.0
- symfony/filesystem: ~3.4|^4.0
- symfony/process: ~3.4|^4.0
Requires (Dev)
- mockery/mockery: 0.9.1
- raulfraile/ladybug: ~1.0
- symfony/finder: ~3.4|^4.0
Suggests
- ext-rar: Allows to uncompress rar files using RarArchive
- ext-zip: Allows to uncompress zip files using ZipArchive
This package is auto-updated.
Last update: 2024-09-10 16:37:37 UTC
README
Distill可以从压缩存档中提取文件。
功能
- 可以从
ar
、bz2
、cab
、chm
、cpio
、deb
、dmg
、epub
、gz
、phar
、rar
、shar
、tar
、tar.bz2
、tar.gz
、tar.xz
、wim
、7z
、xz
、Z
和zip
归档中提取文件。 - 底层采用不同的解压缩方法:PHP 扩展、命令行二进制文件、第三方库以及纯 PHP 的回退方法。
- 如果存在多个可用格式,选择正确文件的策略。策略可以是基于最小化带宽或优化解压缩速度。
安装
建议通过 Composer 安装 Distill。将 raulfraile/distill
包要求添加到您的 composer.json
文件中
{ "require": { "gbeushausen/distill": "@stable" } }
提示:您应该浏览 gbeushausen/distill 页面以选择要使用的稳定版本,避免使用 @stable
元数据约束。
否则,您可以自行安装库并设置自动加载器。
示例
use Distill\Distill; $distill = new Distill(); $distill->extract(__DIR__ . '/../tests/files/file_ok.zip', __DIR__ . '/extract');
格式
策略
Distill允许在存在多个可用格式的情况下选择一个格式。例如,对于想要通过选择具有更高压缩比且在客户端机器上可用的压缩格式来减少带宽使用的安装程序来说,这可能很有用。
库提供了三种策略(可以添加更多)
- 最小尺寸(默认):选择具有更高压缩比的文件。
- 解压缩速度:选择解压缩速度较快的文件。
- 随机:随机获取一个系统可以解压缩的文件。
use Distill\Distill; $distill = new Distill(); $preferredFile = $distill ->getChooser() ->setStrategy(new \Distill\Strategy\MinimumSize()) ->addFile('http://get.symfony.com/Symfony_Standard_Vendors_2.5.3.zip') ->addFile('http://get.symfony.com/Symfony_Standard_Vendors_2.5.3.tgz') ->getPreferredFile(); echo $preferredFile; // http://get.symfony.com/Symfony_Standard_Vendors_2.5.3.tgz
use Distill\Distill; $distill = new Distill(); $preferredFile = $distill ->getChooser() ->setStrategy(new \Distill\Strategy\UncompressionSpeed()) ->addFile('test.phar') ->addFile('test.zip') ->getPreferredFile(); echo $preferredFile; // test.zip
命令行工具
如果您正在寻找用于提取压缩文件的命令行工具,请查看distill-cli,它使用此库
$ distill-cli extract archive.tar.gz path/
贡献
请参阅 CONTRIBUTING 文件。
运行测试
安装 Composer 的 dev
依赖项
$ composer install --dev
然后,使用 PHPUnit 运行测试套件
$ phpunit
致谢
- Raul Fraile (@raulfraile)
- 所有贡献者
许可协议
Distill 在 MIT 许可证下发布。有关详细信息,请参阅捆绑的 LICENSE 文件。