pear/archive_tar
PEAR Archive_Tar handles TAR archives in PHP: create, list, extract, and append files. Supports gzip (zlib), bzip2 (bz2), and LZMA2/XZ compression when extensions are available.
The pear/archive_tar package (now updated to 1.6.0) remains a PEAR-based solution for .tar archive manipulation, though it is increasingly niche due to its reliance on legacy PHP versions and PEAR. This release drops PHP 5.4/5.5 support, requiring PHP 5.6+ (or ideally PHP 7.x+ for stability).
Install via PEAR:
pear install pear/archive_tar
Or include manually in Composer projects (e.g., via pear-core-minimal).
First use case: Extract a .tar file (unchanged):
require_once 'Archive/Tar.php';
$tar = new Archive_Tar('archive.tar');
if ($tar->extract('./output_dir')) {
echo "Extracted successfully";
}
Check the examples/ directory in the source for additional patterns.
Reading archives: Use listContent() to inspect contents without extraction.
$files = $tar->listContent();
foreach ($files as $file) {
echo $file['filename'] . " ({$file['size']} bytes)\n";
}
Adding files/directories: Use add() with an array of paths.
$tar->add(['file1.txt', 'dir/']);
String-based operations: Generate tar content in memory for streaming.
$data = $tar->createArchiveString(['file1.txt']);
header('Content-Type: application/x-tar');
echo $data;
_writeBlock return value: PR #53 resolves a potential edge case in custom stream handling.$tar->setPrefix('myplugin/');
$tar->errorInfo() after operations.chadicus/tar or fony/tar).gzopen/gztell wrappers. For .tar.gz files:
exec('tar -xzf ...') for CLI-based extraction.Archive_Tar + gzdecode()/gzencode() for in-memory handling (less reliable).pear/archive_zip or modern alternatives for compressed archives..tar. External tools or modern packages are required for compressed formats.umask or filesystem restrictions.listContent()/extract() memory exhaustion. Use setTemporaryDir() to offload processing._readBlock() overrides.setTemporaryDir()._writeBlock() or _readBlock() for custom streams (e.g., S3), but documentation is sparse. Prefer modern packages for complex use cases.chadicus/tar (Composer) or fony/tar (Symfony ecosystem).pear/archive_zip (for .zip) or CLI tools (exec('tar')).$tar->errorInfo() after operations.listContent() before extraction.Final Note: This package is only viable for legacy PEAR-based systems. For new Laravel projects, prioritize chadicus/tar or native PHP streams.
How can I help you explore Laravel packages today?