项目作者: splitbrain

项目描述 :
Pure-PHP implementation to read and write TAR and ZIP archives
高级语言: PHP
项目地址: git://github.com/splitbrain/php-archive.git
创建时间: 2015-02-20T14:39:10Z
项目社区:https://github.com/splitbrain/php-archive

开源协议:MIT License

下载


PHPArchive - Pure PHP ZIP and TAR handling

This library allows to handle new ZIP and TAR archives without the need for any special PHP extensions (gz and bzip are
needed for compression). It can create new files or extract existing ones.

To keep things simple, the modification (adding or removing files) of existing archives is not supported.

Install

Use composer:

php composer.phar require splitbrain/php-archive

Usage

The usage for the Zip and Tar classes are basically the same. Here are some
examples for working with TARs to get you started.

Check the API docs for more
info.

  1. require_once 'vendor/autoload.php';
  2. use splitbrain\PHPArchive\Tar;
  3. // To list the contents of an existing TAR archive, open() it and use
  4. // contents() on it:
  5. $tar = new Tar();
  6. $tar->open('myfile.tgz');
  7. $toc = $tar->contents();
  8. print_r($toc); // array of FileInfo objects
  9. // To extract the contents of an existing TAR archive, open() it and use
  10. // extract() on it:
  11. $tar = new Tar();
  12. $tar->open('myfile.tgz');
  13. $tar->extract('/tmp');
  14. // To create a new TAR archive directly on the filesystem (low memory
  15. // requirements), create() it:
  16. $tar = new Tar();
  17. $tar->create('myfile.tgz');
  18. $tar->addFile(...);
  19. $tar->addData(...);
  20. ...
  21. $tar->close();
  22. // To create a TAR archive directly in memory, create() it, add*()
  23. // files and then either save() or getArchive() it:
  24. $tar = new Tar();
  25. $tar->setCompression(9, Archive::COMPRESS_BZIP);
  26. $tar->create();
  27. $tar->addFile(...);
  28. $tar->addData(...);
  29. ...
  30. $tar->save('myfile.tbz'); // compresses and saves it
  31. echo $tar->getArchive(); // compresses and returns it

Differences between Tar and Zip: Tars are compressed as a whole, while Zips compress each file individually. Therefore
you can call setCompression before each addFile() and addData() function call.

The FileInfo class can be used to specify additional info like ownership or permissions when adding a file to
an archive.