/
PHP的Bzip2压缩扩展工具.php
65 lines (45 loc) · 1.09 KB
/
PHP的Bzip2压缩扩展工具.php
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
// yum install bzip2-devel
// ./configure xxxx --with-bz2
$bz = bzopen('/tmp/test.bz', 'w');
// -rw-r--r-- 1 root root 14 Jun 28 09:51 test.bz
$text = "This is Bz Compress";
bzwrite($bz, $text);
// -rw-r--r-- 1 root root 59 Jun 28 09:53 test.bz
bzclose($bz);
$bz = bzopen('/tmp/test.bz', 'r');
$v = bzread($bz);
echo $v, PHP_EOL;
// This is Bz Compress
bzclose($bz);
$bz = bzopen('/tmp/test.bz', 'r');
$v = bzread($bz, 10);
echo $v, PHP_EOL;
// This is Bz
$v = bzread($bz);
echo $v, PHP_EOL;
// Compress
bzclose($bz);
$str = "Test compress String";
$bzstr = bzcompress($str, 9);
echo $bzstr, PHP_EOL;
// BZh91AY&SY��J���@
//
// �� 1
// df����2�h>.�p�!��//
$newStr = bzdecompress($bzstr);
echo $newStr, PHP_EOL;
$chineseStr = "测试";
$bzstr = bzcompress($chineseStr, 9);
echo bzdecompress($bzstr), PHP_EOL;
$bz = bzopen('/tmp/test.bz', 'r');
bzwrite($bz, 'aaa');
print_r(bzerror($bz));
// Array
// (
// [errno] => -1
// [errstr] => SEQUENCE_ERROR
// )
echo bzerrno($bz), PHP_EOL; // -1
echo bzerrstr($bz), PHP_EOL; // SEQUENCE_ERROR
bzclose($bz);