BufferStream
in package
implements
StreamInterface
Provides a buffer stream that can be written to to fill a buffer, and read from to remove bytes from the buffer.
This stream returns a "hwm" metadata value that tells upstream consumers what the configured high water mark of the stream is, or the maximum preferred size of the buffer.
Tags
Interfaces, Classes and Traits
- StreamInterface
- Describes a data stream.
Table of Contents
- $buffer : mixed
- $hwm : mixed
- __construct() : mixed
- __toString() : string
- Reads all data from the stream into a string, from the beginning to end.
- close() : void
- Closes the stream and any underlying resources.
- detach() : resource|null
- Separates any underlying resources from the stream.
- eof() : bool
- Returns true if the stream is at the end of the stream.
- getContents() : string
- Returns the remaining contents in a string
- getMetadata() : array<string|int, mixed>|mixed|null
- Get stream metadata as an associative array or retrieve a specific key.
- getSize() : int|null
- Get the size of the stream if known.
- isReadable() : bool
- Returns whether or not the stream is readable.
- isSeekable() : bool
- Returns whether or not the stream is seekable.
- isWritable() : bool
- Returns whether or not the stream is writable.
- read() : string
- Reads data from the buffer.
- rewind() : mixed
- Seek to the beginning of the stream.
- seek() : mixed
- Seek to a position in the stream.
- tell() : int
- Returns the current position of the file read/write pointer
- write() : int
- Writes data to the buffer.
Properties
$buffer
private
mixed
$buffer
= ''
$hwm
private
mixed
$hwm
Methods
__construct()
public
__construct([int $hwm = 16384 ]) : mixed
Parameters
- $hwm : int = 16384
-
High water mark, representing the preferred maximum buffer size. If the size of the buffer exceeds the high water mark, then calls to write will continue to succeed but will return false to inform writers to slow down until the buffer has been drained by reading from it.
Return values
mixed —__toString()
Reads all data from the stream into a string, from the beginning to end.
public
__toString() : string
This method MUST attempt to seek to the beginning of the stream before reading data and read the stream until the end is reached.
Warning: This could attempt to load a large amount of data into memory.
This method MUST NOT raise an exception in order to conform with PHP's string casting operations.
Return values
string —close()
Closes the stream and any underlying resources.
public
close() : void
Return values
void —detach()
Separates any underlying resources from the stream.
public
detach() : resource|null
After the stream has been detached, the stream is in an unusable state.
Return values
resource|null —Underlying PHP stream, if any
eof()
Returns true if the stream is at the end of the stream.
public
eof() : bool
Return values
bool —getContents()
Returns the remaining contents in a string
public
getContents() : string
Return values
string —getMetadata()
Get stream metadata as an associative array or retrieve a specific key.
public
getMetadata([mixed $key = null ]) : array<string|int, mixed>|mixed|null
The keys returned are identical to the keys returned from PHP's stream_get_meta_data() function.
Parameters
- $key : mixed = null
-
Specific metadata to retrieve.
Return values
array<string|int, mixed>|mixed|null —Returns an associative array if no key is provided. Returns a specific key value if a key is provided and the value is found, or null if the key is not found.
getSize()
Get the size of the stream if known.
public
getSize() : int|null
Return values
int|null —Returns the size in bytes if known, or null if unknown.
isReadable()
Returns whether or not the stream is readable.
public
isReadable() : bool
Return values
bool —isSeekable()
Returns whether or not the stream is seekable.
public
isSeekable() : bool
Return values
bool —isWritable()
Returns whether or not the stream is writable.
public
isWritable() : bool
Return values
bool —read()
Reads data from the buffer.
public
read(mixed $length) : string
Parameters
- $length : mixed
-
Read up to $length bytes from the object and return them. Fewer than $length bytes may be returned if underlying stream call returns fewer bytes.
Return values
string —Returns the data read from the stream, or an empty string if no bytes are available.
rewind()
Seek to the beginning of the stream.
public
rewind() : mixed
If the stream is not seekable, this method will raise an exception; otherwise, it will perform a seek(0).
Return values
mixed —seek()
Seek to a position in the stream.
public
seek(mixed $offset[, mixed $whence = SEEK_SET ]) : mixed
Parameters
- $offset : mixed
-
Stream offset
- $whence : mixed = SEEK_SET
-
Specifies how the cursor position will be calculated based on the seek offset. Valid values are identical to the built-in PHP $whence values for
fseek()
. SEEK_SET: Set position equal to offset bytes SEEK_CUR: Set position to current location plus offset SEEK_END: Set position to end-of-stream plus offset.
Return values
mixed —tell()
Returns the current position of the file read/write pointer
public
tell() : int
Return values
int —Position of the file pointer
write()
Writes data to the buffer.
public
write(mixed $string) : int
Parameters
- $string : mixed
-
The string that is to be written.
Return values
int —Returns the number of bytes written to the stream.