ArrayByteStream
in package
implements
InputInterface, OutputInterface
Array byte stream class
Tags
Table of Contents
Interfaces
- InputInterface
- Input byte stream interface
- OutputInterface
- Output byte stream interface
Properties
- $array : array<string|int, mixed>
- The internal stack of bytes
- $arraySize : int
- The size of the stack
- $mirrors : array<string|int, mixed>
- Bound streams
- $offset : int
- The internal pointer offset
Methods
- __construct() : mixed
- Create a new ArrayByteStream.
- bind() : void
- Attach $is to this stream.
- commit() : void
- Not used
- flushBuffers() : void
- Flush the contents of the stream (empty it) and set the internal pointer to the beginning.
- read() : string|bool
- Reads $length bytes from the stream into a string and moves the pointer through the stream by $length.
- setReadPointer() : void
- Move the internal read pointer to $byteOffset in the stream.
- unbind() : void
- Remove an already bound stream.
- write() : mixed
- Writes $bytes to the end of the stream
Properties
$array
The internal stack of bytes
private
array<string|int, mixed>
$array
= []
$arraySize
The size of the stack
private
int
$arraySize
= 0
$mirrors
Bound streams
private
array<string|int, mixed>
$mirrors
= []
$offset
The internal pointer offset
private
int
$offset
= 0
Methods
__construct()
Create a new ArrayByteStream.
public
__construct([mixed $stack = null ]) : mixed
If $stack is given the stream will be populated with the bytes it contains.
Parameters
- $stack : mixed = null
-
of bytes in string or array form, optional
bind()
Attach $is to this stream.
public
bind(InputInterface $is) : void
The stream acts as an observer, receiving all data that is written. All and operations will be mirrored.
Parameters
- $is : InputInterface
commit()
Not used
public
commit() : void
flushBuffers()
Flush the contents of the stream (empty it) and set the internal pointer to the beginning.
public
flushBuffers() : void
read()
Reads $length bytes from the stream into a string and moves the pointer through the stream by $length.
public
read(int|string $length) : string|bool
If less bytes exist than are requested the remaining bytes are given instead. If no bytes are remaining at all, bool false is returned.
Parameters
- $length : int|string
Return values
string|boolsetReadPointer()
Move the internal read pointer to $byteOffset in the stream.
public
setReadPointer(int|string $byteOffset) : void
Parameters
- $byteOffset : int|string
unbind()
Remove an already bound stream.
public
unbind(InputInterface $is) : void
If $is is not bound, no errors will be raised. If the stream currently has any buffered data it will be written to $is before unbinding occurs.
Parameters
- $is : InputInterface
write()
Writes $bytes to the end of the stream
public
write(string $bytes) : mixed
Parameters
- $bytes : string