Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Archive Tar Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.


Implementation Patterns

Core Workflows

  • 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;
    

New/Improved Features (1.6.0)

  • Large file support: PR #51 introduces optimizations for handling large archives (though memory constraints still apply; see Gotchas).
  • Fixed _writeBlock return value: PR #53 resolves a potential edge case in custom stream handling.

Advanced Patterns

  • Prefix support: Prepend a directory to all files (e.g., for plugin bundles).
    $tar->setPrefix('myplugin/');
    
  • Error handling: Always check $tar->errorInfo() after operations.

Gotchas and Tips

Breaking Changes (1.6.0)

  • PHP 5.4/5.5 dropped: Projects using these versions must upgrade or seek alternatives (e.g., chadicus/tar or fony/tar).
  • Removed gzip shims: PR #58 eliminates internal gzopen/gztell wrappers. For .tar.gz files:
    • Use exec('tar -xzf ...') for CLI-based extraction.
    • Combine with Archive_Tar + gzdecode()/gzencode() for in-memory handling (less reliable).
    • Consider pear/archive_zip or modern alternatives for compressed archives.

Legacy Pitfalls

  • No gzip/bzip2 support: Core functionality remains limited to plain .tar. External tools or modern packages are required for compressed formats.
  • Multibyte paths: Unicode filenames may corrupt or truncate. Test thoroughly in target environments.
  • Permissions: Extracted files retain original permissions but may fail silently due to umask or filesystem restrictions.
  • Memory limits: Large archives still risk listContent()/extract() memory exhaustion. Use setTemporaryDir() to offload processing.

Performance and Extensibility

  • Large file optimizations: PR #51 improves handling but does not eliminate memory constraints. For very large archives, consider:
    • Streaming extraction with custom _readBlock() overrides.
    • Offloading to disk via setTemporaryDir().
  • Extensibility: Override _writeBlock() or _readBlock() for custom streams (e.g., S3), but documentation is sparse. Prefer modern packages for complex use cases.

Maintenance and Alternatives

  • No active maintenance: The 2025 release date in the original assessment is likely a placeholder. The package’s low adoption and PEAR dependency make it non-recommended for new projects.
  • Recommended alternatives:
    • Modern PHP: Use chadicus/tar (Composer) or fony/tar (Symfony ecosystem).
    • Compressed archives: pear/archive_zip (for .zip) or CLI tools (exec('tar')).
    • Legacy PEAR: If locked into PEAR, test thoroughly and monitor for future breakages.

Debugging Tips

  • Silent failures: Always check $tar->errorInfo() after operations.
  • Path normalization: Verify filenames with listContent() before extraction.
  • Symlinks/hardlinks: These may not round-trip correctly; test in staging.

Final Note: This package is only viable for legacy PEAR-based systems. For new Laravel projects, prioritize chadicus/tar or native PHP streams.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4