cataphract/libarchive

PHP extension for reading and writing archives via libarchive

Maintainers

Package info

github.com/cataphract/php-libarchive

Language:C

Type:php-ext

Ext name:ext-archive

pkg:composer/cataphract/libarchive

Statistics

Installs: 12

Dependents: 0

Suggesters: 0

Stars: 2

v0.2.0 2026-03-10 18:39 UTC

This package is auto-updated.

Last update: 2026-04-16 23:58:26 UTC


README

PHP extension for reading archives (tar, zip, 7-zip, cpio, …) via libarchive. Supports all compression filters the installed libarchive recognises (gzip, bzip2, xz, zstd, …).

Requirements

  • PHP 8.0+
  • libarchive 3.x

Installation

pie install cataphract/libarchive

Usage

Extract an archive to disk

use libarchive\Archive;
use libarchive\EXTRACT_PERM;
use libarchive\EXTRACT_TIME;

$archive = new Archive('/path/to/archive.tar.gz', EXTRACT_PERM | EXTRACT_TIME);

chdir('/tmp/extract');

foreach ($archive as $entry) {
    echo $entry->pathname . "\n";
    $archive->extractCurrent($entry);
}

Read an entry as a stream

use libarchive\Archive;

$archive = new Archive('/path/to/archive.zip');

foreach ($archive as $entry) {
    if ($entry->pathname === 'data.json') {
        $stream = $archive->currentEntryStream();
        $contents = stream_get_contents($stream);
        fclose($stream);
        break;
    }
}

API

See libarchive.stub.php for the full class and constant documentation.

License

MIT