PHPackages                             amitdugar/archiveutil - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. amitdugar/archiveutil

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

amitdugar/archiveutil
=====================

Smart single-file compressor/decompressor for zstd, pigz/gzip, and zip with password-protected ZIP support

1.0.3(4mo ago)01981MITPHPPHP ^8.2CI passing

Since Dec 12Pushed 4mo agoCompare

[ Source](https://github.com/amitdugar/archiveutil)[ Packagist](https://packagist.org/packages/amitdugar/archiveutil)[ Docs](https://github.com/amitdugar/archiveutil)[ RSS](/packages/amitdugar-archiveutil/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (5)Used By (1)

archiveutil
===========

[](#archiveutil)

Smart single-file compressor/decompressor with automatic backend selection (zstd → pigz/gzip → zip) and password-protected ZIP extraction.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Extensions: `zip`, `zlib`
- CLI tools on `PATH` for compression/decompression: `zstd` (preferred), `pigz`, `gzip`. If none are present, falls back to `ZipArchive` for `.zip`.
- Composer dependency: `symfony/process`

Installation
------------

[](#installation)

```
composer require amitdugar/archiveutil
```

API
---

[](#api)

### Compression

[](#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

[](#decompression)

- `decompressToFile(string $src, string $dstDir): string` — Extracts an archive into a directory (supports `.zst`, `.gz`, `.zip`, or plain `.csv` passthrough).
- `decompressToString(string $src): string` — Returns decompressed contents as a string.
- `findAndDecompressArchive(string $directory, string $filename): string` — Looks for `.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

[](#configuration)

- `setZstdLevel(int $level): void` — Default `19`.
- `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
-----

[](#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 /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

[](#password-protected-zips)

```
$sqlPath = ArchiveUtility::extractPasswordProtectedZip(
    '/path/dump.zip',
    'super-secret-password',
    sys_get_temp_dir()
);
```

Testing
-------

[](#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
-------

[](#license)

MIT License (see `LICENSE`).

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance74

Regular maintenance activity

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

148d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8706dc157a0364828ab72d9f6b8eda4c8dd9f976597f5741edb0b5d719ba3719?d=identicon)[amitdugar](/maintainers/amitdugar)

---

Top Contributors

[![amitdugar](https://avatars.githubusercontent.com/u/911981?v=4)](https://github.com/amitdugar "amitdugar (4 commits)")

---

Tags

compressionarchivezipgzipzstdpigz

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/amitdugar-archiveutil/health.svg)

```
[![Health](https://phpackages.com/badges/amitdugar-archiveutil/health.svg)](https://phpackages.com/packages/amitdugar-archiveutil)
```

###  Alternatives

[alchemy/zippy

Zippy, the archive manager companion

47522.6M51](/packages/alchemy-zippy)[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.

2791.6M7](/packages/wapmorgan-unified-archive)[raulfraile/distill

Smart compressed files extractor

228190.4k9](/packages/raulfraile-distill)[konstantin-kuklin/assetic-static-gzip-bundle

Provide static gzip compression for css,js files via AsseticBundle

149.2k1](/packages/konstantin-kuklin-assetic-static-gzip-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
