38 $bytes = $this->read(4); |
38 $bytes = $this->read(4); |
39 if (4 != $this->strlen($bytes)) |
39 if (4 != $this->strlen($bytes)) |
40 return false; |
40 return false; |
41 $endian_letter = ('big' == $this->endian)? 'N' : 'V'; |
41 $endian_letter = ('big' == $this->endian)? 'N' : 'V'; |
42 $int = unpack($endian_letter, $bytes); |
42 $int = unpack($endian_letter, $bytes); |
43 return array_shift($int); |
43 return reset( $int ); |
44 } |
44 } |
45 |
45 |
46 /** |
46 /** |
47 * Reads an array of 32-bit Integers from the Stream |
47 * Reads an array of 32-bit Integers from the Stream |
48 * |
48 * |
56 return false; |
56 return false; |
57 $endian_letter = ('big' == $this->endian)? 'N' : 'V'; |
57 $endian_letter = ('big' == $this->endian)? 'N' : 'V'; |
58 return unpack($endian_letter.$count, $bytes); |
58 return unpack($endian_letter.$count, $bytes); |
59 } |
59 } |
60 |
60 |
61 |
61 /** |
|
62 * @param string $string |
|
63 * @param int $start |
|
64 * @param int $length |
|
65 * @return string |
|
66 */ |
62 function substr($string, $start, $length) { |
67 function substr($string, $start, $length) { |
63 if ($this->is_overloaded) { |
68 if ($this->is_overloaded) { |
64 return mb_substr($string, $start, $length, 'ascii'); |
69 return mb_substr($string, $start, $length, 'ascii'); |
65 } else { |
70 } else { |
66 return substr($string, $start, $length); |
71 return substr($string, $start, $length); |
67 } |
72 } |
68 } |
73 } |
69 |
74 |
|
75 /** |
|
76 * @param string $string |
|
77 * @return int |
|
78 */ |
70 function strlen($string) { |
79 function strlen($string) { |
71 if ($this->is_overloaded) { |
80 if ($this->is_overloaded) { |
72 return mb_strlen($string, 'ascii'); |
81 return mb_strlen($string, 'ascii'); |
73 } else { |
82 } else { |
74 return strlen($string); |
83 return strlen($string); |
75 } |
84 } |
76 } |
85 } |
77 |
86 |
|
87 /** |
|
88 * @param string $string |
|
89 * @param int $chunk_size |
|
90 * @return array |
|
91 */ |
78 function str_split($string, $chunk_size) { |
92 function str_split($string, $chunk_size) { |
79 if (!function_exists('str_split')) { |
93 if (!function_exists('str_split')) { |
80 $length = $this->strlen($string); |
94 $length = $this->strlen($string); |
81 $out = array(); |
95 $out = array(); |
82 for ($i = 0; $i < $length; $i += $chunk_size) |
96 for ($i = 0; $i < $length; $i += $chunk_size) |
102 } |
116 } |
103 endif; |
117 endif; |
104 |
118 |
105 if ( !class_exists( 'POMO_FileReader' ) ): |
119 if ( !class_exists( 'POMO_FileReader' ) ): |
106 class POMO_FileReader extends POMO_Reader { |
120 class POMO_FileReader extends POMO_Reader { |
|
121 |
|
122 /** |
|
123 * @param string $filename |
|
124 */ |
107 function POMO_FileReader($filename) { |
125 function POMO_FileReader($filename) { |
108 parent::POMO_Reader(); |
126 parent::POMO_Reader(); |
109 $this->_f = fopen($filename, 'rb'); |
127 $this->_f = fopen($filename, 'rb'); |
110 } |
128 } |
111 |
129 |
|
130 /** |
|
131 * @param int $bytes |
|
132 */ |
112 function read($bytes) { |
133 function read($bytes) { |
113 return fread($this->_f, $bytes); |
134 return fread($this->_f, $bytes); |
114 } |
135 } |
115 |
136 |
|
137 /** |
|
138 * @param int $pos |
|
139 * @return boolean |
|
140 */ |
116 function seekto($pos) { |
141 function seekto($pos) { |
117 if ( -1 == fseek($this->_f, $pos, SEEK_SET)) { |
142 if ( -1 == fseek($this->_f, $pos, SEEK_SET)) { |
118 return false; |
143 return false; |
119 } |
144 } |
120 $this->_pos = $pos; |
145 $this->_pos = $pos; |
155 parent::POMO_Reader(); |
180 parent::POMO_Reader(); |
156 $this->_str = $str; |
181 $this->_str = $str; |
157 $this->_pos = 0; |
182 $this->_pos = 0; |
158 } |
183 } |
159 |
184 |
160 |
185 /** |
|
186 * @param string $bytes |
|
187 * @return string |
|
188 */ |
161 function read($bytes) { |
189 function read($bytes) { |
162 $data = $this->substr($this->_str, $this->_pos, $bytes); |
190 $data = $this->substr($this->_str, $this->_pos, $bytes); |
163 $this->_pos += $bytes; |
191 $this->_pos += $bytes; |
164 if ($this->strlen($this->_str) < $this->_pos) $this->_pos = $this->strlen($this->_str); |
192 if ($this->strlen($this->_str) < $this->_pos) $this->_pos = $this->strlen($this->_str); |
165 return $data; |
193 return $data; |
166 } |
194 } |
167 |
195 |
|
196 /** |
|
197 * @param int $pos |
|
198 * @return int |
|
199 */ |
168 function seekto($pos) { |
200 function seekto($pos) { |
169 $this->_pos = $pos; |
201 $this->_pos = $pos; |
170 if ($this->strlen($this->_str) < $this->_pos) $this->_pos = $this->strlen($this->_str); |
202 if ($this->strlen($this->_str) < $this->_pos) $this->_pos = $this->strlen($this->_str); |
171 return $this->_pos; |
203 return $this->_pos; |
172 } |
204 } |