downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

bzclose> <范例
[edit] Last updated: Sun, 19 May 2013

view this page in

Bzip2 函数

Table of Contents

  • bzclose — 关闭一个 bzip2 文件
  • bzcompress — 把一个字符串压缩成 bzip2 编码数据
  • bzdecompress — 解压经 bzip2 编码过的数据
  • bzerrno — 返回一个 bzip2 错误码
  • bzerror — 返回包含 bzip2 错误号和错误字符串的一个 array
  • bzerrstr — 返回一个 bzip2 的错误字符串
  • bzflush — 强制写入所有写缓冲区的数据
  • bzopen — 打开一个经 bzip2 压缩过的文件
  • bzread — bzip2 文件二进制安全地读取
  • bzwrite — 二进制安全地写入 bzip2 文件


add a note add a note User Contributed Notes Bzip2 函数 - [1 notes]
up
0
ec10 at gmx dot net
8 years ago
<?php
/**
 * @return bool
 * @param string $in
 * @param string $out
 * @desc compressing the file with the bzip2-extension
*/
function bzip2 ($in, $out)
{
    if (!
file_exists ($in) || !is_readable ($in))
        return
false;
    if ((!
file_exists ($out) && !is_writeable (dirname ($out)) || (file_exists($out) && !is_writable($out)) ))
        return
false;
   
   
$in_file = fopen ($in, "rb");
   
$out_file = bzopen ($out, "wb");
   
    while (!
feof ($in_file)) {
       
$buffer = fgets ($in_file, 4096);
        
bzwrite ($out_file, $buffer, 4096);
    }

   
fclose ($in_file);
   
bzclose ($out_file);
   
    return
true;
}

/**
 * @return bool
 * @param string $in
 * @param string $out
 * @desc uncompressing the file with the bzip2-extension
*/
function bunzip2 ($in, $out)
{
    if (!
file_exists ($in) || !is_readable ($in))
        return
false;
    if ((!
file_exists ($out) && !is_writeable (dirname ($out)) || (file_exists($out) && !is_writable($out)) ))
        return
false;

   
$in_file = bzopen ($in, "rb");
   
$out_file = fopen ($out, "wb");

    while (
$buffer = bzread ($in_file, 4096)) {
       
fwrite ($out_file, $buffer, 4096);
    }
 
   
bzclose ($in_file);
   
fclose ($out_file);
   
    return
true;
}
?>

 
show source | credits | sitemap | contact | advertising | mirror sites