The popphp/pop-archive component provides a normalized interface and integrated adapters to let a user decompress, extract, package and compress files in a common archive format. The supported formats are:

  • tar
  • tar.gz
  • tar.bz2
  • zip
  • rar (extract-only)


Install it directly into your project:

composer require popphp/pop-archive

Or, include it in your composer.json file:

    "require": {
        "popphp/pop-archive": "2.1.*",

Extracting Files

You can pass it any of the supported archive file types and extract them:

$archive = new Pop\Archive\Archive('test.zip');

If the archive file is compressed, it will decompress it first. No extra step required:

$archive = new Pop\Archive\Archive('test.tar.gz');

Compressing Files

To add files to an archive, you pass it the archive filename (new or existing), and then call either the addFile method or the addFiles method:

$archive = new Pop\Archive\Archive('test.zip');

To compress an TAR archive file, you call the compress method and pass it either gz or bz2:

$archive = new Pop\Archive\Archive('test.tar');

// Creates the compressed archive file 'test.tar.bz2'