php archive
1.0.0
該庫允許無需任何特殊的PHP擴展即可處理新的拉鍊和焦油檔案(GZ和BZIP需要進行壓縮)。它可以創建新文件或提取現有文件。
為了保持簡單,不支持現有檔案的修改(添加或刪除文件)。
使用作曲家:
php composer.phar require splitbrain/php-archive
拉鍊和焦油類的用法基本相同。以下是與焦油合作的一些示例,可以讓您入門。
檢查API文檔以獲取更多信息。
require_once ' vendor/autoload.php ' ;
use splitbrain PHPArchive Tar ;
// To list the contents of an existing TAR archive, open() it and use
// contents() on it:
$ tar = new Tar ();
$ tar -> open ( ' myfile.tgz ' );
$ toc = $ tar -> contents ();
print_r ( $ toc ); // array of FileInfo objects
// To extract the contents of an existing TAR archive, open() it and use
// extract() on it:
$ tar = new Tar ();
$ tar -> open ( ' myfile.tgz ' );
$ tar -> extract ( ' /tmp ' );
// To create a new TAR archive directly on the filesystem (low memory
// requirements), create() it:
$ tar = new Tar ();
$ tar -> create ( ' myfile.tgz ' );
$ tar -> addFile (...);
$ tar -> addData (...);
. . .
$ tar -> close ();
// To create a TAR archive directly in memory, create() it, add*()
// files and then either save() or getArchive() it:
$ tar = new Tar ();
$ tar -> setCompression ( 9 , Archive:: COMPRESS_BZIP );
$ tar -> create ();
$ tar -> addFile (...);
$ tar -> addData (...);
. . .
$ tar -> save ( ' myfile.tbz ' ); // compresses and saves it
echo $ tar -> getArchive (); // compresses and returns it焦油和拉鍊之間的差異:焦油整體被壓縮,而拉鍊則分別壓縮每個文件。因此,您可以在每個addFile()和addData()函數調用之前調用setCompression 。
FileInfo類可用於指定其他信息,例如所有權或將文件添加到存檔時。