phparchive-纯PHP拉链和焦油处理
该库允许无需任何特殊的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类可用于指定其他信息,例如所有权或将文件添加到存档时。
