Stream Readers

Classes for reading streams of data, used by the MO file parser. Handles byte-level I/O with endian-aware integer reading and mbstring overload safety.

Source: wp-includes/pomo/streams.php

Class Hierarchy

POMO_Reader
    ├── POMO_FileReader          (reads from file handle)
    └── POMO_StringReader        (reads from in-memory string)
            └── POMO_CachedFileReader    (reads file into memory, then string-based)
                    └── POMO_CachedIntFileReader  (same as parent)

POMO_Reader

Base class providing endian-aware integer reading and mbstring-safe string operations.

Properties

PropertyTypeDefaultDescription
$endianstring'little'Byte order: 'little' or 'big'
$_posint0Current read position
$is_overloadedboolWhether mbstring.func_overload is active for string functions

Methods

MethodReturnsDescription
__construct()Detects mbstring overloading, initializes position to 0
POMO_Reader()Deprecated 5.4.0. PHP4 constructor
setEndian( $endian )voidSets byte order ('big' or 'little')
readint32()int|falseReads a 32-bit integer using current endianness. Returns false if fewer than 4 bytes available
readint32array( $count )array|falseReads $count 32-bit integers. Returns false if not enough data
substr( $input_string, $start, $length )stringmbstring-safe substr (uses 'ascii' encoding if overloaded)
strlen( $input_string )intmbstring-safe strlen
str_split( $input_string, $chunk_size )arraySplits string into chunks (manual implementation if str_split() unavailable)
pos()intReturns current position
is_resource()trueAlways returns true
close()trueAlways returns true

POMO_FileReader

Extends: POMO_Reader

Reads from an actual file via fopen()/fread().

Properties

PropertyTypeDescription
$_fresource|falseFile pointer opened in 'rb' mode

Methods

MethodReturnsDescription
__construct( $filename )Opens file in binary read mode
POMO_FileReader( $filename )Deprecated 5.4.0. PHP4 constructor
read( $bytes )string|falseReads $bytes bytes via fread()
seekto( $pos )boolSeeks to absolute position. Returns false on failure
is_resource()boolReturns is_resource( $this->_f )
feof()boolReturns feof( $this->_f )
close()boolCloses the file handle
read_all()stringReturns remaining contents via stream_get_contents()

POMO_StringReader

Extends: POMO_Reader

Reads from an in-memory string, providing file-like seek/read operations.

Properties

PropertyTypeDefaultDescription
$_strstring''The string data

Methods

MethodReturnsDescription
__construct( $str = '' )Stores the string, resets position to 0
POMO_StringReader( $str = '' )Deprecated 5.4.0. PHP4 constructor
read( $bytes )stringReads $bytes bytes from current position, advances position (clamped to string length)
seekto( $pos )intSeeks to position (clamped to string length), returns new position
length()intReturns total string length
read_all()stringReturns remaining data from current position

POMO_CachedFileReader

Extends: POMO_StringReader

Reads an entire file into memory at construction time, then operates as a string reader.

Methods

MethodReturnsDescription
__construct( $filename )Reads file via file_get_contents(). Sets $_str to false on failure
POMO_CachedFileReader( $filename )Deprecated 5.4.0. PHP4 constructor

POMO_CachedIntFileReader

Extends: POMO_CachedFileReader

Identical to POMO_CachedFileReader. Exists as a separate class for historical/type-distinction reasons. No additional functionality.

Methods

MethodReturnsDescription
__construct( $filename )Delegates to parent
POMO_CachedIntFileReader( $filename )Deprecated 5.4.0. PHP4 constructor