代码
/*将字符串添加至GZ文件*/
function gz_str($str,$gz_name){
$fp = gzopen ($gz_name, 'w9');
gzwrite ($fp, $str);
gzclose($fp);
}
/*将文件添加至GZ文件*/
function gz_file($file,$gz_name){
$fp = gzopen ($gz_name, 'w9');
gzwrite ($fp, file_get_contents($file));
gzclose($fp);
}
/*读取GZ文件*/
function read_gz($gz_file){
$buffer_size = 4096; // read 4kb at a time
$file = gzopen($gz_file, 'rb');
$str='';
while(!gzeof($file)) {
$str.=gzread($file, $buffer_size);
}
gzclose($file);
return $str;
}
/*解压GZ文件*/
function unzip_gz($gz_file){
$buffer_size = 4096; // read 4kb at a time
$out_file_name = str_replace('.gz', '', $gz_file);
$file = gzopen($gz_file, 'rb');
$out_file = fopen($out_file_name, 'wb');
$str='';
while(!gzeof($file)) {
fwrite($out_file, gzread($file, $buffer_size));
}
fclose($out_file);
gzclose($file);
}