<?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;
}
?>
VIII. Bzip2 压缩函数
简介
Bzip2 函数用来透明的读写 bzip2(.bz2)压缩文件。
安装
PHP 的 bzip2 支持默认未打开。编译 PHP 时需要 --with-bz2[=DIR] 配置选项来激活 bzip2 支持。
运行时配置
本扩展模块在 php.ini 中未定义任何配置选项。
资源类型
本扩展定义了一种资源类型:一个文件指针,指向正在被操作的 bz2 文件。
预定义常量
本扩展模块未定义任何常量。
范例
该例子打开一临时文件,并写入一测试字符串,然后打印文件内容。
- 目录
- bzclose -- Close a bzip2 file
- bzcompress -- Compress a string into bzip2 encoded data
- bzdecompress -- Decompresses bzip2 encoded data
- bzerrno -- Returns a bzip2 error number
- bzerror -- Returns the bzip2 error number and error string in an array
- bzerrstr -- Returns a bzip2 error string
- bzflush -- Force a write of all buffered data
- bzopen -- Opens a bzip2 compressed file
- bzread -- Binary safe bzip2 file read
- bzwrite -- Binary safe bzip2 file write
Bzip2 压缩函数
ec10 at gmx dot net
20-May-2004 11:34
20-May-2004 11:34
