cataphract / libarchive
PHP extension for reading and writing archives via libarchive
Package info
github.com/cataphract/php-libarchive
Language:C
Type:php-ext
Ext name:ext-archive
pkg:composer/cataphract/libarchive
v0.2.0
2026-03-10 18:39 UTC
Requires
- php: ^8.0
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