56 return strlen($this->buffer);
79 public function seek($offset, $whence = SEEK_SET)
81 throw new \RuntimeException(
'Cannot seek a BufferStream');
86 return strlen($this->buffer) === 0;
91 throw new \RuntimeException(
'Cannot determine the position of a BufferStream');
97 public function read($length)
99 $currentLength = strlen($this->buffer);
101 if ($length >= $currentLength) {
107 $result = substr($this->buffer, 0, $length);
108 $this->buffer = substr($this->buffer, $length);
119 $this->buffer .= $string;
122 if (strlen($this->buffer) >= $this->hwm) {
126 return strlen($string);
135 return $key ? null : [];
An exception for terminatinating execution or to throw for unit testing.
Provides a buffer stream that can be written to to fill a buffer, and read from to remove bytes from ...
seek($offset, $whence=SEEK_SET)
Seek to a position in the stream.
isSeekable()
Returns whether or not the stream is seekable.
close()
Closes the stream and any underlying resources.
__toString()
Reads all data from the stream into a string, from the beginning to end.
write($string)
Writes data to the buffer.
eof()
Returns true if the stream is at the end of the stream.
isReadable()
Returns whether or not the stream is readable.
isWritable()
Returns whether or not the stream is writable.
read($length)
Reads data from the buffer.
rewind()
Seek to the beginning of the stream.
getMetadata($key=null)
Get stream metadata as an associative array or retrieve a specific key.
getContents()
Returns the remaining contents in a string.
tell()
Returns the current position of the file read/write pointer.
getSize()
Get the size of the stream if known.
detach()
Separates any underlying resources from the stream.