~ubuntu-branches/ubuntu/edgy/torrentflux/edgy-security

« back to all changes in this revision

Viewing changes to html/adodb/session/adodb-compress-bzip2.php

  • Committer: Bazaar Package Importer
  • Author(s): Cameron Dale
  • Date: 2006-04-14 15:13:06 UTC
  • Revision ID: james.westby@ubuntu.com-20060414151306-dwc5yc3hof3l2kmf
Tags: upstream-2.1
ImportĀ upstreamĀ versionĀ 2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/*
 
4
V4.80 8 Mar 2006  (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
 
5
         Contributed by Ross Smith (adodb@netebb.com). 
 
6
  Released under both BSD license and Lesser GPL library license.
 
7
  Whenever there is any discrepancy between the two licenses,
 
8
  the BSD license will take precedence.
 
9
          Set tabs to 4 for best viewing.
 
10
 
 
11
*/
 
12
 
 
13
if (!function_exists('bzcompress')) {
 
14
        trigger_error('bzip2 functions are not available', E_USER_ERROR);
 
15
        return 0;
 
16
}
 
17
 
 
18
/*
 
19
*/
 
20
class ADODB_Compress_Bzip2 {
 
21
        /**
 
22
         */
 
23
        var $_block_size = null;
 
24
 
 
25
        /**
 
26
         */
 
27
        var $_work_level = null;
 
28
 
 
29
        /**
 
30
         */
 
31
        var $_min_length = 1;
 
32
 
 
33
        /**
 
34
         */
 
35
        function getBlockSize() {
 
36
                return $this->_block_size;
 
37
        }
 
38
 
 
39
        /**
 
40
         */
 
41
        function setBlockSize($block_size) {
 
42
                assert('$block_size >= 1');
 
43
                assert('$block_size <= 9');
 
44
                $this->_block_size = (int) $block_size;
 
45
        }
 
46
 
 
47
        /**
 
48
         */
 
49
        function getWorkLevel() {
 
50
                return $this->_work_level;
 
51
        }
 
52
 
 
53
        /**
 
54
         */
 
55
        function setWorkLevel($work_level) {
 
56
                assert('$work_level >= 0');
 
57
                assert('$work_level <= 250');
 
58
                $this->_work_level = (int) $work_level;
 
59
        }
 
60
 
 
61
        /**
 
62
         */
 
63
        function getMinLength() {
 
64
                return $this->_min_length;
 
65
        }
 
66
 
 
67
        /**
 
68
         */
 
69
        function setMinLength($min_length) {
 
70
                assert('$min_length >= 0');
 
71
                $this->_min_length = (int) $min_length;
 
72
        }
 
73
 
 
74
        /**
 
75
         */
 
76
        function ADODB_Compress_Bzip2($block_size = null, $work_level = null, $min_length = null) {
 
77
                if (!is_null($block_size)) {
 
78
                        $this->setBlockSize($block_size);
 
79
                }
 
80
 
 
81
                if (!is_null($work_level)) {
 
82
                        $this->setWorkLevel($work_level);
 
83
                }
 
84
 
 
85
                if (!is_null($min_length)) {
 
86
                        $this->setMinLength($min_length);
 
87
                }
 
88
        }
 
89
 
 
90
        /**
 
91
         */
 
92
        function write($data, $key) {
 
93
                if (strlen($data) < $this->_min_length) {
 
94
                        return $data;
 
95
                }
 
96
 
 
97
                if (!is_null($this->_block_size)) {
 
98
                        if (!is_null($this->_work_level)) {
 
99
                                return bzcompress($data, $this->_block_size, $this->_work_level);
 
100
                        } else {
 
101
                                return bzcompress($data, $this->_block_size);
 
102
                        }
 
103
                }
 
104
 
 
105
                return bzcompress($data);
 
106
        }
 
107
 
 
108
        /**
 
109
         */
 
110
        function read($data, $key) {
 
111
                return $data ? bzdecompress($data) : $data;
 
112
        }
 
113
 
 
114
}
 
115
 
 
116
return 1;
 
117
 
 
118
?>