* Classes, which help reading streams of data from files.
* Based on the classes from Danilo Segan <danilo@kvota.net>
*
- * @version $Id: streams.php 293 2009-11-12 15:43:50Z nbachiyski $
+ * @version $Id: streams.php 406 2010-02-07 11:10:24Z nbachiyski $
* @package pomo
* @subpackage streams
*/
if ( !class_exists( 'POMO_Reader' ) ):
class POMO_Reader {
-
+
var $endian = 'little';
var $_post = '';
-
+
function POMO_Reader() {
$this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr');
$this->_pos = 0;
}
-
+
/**
* Sets the endianness of the file.
*
$endian_letter = ('big' == $this->endian)? 'N' : 'V';
return unpack($endian_letter.$count, $bytes);
}
-
-
+
+
function substr($string, $start, $length) {
if ($this->is_overloaded) {
return mb_substr($string, $start, $length, 'ascii');
return substr($string, $start, $length);
}
}
-
+
function strlen($string) {
if ($this->is_overloaded) {
return mb_strlen($string, 'ascii');
return strlen($string);
}
}
-
+
function str_split($string, $chunk_size) {
if (!function_exists('str_split')) {
$length = $this->strlen($string);
return str_split( $string, $chunk_size );
}
}
-
-
+
+
function pos() {
return $this->_pos;
}
function is_resource() {
return true;
}
-
+
function close() {
return true;
}
parent::POMO_Reader();
$this->_f = fopen($filename, 'r');
}
-
+
function read($bytes) {
return fread($this->_f, $bytes);
}
-
+
function seekto($pos) {
if ( -1 == fseek($this->_f, $pos, SEEK_SET)) {
return false;
$this->_pos = $pos;
return true;
}
-
+
function is_resource() {
return is_resource($this->_f);
}
-
+
function feof() {
return feof($this->_f);
}
-
+
function close() {
return fclose($this->_f);
}
-
+
function read_all() {
$all = '';
while ( !$this->feof() )
* of a physical file.
*/
class POMO_StringReader extends POMO_Reader {
-
+
var $_str = '';
-
+
function POMO_StringReader($str = '') {
parent::POMO_Reader();
$this->_str = $str;
function read_all() {
return $this->substr($this->_str, $this->_pos, $this->strlen($this->_str));
}
-
+
}
endif;