wapmorgan/unified-archive
Composer 安装命令:
composer require wapmorgan/unified-archive
包简介
UnifiedArchive - an archive manager with unified interface of working with all popular archive formats (zip/7z/rar/gz/bz2/xz/cab/tar/tar.gz/tar.bz2/tar.x/tar.Z/...) for PHP with ability for listing, reading, extracting and creation + built-in console archive manager.
README 文档
README
UnifiedArchive - an archive manager with unified interface for different formats that works on wide variety of system configuration. It supports all basic operations on widespread formats and some format-specific features for most popular ones (zip, rar, 7z, tar).
Main purpose of this library is to create unified interface for popular archive formats, that works in various system configurations via different drivers, when there is no ability to update system configuration, when code delivered to another system configurations, or when you just want to install libraries and work. It's handy when there's need to support archive types regardless of the system configuration.
- Functions & Features
- How it works
- Quick start
- Built-in console archive manager
- Usage
- Drivers & formats
- Full API description
- Changelog
Functions & Features
UnifiedArchive is aimed to provide all operations on popular archive formats (zip, tar, rar, 7z) by all means and at better performance (depends on your OS/PHP configuration). Also, it allows to work with less popular archive types (with lack of functions).
Main functions:
- Open an archive with automatic format detection (more 20 formats).
- List archive content, calculate original size of archive
- Get details (original size, date of modification) of every archived file. Extract or stream archived file content
- Extract all archive content. Append an archive with new files or directories. Remove files from archive
- Create new archives with files/directories on disk and stream from memory
- Fully implemented PclZip-like interface for archives for all formats. Easy transition from old PclZip.
- Bundled with cli utility
Specific functions:
- Read (zip, rar) & set (zip) archive comment
- Open archives encrypted with password (zip, rar, 7z)
- Set passwords (7z, zip) for new archives
- Adjust compression level (zip, gzip, 7zip) for new archives
How it works
UnifiedArchive uses "drivers", which can be one of types:
- PHP Extensions
- Utilities + bridge
- Pure PHP
By default, UA goes top-down to select first available driver for passed archive. So, PHP Extension driver will be used (if available), then Utilities + bridge driver (if available), and then Pure PHP driver.
There is at least one driver in all three types, which handles zip format, so this format can be fully supported in any OS/PHP configuration:
- PHP extensions: zip / phar
- Utility + bridge: SevenZip / AlchemyZippy
- Pure: NelexaZip / SplitbrainPhpArchive
tar format (with compressed variants) supported by:
- PHP extension: phar
- Utility + bridge: SevenZip / AlchemyZippy
- Pure: TarByPear / SplitbrainPhpArchive
So, there is always one driver that supports popular formats, and you should not remember how to work with this concrete driver (zip/phar/SevenZip/AlchemyZippy/NelexaZip/SplitbrainPhpArchive), interface for them is uniform.
Quick start
Installation and configuration
Install library
composer require wapmorgan/unified-archive #Check supported formats with installed drivers ./vendor/bin/cam system:formats #Check supported functions for zip format ./vendor/bin/cam system:format zip
Install new driver
#Read installation instructions from ./vendor/bin/cam system:drivers #install missing drivers, for example pear/archive_tar composer require pear/archive_tar #check out driver functions ./vendor/bin/cam system:formats TarByPear #if needed, install extensions, cli tools and php libraries #to enable support of other formats
Usage
use \wapmorgan\UnifiedArchive\UnifiedArchive; $output_dir = '/var/www/extracted'; # Extraction $archive = UnifiedArchive::open('archive.zip'); // archive.rar, archive.tar.bz2 if (disk_free_space($output_dir) < $archive->getOriginalSize()) { throw new \RuntimeException('No needed space available. Need ' . ($archive->getOriginalSize() - disk_free_space($output_dir)) . ' byte(s) more'); } $extracted = $archive->extract($output_dir); echo 'Number of extracted files' . $extracted.PHP_EOL; # Archiving UnifiedArchive::create([ 'README.md' => '/default/path/to/README.md', '' => '/folder/with/content/', ], 'archive.zip');
Built-in console archive manager
UnifiedArchive is distributed with a unified console program to manipulate archives. It supports all formats and all operations on them that UnifiedArchive does, so it can be used to manipulate archives without other system software. To show help, launch it:
./vendor/bin/cam list # help ./vendor/bin/cam archive:info archive.tar.gz # archive information ./vendor/bin/cam files:list -l archive.tar.gz # files list (or files:table for table) ./vendor/bin/cam archive:extract archive.tar.gz ./OUTPUT/ # extraction all archive ./vendor/bin/cam archive:create --compression=maximum archive2.tar.gz ./OUTPUT/partners # archive creation from files
wapmorgan/unified-archive 适用场景与选型建议
wapmorgan/unified-archive 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.75M 次下载、GitHub Stars 达 280, 最近一次更新时间为 2014 年 05 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「compression」 「zip」 「archive」 「tar」 「iso」 「gzip」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wapmorgan/unified-archive 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wapmorgan/unified-archive 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wapmorgan/unified-archive 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asset Management for PHP
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.
Allow packages to be installed from a repository or tarball bundle that have multiple packages in the sub-folders
Iteration tools for PHP
Convert and operate with FIPS codes for states, counties, etc.
Yii2 integration for TinyPng
统计信息
- 总下载量: 1.75M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 287
- 点击次数: 46
- 依赖项目数: 9
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2014-05-19