gemorroj/archive7z
Composer 安装命令:
composer require gemorroj/archive7z
包简介
7z cli wrapper
README 文档
README
Features:
- Supported all 7-zip formats:
- Packing / unpacking:
7z,XZ,BZIP2,GZIP,TAR,ZIPandWIM. - Unpacking only:
APFS,AR,ARJ,Base64,CAB,CHM,CPIO,CramFS,DMG,EXT,FAT,GPT,HFS,IHEX,ISO,LZH,LZMA,MBR,MSI,NSIS,NTFS,QCOW2,RAR,RPM,SquashFS,UDF,UEFI,VDI,VHD,VHDX,VMDK,XARandZ.
- Packing / unpacking:
- List files and directories
- Get contents of any file from archive
- Delete files or directories
- Add files or directories
Requirements:
- PHP >= 8.2
- allow proc_open function
- for Windows: 7-zip >= 7.30 (https://www.7-zip.org/)
- for Linux/MacOs: 7-zip >= 21.01 or p7zip >= 9.38 (https://github.com/p7zip-project/p7zip)
Installation:
composer require gemorroj/archive7z
Notes:
- https://sourceforge.net/p/p7zip/discussion/383043/thread/fa143cf2/
- Correctly works only with filenames in UTF-8 encoding #15.
Recommendations:
Archive7z focuses on wrapping up the original 7-zip features. But it is not always convenient to use in your application. Therefore, we recommend that you always create your own wrapper class over Archive7z with the addition of higher-level logic.
Example:
<?php use Archive7z\Archive7z; class MyArchive7z extends Archive7z { protected $timeout = 120; protected $compressionLevel = 6; protected $overwriteMode = self::OVERWRITE_MODE_S; protected $outputDirectory = '/path/to/custom/output/directory'; } $obj = new MyArchive7z('path_to_7z_file.7z'); if (!$obj->isValid()) { throw new \RuntimeException('Incorrect archive'); } print_r($obj->getInfo()); /* Archive7z\Info Object ( [path:Archive7z\Info:private] => /full_path_to/test.7z [type:Archive7z\Info:private] => 7z [physicalSize:Archive7z\Info:private] => 165343 [headersSize:Archive7z\Info:private] => 241 [method:Archive7z\Info:private] => LZMA2:192k [solid:Archive7z\Info:private] => + [blocks:Archive7z\Info:private] => 1 [codePage:Archive7z\Info:private] => ) */ // $obj->setPassword('123'); // $obj->getEntries('test', 100) foreach ($obj->getEntries() as $entry) { print_r($entry); /* Archive7z\Entry Object ( [path:Archive7z\Entry:private] => 1.jpg [size:Archive7z\Entry:private] => 91216 [packedSize:Archive7z\Entry:private] => 165344 [modified:Archive7z\Entry:private] => 2013-06-10 09:56:07 [created:Archive7z\Entry:private] => [attributes:Archive7z\Entry:private] => A [crc:Archive7z\Entry:private] => 871345C2 [encrypted:Archive7z\Entry:private] => + [method:Archive7z\Entry:private] => LZMA:192k 7zAES:19 [block:Archive7z\Entry:private] => 0 [comment:Archive7z\Entry:private] => [hostOs:Archive7z\Entry:private] => [characteristics:Archive7z\Entry:private] => [folder:Archive7z\Entry:private] => [archive:Archive7z\Entry:private] => MyArchive7z Object ( [timeout:protected] => 60 [compressionLevel:protected] => 6 [overwriteMode:protected] => -aos [outputDirectory:protected] => /path/to/custom/output/directory [binary7z:Archive7z\Archive7z:private] => C:\Program Files\7-Zip\7z.exe [filename:Archive7z\Archive7z:private] => s:\VCS\Git\Archive7z\tests/fixtures/testPasswd.7z [password:Archive7z\Archive7z:private] => 123 [encryptFilenames:protected] => ) ) */ if ($entry->getPath() === 'test/test.txt') { $entry->extractTo('path_to_extract_folder/'); // extract the file } } echo $obj->getContent('test/test.txt'); // show content of the file $obj->setOutputDirectory('path_to_extract_folder/')->extract(); // extract the archive $obj->setOutputDirectory('path_to_extract_pass_folder/')->setPassword('pass')->extractEntry('test/test.txt'); // extract the password-protected entry $solidMode = new SolidMode(); $solidMode->setMode(SolidMode::OFF); $obj->setSolidMode($solidMode); $obj->addEntry(__DIR__); // add directory to the archive (include subfolders) $obj->addEntry(__FILE__); // add file to the archive $obj->renameEntry(__FILE__, __FILE__.'new'); // rename the file in the archive $obj->delEntry(__FILE__.'new'); // remove the file from the archive
gemorroj/archive7z 适用场景与选型建议
gemorroj/archive7z 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.04M 次下载、GitHub Stars 达 101, 最近一次更新时间为 2013 年 12 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「archive」 「7z」 「7zip」 「p7zip」 「7-zip」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gemorroj/archive7z 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gemorroj/archive7z 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gemorroj/archive7z 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Smart compressed files extractor
The 7-Zip integration for the Zippy.
PHP package to handle archives (.zip, .rar, .tar, .7z, .pdf) with unified API and hybrid solution (native/p7zip), designed to works with EPUB and CBA (.cbz, .cbr, .cb7, .cbt).
A trait to make an Eloquent model archivable
Smart compressed files extractor
OriginPHP Zip
统计信息
- 总下载量: 1.04M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 103
- 点击次数: 34
- 依赖项目数: 3
- 推荐数: 2
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2013-12-03