本文整理汇总了PHP中bzcompress函数的典型用法代码示例。如果您正苦于以下问题:PHP bzcompress函数的具体用法?PHP bzcompress怎么用?PHP bzcompress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bzcompress函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDecodeThrowsErrorOnEmptyResult
/**
* @expectedException \Brainbits\Transcoder\Exception\DecodeFailedException
*/
public function testDecodeThrowsErrorOnEmptyResult()
{
$testString = '';
$encodedString = bzcompress($testString);
$result = $this->decoder->decode($encodedString);
$this->assertSame($testString, $result);
}
示例2: pack
/**
* Pack file by BZIP2 compressor.
*
* @param string $source
* @param string $destination
* @return string
*/
public function pack($source, $destination)
{
$data = $this->_readFile($source);
$bzData = bzcompress($data, 9);
$this->_writeFile($destination, $bzData);
return $destination;
}
示例3: create
public function create($paths, $filename = FALSE)
{
$archive = new Archive('tar');
foreach ($paths as $set) {
$archive->add($set[0], $set[1]);
}
$gzfile = bzcompress($archive->create());
if ($filename == FALSE) {
return $gzfile;
}
if (substr($filename, -8) !== '.tar.bz2') {
// Append tar extension
$filename .= '.tar.bz2';
}
// Create the file in binary write mode
$file = fopen($filename, 'wb');
// Lock the file
flock($file, LOCK_EX);
// Write the tar file
$return = fwrite($file, $gzfile);
// Unlock the file
flock($file, LOCK_UN);
// Close the file
fclose($file);
return (bool) $return;
}
示例4: render
public function render($maxUrls = NULL, $maxMegabytes = NULL, $compression = NULL)
{
if ($maxUrls && !count($this) > $maxUrls) {
throw new OutOfBoundsException('Sitemap has more than ' . $maxUrls . ' URLs and needs to be spitted');
}
$tree = new XML_Node('urlset');
$tree->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
foreach ($this->urls as $url) {
$node = new XML_Node('url');
$node->addChild(new XML_Node('loc', $url->getLocation()));
if ($datetime = $url->getDatetime()) {
$node->addChild(new XML_Node('lastmod', $datetime));
}
$tree->addChild($node);
}
$builder = new XML_Builder();
$xml = $builder->build($tree);
if ($compression) {
if (!in_array($compression, $this->compressions)) {
throw new OutOfRangeException('Available compression types are ' . join(", ", $this->compressions));
}
switch ($compression) {
case 'bz':
$xml = bzcompress($xml);
break;
case 'gz':
$xml = gzencode($xml);
break;
}
}
if ($maxMegabytes && strlen($xml) > $maxMegabytes * 1024 * 1024) {
throw new OutOfBoundsException('Rendered sitemap is to large (max: ' . $maxMegabytes . ' MB)');
}
return $xml;
}
示例5: server
function server()
{
list($dr, $nod) = split_right('/', $_GET['table'], 1);
$main = msql_read($dr, $nod, '');
//p($main);
if ($main) {
$dscrp = flux_xml($main);
}
$host = $_SERVER['HTTP_HOST'];
//$dscrp=str_replace('users/','http://'.$host.'/users/',$dscrp);
//$dscrp=str_replace('img/','http://'.$host.'/img/',$dscrp);
$xml = '<' . '?xml version="1.0" encoding="utf-8" ?' . '>' . "\n";
//iso-8859-1//
$xml .= '<rss version="2.0">' . "\n";
$xml .= '<channel>' . "\n";
$xml .= '<title>http://' . $host . '/msql/' . $_GET['table'] . '</title>' . "\n";
$xml .= '<link>http://' . $host . '/</link>' . "\n";
$xml .= '<description>' . count($main) . ' entries</description>' . "\n";
$xml .= $dscrp;
$xml .= '</channel>' . "\n";
$xml .= '</rss>' . "\n";
//$xml.='</xml>'."\n";
if ($_GET['bz2']) {
return bzcompress($xml);
}
if ($_GET["b64"]) {
return base64_encode($xml);
}
return utf8_encode($xml);
}
示例6: insertPageForMenuItem
public function insertPageForMenuItem($item)
{
$faker = Faker\Factory::create();
$this->insert('page', ['title' => $item['title'], 'path' => $item['path'], 'status' => TRUE, 'body' => base64_encode(bzcompress($faker->text)), 'type' => PageTypes::PAGE_TYPE]);
$pageId = $this->getAdapter()->getConnection()->lastInsertId();
return $pageId;
}
示例7: encrypt
/**
* Encode a string from the values that have been generated
*
* @param text string The string to be encoded
*
* @return string
*/
public static function encrypt($text)
{
$config = Config::settings('encrypt');
$base64key = $config['key'];
$base64ivector = $config['iv'];
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, base64_decode($base64key), bzcompress(trim($text)), MCRYPT_MODE_CBC, base64_decode($base64ivector)));
}
示例8: write_to_file
function write_to_file($filename, $stream_id, $content)
{
global $GLOBAL_CRON;
$file_ext = substr($filename, strrpos($filename, '.') + 1);
switch ($file_ext) {
case 'gz':
$string = gzencode($content, 9);
break;
case 'bz2':
$string = bzcompress($content, 9);
break;
default:
$string = $content;
break;
}
flush();
if (!$GLOBAL_CRON) {
echo $string;
} else {
echo "file " . $filename . " " . strlen($string) . "\n";
}
if ($stream_id) {
return fwrite($stream_id, $string);
}
}
示例9: encode
/**
* @inheritDoc
*/
public function encode($data)
{
$data = bzcompress($data, 9);
if (!$data) {
throw new EncodeFailedException("bzcompress returned no data.");
}
return $data;
}
示例10: compress
/**
* {@inheritdoc}
*/
public function compress($data, $length)
{
$output = @bzcompress(substr($data, 0, $length));
if (!is_string($output)) {
throw new InvalidInputDataException('The compression input data is invalid.', $output);
}
return $output;
}
示例11: var_export
/**
// You can use this class like that.
$test = new bzip2;
$test->makeBzip2('./','./toto.bzip2');
var_export($test->infosBzip2('./toto.bzip2'));
$test->extractBzip2('./toto.bzip2', './new/');
**/
function makeBzip2($src, $dest = false)
{
$Bzip2 = bzcompress(strpos(chr(0), $src) ? file_get_contents($src) : $src, 6);
if (empty($dest)) {
return $Bzip2;
} elseif (file_put_contents($dest, $Bzip2)) {
return $dest;
}
return false;
}
示例12: compress
public function compress($data = '', $blockSize = 4, $workFactor = 0)
{
if (!is_scalar($data)) {
return Error::set('Error', 'valueParameter', '1.(data)');
}
if (!is_numeric($blockSize) || !is_numeric($workFactor)) {
return Error::set('Error', 'numericParameter', '2.(blockSize) & 3.(workFactor)');
}
return bzcompress($data, $blockSize, $workFactor);
}
示例13: compress
function compress($str, $lvl)
{
global $compression_handler;
switch ($compression_handler) {
case 'no':
return $str;
case 'bzip2':
return bzcompress($str, $lvl);
default:
return gzcompress($str, $lvl);
}
}
示例14: CacheMakeEncode
function CacheMakeEncode($cacheFileName = null, $cacheContent = null, $cacheDirectory = null)
{
$content = base64_encode(bzcompress(serialize($cacheContent), 9));
$cont = "<?php";
$cont .= "\r\n";
$cont .= "\$content='" . $content . "';";
$cont .= "?>";
$fpindex = @fopen($cacheDirectory . $cacheFileName, "w+");
$fw = @fwrite($fpindex, $cont);
@fclose($fpindex);
return $fw;
}
示例15: export
/**
* Export data to a download file.
*
* BROWSER BUG:
* IE has problems with the use of attachment; needs atachment (someone at MS can't spell) or none.
* however ns under version 6 accepts this also.
* NS 6+ has problems with the absense of attachment; and the misspelling of attachment;
* at present ie 5 on mac gives wrong filename and NS 6+ gives wrong filename.
*
* @todo Currently supports only csv/excel mimetypes.
*
* @param string $data The content
* @param string $fileName Filename for the download
* @param string $type The type (csv / excel / xml)
* @param string $ext Extension of the file
* @param string $compression Compression method (bzip / gzip)
*/
public function export($data, $fileName, $type, $ext = '', $compression = '')
{
ob_end_clean();
if ($compression == 'bzip') {
$mime_type = 'application/x-bzip';
$ext = 'bz2';
} elseif ($compression == 'gzip') {
$mime_type = 'application/x-gzip';
$ext = 'gz';
} elseif ($type == 'csv') {
$mime_type = 'text/x-csv';
$ext = 'csv';
} elseif ($type == 'excel') {
$mime_type = 'application/octet-stream';
$ext = 'xls';
} elseif ($type == 'xml') {
$mime_type = 'text/xml';
$ext = 'xml';
} else {
$mime_type = 'application/octet-stream';
}
header('Content-Type: ' . $mime_type);
header('Content-Disposition: filename="' . $fileName . '.' . $ext . '"');
// Fix for downloading (Office) documents using an SSL connection in
// combination with MSIE.
if (($_SERVER['SERVER_PORT'] == '443' || Tools::atkArrayNvl($_SERVER, 'HTTP_X_FORWARDED_PROTO') == 'https') && preg_match('/msie/i', $_SERVER['HTTP_USER_AGENT'])) {
header('Pragma: public');
} else {
header('Pragma: no-cache');
}
header('Expires: 0');
// 1. as a bzipped file
if ($compression == 'bzip') {
if (@function_exists('bzcompress')) {
echo bzcompress($data);
}
} else {
if ($compression == 'gzip') {
if (@function_exists('gzencode')) {
// without the optional parameter level because it bug
echo gzencode($data);
}
} else {
if ($type == 'csv' || $type == 'excel') {
// in order to output UTF-8 content that Excel both on Windows and OS X will be able to successfully read
echo mb_convert_encoding($data, 'Windows-1252', 'UTF-8');
}
}
}
flush();
exit;
}