StreamReader
in package
A stream reader class
Table of Contents
Properties
- $buffer : string
- The buffer.
- $bufferLength : int
- The buffer length.
- $closeStream : bool
- Defines whether the stream should be closed when the stream reader instance is deconstructed or not.
- $offset : int
- The byte-offset position in the buffer.
- $position : int
- The byte-offset position in the stream.
- $stream : resource
- The stream resource.
- $totalLength : int
- The total length of the stream.
Methods
- __construct() : mixed
- StreamReader constructor.
- __destruct() : mixed
- The destructor.
- addOffset() : mixed
- Add an offset to the current offset.
- cleanUp() : mixed
- Closes the file handle.
- createByFile() : StreamReader
- Creates a stream reader instance by a filename.
- createByString() : StreamReader
- Creates a stream reader instance by a string value.
- ensure() : mixed
- Ensures bytes in the buffer with a specific length and location in the file.
- ensureContent() : bool
- Make sure that there is at least one character beyond the current offset in the buffer.
- getBuffer() : string
- Returns the current buffer.
- getBufferLength() : int
- Returns the byte length of the buffer.
- getByte() : string|bool
- Gets a byte at a specific position in the buffer.
- getOffset() : int
- Returns the current offset in the current buffer.
- getPosition() : int
- Get the current position in the stream.
- getStream() : resource
- Returns the stream.
- getTotalLength() : int
- Gets the total available length.
- increaseLength() : bool
- Forcefully read more data into the buffer.
- readByte() : string|bool
- Returns a byte at a specific position, and set the offset to the next byte position.
- readBytes() : string|false
- Read bytes from the current or a specific offset position and set the internal pointer to the next byte.
- readLine() : string|bool
- Read a line from the current position.
- reset() : mixed
- Resets the buffer to a position and re-read the buffer with the given length.
- setOffset() : mixed
- Set the offset position in the current buffer.
Properties
$buffer
The buffer.
protected
string
$buffer
$bufferLength
The buffer length.
protected
int
$bufferLength
$closeStream
Defines whether the stream should be closed when the stream reader instance is deconstructed or not.
protected
bool
$closeStream
$offset
The byte-offset position in the buffer.
protected
int
$offset
$position
The byte-offset position in the stream.
protected
int
$position
$stream
The stream resource.
protected
resource
$stream
$totalLength
The total length of the stream.
protected
int
$totalLength
Methods
__construct()
StreamReader constructor.
public
__construct(resource $stream[, bool $closeStream = false ]) : mixed
Parameters
- $stream : resource
- $closeStream : bool = false
-
Defines whether to close the stream resource if the instance is destructed or not.
__destruct()
The destructor.
public
__destruct() : mixed
addOffset()
Add an offset to the current offset.
public
addOffset(int $offset) : mixed
Parameters
- $offset : int
cleanUp()
Closes the file handle.
public
cleanUp() : mixed
createByFile()
Creates a stream reader instance by a filename.
public
static createByFile(string $filename) : StreamReader
Parameters
- $filename : string
Return values
StreamReadercreateByString()
Creates a stream reader instance by a string value.
public
static createByString(string $content[, int $maxMemory = 2097152 ]) : StreamReader
Parameters
- $content : string
- $maxMemory : int = 2097152
Return values
StreamReaderensure()
Ensures bytes in the buffer with a specific length and location in the file.
public
ensure(int $pos, int $length) : mixed
Parameters
- $pos : int
- $length : int
Tags
ensureContent()
Make sure that there is at least one character beyond the current offset in the buffer.
public
ensureContent() : bool
Return values
boolgetBuffer()
Returns the current buffer.
public
getBuffer([bool $atOffset = true ]) : string
Parameters
- $atOffset : bool = true
Return values
stringgetBufferLength()
Returns the byte length of the buffer.
public
getBufferLength([bool $atOffset = false ]) : int
Parameters
- $atOffset : bool = false
Return values
intgetByte()
Gets a byte at a specific position in the buffer.
public
getByte([int|null $position = null ]) : string|bool
If the position is invalid the method will return false.
If the $position parameter is set to null the value of $this->offset will be used.
Parameters
- $position : int|null = null
Return values
string|boolgetOffset()
Returns the current offset in the current buffer.
public
getOffset() : int
Return values
intgetPosition()
Get the current position in the stream.
public
getPosition() : int
Return values
intgetStream()
Returns the stream.
public
getStream() : resource
Return values
resourcegetTotalLength()
Gets the total available length.
public
getTotalLength() : int
Return values
intincreaseLength()
Forcefully read more data into the buffer.
public
increaseLength([int $minLength = 100 ]) : bool
Parameters
- $minLength : int = 100
Return values
bool —Returns false if the stream reaches the end
readByte()
Returns a byte at a specific position, and set the offset to the next byte position.
public
readByte([int|null $position = null ]) : string|bool
If the position is invalid the method will return false.
If the $position parameter is set to null the value of $this->offset will be used.
Parameters
- $position : int|null = null
Return values
string|boolreadBytes()
Read bytes from the current or a specific offset position and set the internal pointer to the next byte.
public
readBytes(int $length[, int|null $position = null ]) : string|false
If the position is invalid the method will return false.
If the $position parameter is set to null the value of $this->offset will be used.
Parameters
- $length : int
- $position : int|null = null
Return values
string|falsereadLine()
Read a line from the current position.
public
readLine([int $length = 1024 ]) : string|bool
Parameters
- $length : int = 1024
Return values
string|boolreset()
Resets the buffer to a position and re-read the buffer with the given length.
public
reset([int|null $pos = 0 ][, int $length = 200 ]) : mixed
If the $pos parameter is negative the start buffer position will be the $pos'th position from the end of the file.
If the $pos parameter is negative and the absolute value is bigger then the totalLength of the file $pos will set to zero.
Parameters
- $pos : int|null = 0
-
Start position of the new buffer
- $length : int = 200
-
Length of the new buffer. Mustn't be negative
setOffset()
Set the offset position in the current buffer.
public
setOffset(int $offset) : mixed
Parameters
- $offset : int