6 V4.01 23 Oct 2003 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
7 Contributed by Ross Smith (adodb@netebb.com).
8 Released under both BSD license and Lesser GPL library license.
9 Whenever there is any discrepancy between the two licenses,
10 the BSD license will take precedence.
11 Set tabs to 4 for best viewing.
15 if (!function_exists('bzcompress')) {
16 trigger_error('bzip2 functions are not available', E_USER_ERROR
);
22 class ADODB_Compress_Bzip2
{
25 var $_block_size = null;
29 var $_work_level = null;
37 function getBlockSize() {
38 return $this->_block_size
;
43 function setBlockSize($block_size) {
44 assert('$block_size >= 1');
45 assert('$block_size <= 9');
46 $this->_block_size
= (int) $block_size;
51 function getWorkLevel() {
52 return $this->_work_level
;
57 function setWorkLevel($work_level) {
58 assert('$work_level >= 0');
59 assert('$work_level <= 250');
60 $this->_work_level
= (int) $work_level;
65 function getMinLength() {
66 return $this->_min_length
;
71 function setMinLength($min_length) {
72 assert('$min_length >= 0');
73 $this->_min_length
= (int) $min_length;
78 function ADODB_Compress_Bzip2($block_size = null, $work_level = null, $min_length = null) {
79 if (!is_null($block_size)) {
80 $this->setBlockSize($block_size);
83 if (!is_null($work_level)) {
84 $this->setWorkLevel($work_level);
87 if (!is_null($min_length)) {
88 $this->setMinLength($min_length);
94 function write($data, $key) {
95 if (strlen($data) < $this->_min_length
) {
99 if (!is_null($this->_block_size
)) {
100 if (!is_null($this->_work_level
)) {
101 return bzcompress($data, $this->_block_size
, $this->_work_level
);
103 return bzcompress($data, $this->_block_size
);
107 return bzcompress($data);
112 function read($data, $key) {
113 return $data ?
bzdecompress($data) : $data;