PharData::compress() - PharData类
PharData::compress()
(PHP 5 >= 5.3.0, PHP 7, PECL phar >= 2.0.0)
Compresses the entire tar/zip archive using Gzip or Bzip2 compression
说明
PharData::compress(int $compression[,string $extension]): objectFor tar archives, this method compresses the entire archive using gzip compression or bzip2 compression. The resulting file can be processed with the gunzip command/bunzip command, or accessed directly and transparently with the Phar extension.
For zip archives, this method fails with an exception. The zlib extension must be enabled to compress with gzip compression, the bzip2 extension must be enabled in order to compress with bzip2 compression.
In addition, this method automatically renames the archive, appending.gz,.bz2or removing the extension if passedPhar::NONEto remove compression. Alternatively, a file extension may be specified with the second parameter.
参数
$compressionCompression must be one ofPhar::GZ,Phar::BZ2to add compression, orPhar::NONEto remove compression.
$extensionBy default, the extension is.tar.gzor.tar.bz2for compressing a tar, and.tarfor decompressing.
返回值
A PharData object is returned.
错误/异常
Throws BadMethodCallException if the zlib extension is not available, or the bzip2 extension is not enabled.
范例
A PharData::compress() example
参见
- Phar::compress() Compresses the entire Phar archive using Gzip or Bzip2 compression
This is a very irritating bug. You can use this to get around it though: $data = 'some.test.string'; $phar = new PharData('test.tar'); $phar->compress(Phar::GZ, substr($data, strpos($data, '.') + 1));
This method destroys everything after the first dot in your filename and replaces it with the zip extension (.tar.gz, etc) Example: Ends up with a file named "2.tar.gz"
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!