1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| /*将字符串添加至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);
}
|