PHPackages                             temant/zip-archiver - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. temant/zip-archiver

ActiveLibrary[File &amp; Storage](/categories/file-storage)

temant/zip-archiver
===================

A general-purpose compression/decompression library supporting ZIP, TAR, GZ, BZ2, RAR and more

09PHPCI passing

Since Mar 17Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/EmadAlmahdi/Temant-ZipArchiver)[ Packagist](https://packagist.org/packages/temant/zip-archiver)[ RSS](/packages/temant-zip-archiver/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Temant Archiver
===============

[](#temant-archiver)

[![CI](https://github.com/EmadAlmahdi/Temant-ZipArchiver/actions/workflows/ci.yml/badge.svg)](https://github.com/EmadAlmahdi/Temant-ZipArchiver/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/9d3b144a83ba637ef7dee7a61024967283017df623aa1c2466202266dca43c1e/68747470733a2f2f706f7365722e707567782e6f72672f74656d616e742f61726368697665722f762f737461626c65)](https://packagist.org/packages/temant/archiver)[![Total Downloads](https://camo.githubusercontent.com/5c9247e2593569b10b9b93d38f0ec680d733924e30fc29136f6052caa9ab24aa/68747470733a2f2f706f7365722e707567782e6f72672f74656d616e742f61726368697665722f646f776e6c6f616473)](https://packagist.org/packages/temant/archiver)[![License](https://camo.githubusercontent.com/62792e956125008422bc38f564cc68655107b6e3c4548add83fa35715c0e7988/68747470733a2f2f706f7365722e707567782e6f72672f74656d616e742f61726368697665722f6c6963656e7365)](https://packagist.org/packages/temant/archiver)[![PHP Version Require](https://camo.githubusercontent.com/f240d1fef4b9e2171e0b2c5f10f9caa781fdd9fb9aa44f295c0c781946b1f955/68747470733a2f2f706f7365722e707567782e6f72672f74656d616e742f61726368697665722f726571756972652f706870)](https://packagist.org/packages/temant/archiver)[![PHPStan Level](https://camo.githubusercontent.com/14995ff65edea59395c224e37e4fc66f91c1e601c1a58311e3c6f38c4fe37feb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c2532306d61782d627269676874677265656e)](https://phpstan.org/)

A general-purpose compression/decompression library for PHP 8.1+ supporting ZIP, TAR, TAR.GZ, TAR.BZ2, GZIP, BZIP2, and RAR formats with a unified API.

Features
--------

[](#features)

- **7 archive formats** -- ZIP, TAR, TAR.GZ, TAR.BZ2, GZIP, BZIP2, RAR (decompress only)
- **Unified facade** -- single `Archiver` class handles all formats transparently
- **Auto-detection** -- format resolved automatically from file extension
- **Driver architecture** -- strategy pattern with per-format drivers, easily extensible
- **Password protection** -- AES-256 encryption for ZIP archives
- **Compression levels** -- 6 levels from `Fastest` to `Best` via a clean enum
- **Include/exclude filters** -- glob-based patterns for selective compress/extract
- **Progress callbacks** -- real-time feedback during compress and decompress operations
- **Archive inspection** -- list entries, get metadata, compression ratios, search/filter
- **Archive verification** -- test integrity without extracting
- **Archive comments** -- read and write comments (ZIP)
- **Custom drivers** -- register your own format drivers via the factory
- **PHPStan max level** -- fully statically analysed with zero errors
- **Zero dependencies** -- only requires `ext-phar` (format extensions are optional)

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

[](#requirements)

- PHP 8.1 or higher
- [Composer](https://getcomposer.org/)
- `ext-phar` (bundled with PHP)

Optional extensions (required only for their respective formats):

ExtensionFormats`ext-zip`ZIP`ext-zlib`GZIP, TAR.GZ`ext-bz2`BZIP2, TAR.BZ2`ext-rar`RAR (decompress only)Installation
------------

[](#installation)

```
composer require temant/archiver
```

Quick Start
-----------

[](#quick-start)

```
use Temant\Archiver\Archiver;

$archiver = new Archiver();

// Compress a directory to ZIP (format auto-detected from extension)
$archiver->compress('/path/to/directory', '/path/to/archive.zip');

// Decompress
$archiver->decompress('/path/to/archive.zip', '/path/to/output');
```

Usage
-----

[](#usage)

### Creating the Archiver

[](#creating-the-archiver)

```
use Temant\Archiver\Archiver;

$archiver = new Archiver();
```

The `Archiver` facade auto-detects the format from the file extension and delegates to the appropriate driver.

### Compressing Files

[](#compressing-files)

#### Directory to Archive

[](#directory-to-archive)

```
// ZIP
$archiver->compress('/path/to/directory', '/output/archive.zip');

// TAR
$archiver->compress('/path/to/directory', '/output/archive.tar');

// TAR.GZ
$archiver->compress('/path/to/directory', '/output/archive.tar.gz');

// TAR.BZ2
$archiver->compress('/path/to/directory', '/output/archive.tar.bz2');
```

#### Single File (GZIP / BZIP2)

[](#single-file-gzip--bzip2)

```
// GZIP -- single file only
$archiver->compress('/path/to/file.log', '/output/file.log.gz');

// BZIP2 -- single file only
$archiver->compress('/path/to/file.log', '/output/file.log.bz2');
```

### Decompressing Archives

[](#decompressing-archives)

```
// Extract to a directory
$archiver->decompress('/path/to/archive.zip', '/output/directory');

// Works with any supported format
$archiver->decompress('/path/to/archive.tar.gz', '/output/directory');
$archiver->decompress('/path/to/archive.rar', '/output/directory');
```

### Compression Levels

[](#compression-levels)

```
use Temant\Archiver\Enum\CompressionLevel;

$archiver->compress($source, $dest, [
    'level' => CompressionLevel::Best,    // Maximum compression
]);

// Available levels: None, Fastest, Fast, Normal, Good, Best
```

### Password Protection (ZIP)

[](#password-protection-zip)

```
// Compress with AES-256 encryption
$archiver->compress($source, 'secret.zip', [
    'password' => 'my-secret-password',
]);

// Decompress with password
$archiver->decompress('secret.zip', $output, [
    'password' => 'my-secret-password',
]);
```

### Include / Exclude Filters

[](#include--exclude-filters)

```
// Only include PHP files
$archiver->compress($source, 'code.zip', [
    'include' => ['*.php'],
]);

// Exclude log files and the vendor directory
$archiver->compress($source, 'project.zip', [
    'exclude' => ['*.log', 'vendor/*'],
]);

// Filters also work on decompress
$archiver->decompress('archive.zip', $output, [
    'include' => ['*.txt'],
]);
```

### Progress Callbacks

[](#progress-callbacks)

```
$archiver->compress($source, $dest, [
    'progress' => function (string $currentFile, int $processed, int $total): void {
        echo "{$currentFile}: {$processed}/{$total}\n";
    },
]);
```

### Archive Comments (ZIP)

[](#archive-comments-zip)

```
$archiver->compress($source, 'archive.zip', [
    'comment' => 'Release v1.2.0',
]);
```

### Listing Archive Entries

[](#listing-archive-entries)

```
use Temant\Archiver\DTO\ArchiveEntry;

$entries = $archiver->list('/path/to/archive.zip');

foreach ($entries as $entry) {
    echo $entry->path;           // relative path inside archive
    echo $entry->size;           // uncompressed size in bytes
    echo $entry->compressedSize; // compressed size in bytes
    echo $entry->isDirectory;    // bool
    echo $entry->modifiedTime;   // Unix timestamp
    echo $entry->compressionRatio(); // e.g. 0.65
}
```

### Archive Information

[](#archive-information)

```
use Temant\Archiver\DTO\ArchiveInfo;

$info = $archiver->info('/path/to/archive.zip');

echo $info->format;               // ArchiveFormat::Zip
echo $info->fileCount;            // number of files
echo $info->directoryCount;       // number of directories
echo $info->totalSize;            // total uncompressed size
echo $info->compressedSize;       // total compressed size
echo $info->compressionRatio();   // overall ratio
echo $info->formattedTotalSize(); // e.g. "1.24 MB"

// Search and filter entries
$phpFiles = $info->searchEntries('*.php');
$byExtension = $info->entriesByExtension('json');
```

### Verifying Archives

[](#verifying-archives)

```
$isValid = $archiver->verify('/path/to/archive.zip'); // true or false
```

### Format Detection

[](#format-detection)

```
use Temant\Archiver\Enum\ArchiveFormat;

$format = $archiver->detectFormat('/path/to/archive.tar.gz');
// ArchiveFormat::TarGz

// Check format capabilities
$format->supportsDirectories(); // true
$format->supportsPassword();    // false
$format->supportsCompression(); // true
$format->isDecompressOnly();    // false
```

### Using Specific Drivers

[](#using-specific-drivers)

```
$driver = $archiver->driver(ArchiveFormat::Zip);
$driver->compress($source, $dest, $options);
```

### Registering Custom Drivers

[](#registering-custom-drivers)

```
use Temant\Archiver\ArchiverFactory;
use Temant\Archiver\Contract\ArchiverInterface;

$factory = $archiver->factory();
$factory->register(new MyCustomArchiver());
```

### Supported Formats

[](#supported-formats)

```
// All registered formats
$archiver->supportedFormats(); // [ArchiveFormat::Zip, ArchiveFormat::Tar, ...]
```

Supported Formats
-----------------

[](#supported-formats-1)

FormatExtension(s)CompressDecompressDirectoriesPasswordExtension RequiredZIP`.zip`YesYesYesAES-256`ext-zip`TAR`.tar`YesYesYesNo`ext-phar`TAR.GZ`.tar.gz`, `.tgz`YesYesYesNo`ext-zlib`TAR.BZ2`.tar.bz2`, `.tbz2`YesYesYesNo`ext-bz2`GZIP`.gz`, `.gzip`YesYesNoNo`ext-zlib`BZIP2`.bz2`, `.bzip2`YesYesNoNo`ext-bz2`RAR`.rar`NoYesYesYes`ext-rar`Exception Handling
------------------

[](#exception-handling)

All exceptions extend `ArchiverException` (which extends `RuntimeException`).

ExceptionWhen`CompressionException`Compression fails (invalid source, write error, unsupported operation)`DecompressionException`Decompression fails (invalid archive, password error, write error)`UnsupportedFormatException`Unrecognized file extension or missing PHP extension`ArchiverException`Base exception for general archive errors```
use Temant\Archiver\Exception\CompressionException;
use Temant\Archiver\Exception\UnsupportedFormatException;

try {
    $archiver->compress($source, 'archive.xyz');
} catch (UnsupportedFormatException $e) {
    // Unknown format
} catch (CompressionException $e) {
    // Compression failed
}
```

API Reference
-------------

[](#api-reference)

### Archiver (Facade)

[](#archiver-facade)

MethodDescription`compress(source, destination, options?)`Compress a file or directory`decompress(archive, destination, options?)`Decompress an archive`list(archive, options?)`List entries without extracting`info(archive)`Get archive metadata`verify(archive)`Test archive integrity`detectFormat(path)`Detect format from file extension`supportedFormats()`List all supported formats`driver(format)`Get a specific format driver`factory()`Access the underlying factory### Options

[](#options)

OptionTypeApplies ToDescription`password``string`ZIP, RAREncryption password`level``CompressionLevel`AllCompression level enum`include``string[]`ZIP, TARGlob patterns to include`exclude``string[]`ZIP, TARGlob patterns to exclude`comment``string`ZIPArchive comment`overwrite``bool`ZIPOverwrite existing files (default: true)`progress``callable`AllProgress callback### Enums

[](#enums)

#### `ArchiveFormat`

[](#archiveformat)

Cases: `Zip`, `Tar`, `TarGz`, `TarBz2`, `Gz`, `Bz2`, `Rar`

Methods: `fromPath()`, `extension()`, `supportsDirectories()`, `supportsPassword()`, `supportsCompression()`, `isDecompressOnly()`, `label()`

#### `CompressionLevel`

[](#compressionlevel)

Cases: `None` (0), `Fastest` (1), `Fast` (3), `Normal` (5), `Good` (7), `Best` (9)

Testing
-------

[](#testing)

```
# Run tests
vendor/bin/phpunit

# Run tests with coverage
vendor/bin/phpunit --coverage-text

# Run static analysis
vendor/bin/phpstan analyse

# Run both
vendor/bin/phpunit && vendor/bin/phpstan analyse
```

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance58

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3e96f21e803c229bcc4ec2e9b3f83535aa1723c9981a67d95513faee24e27d4f?d=identicon)[Slvstar](/maintainers/Slvstar)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/temant-zip-archiver/health.svg)

```
[![Health](https://phpackages.com/badges/temant-zip-archiver/health.svg)](https://phpackages.com/packages/temant-zip-archiver)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M125](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

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