amitdugar/archiveutil
Composer 安装命令:
composer require amitdugar/archiveutil
包简介
Smart single-file compressor/decompressor for zstd, pigz/gzip, and zip with password-protected ZIP support
README 文档
README
Smart single-file compressor/decompressor with automatic backend selection (zstd → pigz/gzip → zip) and password-protected ZIP extraction.
Requirements
- PHP 8.4 – 8.5
- Extensions:
zip,zlib - CLI tools on
PATHfor compression/decompression:zstd(preferred),pigz,gzip. If none are present, falls back toZipArchivefor.zip. - Composer dependency:
symfony/process
Installation
composer require amitdugar/archiveutil
API
Compression
compressFile(string $src, string $dst, ?string $backend = null): string— Compress a file. Adds the correct extension automatically.compressContent(string $content, string $dst, ?string $backend = null): string— Compress raw content to disk.pickBestBackend(): string— Chooses the best available backend based on installed tools.extensionForBackend(string $backend): string— Returns.zst,.gz, or.zip.
Decompression
decompressToFile(string $src, string $dstDir): string— Extracts an archive into a directory (supports.zst,.gz,.zip, or plain.csvpassthrough).decompressToString(string $src): string— Returns decompressed contents as a string.findAndDecompressArchive(string $directory, string $filename): string— Looks for<filename>.zst,.gz,.zip, then plain file.validateArchive(string $path): bool— Quick integrity check (treats password-protected ZIPs as valid).isPasswordProtected(string $path): bool— Detects encrypted ZIP archives.extractPasswordProtectedZip(string $zipPath, string $password, string $dstDir): string— Extracts the first SQL file from an encrypted ZIP.
Configuration
setZstdLevel(int $level): void— Default19.setZstdThreads(int $threads): void—0/-1= auto (all cores), otherwise a positive thread count.setMaxFileSize(?int $bytes): void— Guard compress operations with a maximum size (default: unlimited).setDirPermissions(int $permissions): void— Permissions used when creating destination directories.
Usage
use ArchiveUtil\ArchiveUtility; // Compress a CSV (auto-picks best available backend) $compressed = ArchiveUtility::compressFile('/path/data.csv', '/path/data.csv'); // Read contents from any supported archive $contents = ArchiveUtility::decompressToString($compressed); // Extract to a directory $extracted = ArchiveUtility::decompressToFile($compressed, sys_get_temp_dir()); // Find <dir>/file.csv.{zst|gz|zip} (or plain file) and return contents $raw = ArchiveUtility::findAndDecompressArchive('/path/dir', 'file.csv'); // Validate archive health (encrypted ZIPs count as valid) $isValid = ArchiveUtility::validateArchive($compressed); // Tuning ArchiveUtility::setMaxFileSize(25 * 1024 * 1024); // 25MB guard ArchiveUtility::setZstdLevel(19); ArchiveUtility::setZstdThreads(0); // auto threads
Password-protected ZIPs
$sqlPath = ArchiveUtility::extractPasswordProtectedZip( '/path/dump.zip', 'super-secret-password', sys_get_temp_dir() );
Testing
composer install
composer test
Tests isolate work in temp directories and skip backends that are not installed (e.g., zstd or pigz). No static analysis tools are bundled; add phpstan/psalm in your project if desired.
License
MIT License (see LICENSE).
amitdugar/archiveutil 适用场景与选型建议
amitdugar/archiveutil 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.82k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「compression」 「zip」 「archive」 「gzip」 「zstd」 「pigz」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 amitdugar/archiveutil 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 amitdugar/archiveutil 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 amitdugar/archiveutil 相关的其它包
同方向 / 同关键字的高下载量 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.82k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-08