Class
StringStream
A readable, seekable PSR-7 stream over a string that is known in full.
Introduction#
Never blocks.
Class synopsis#
class StringStream implements StreamInterface, \Stringable {
/* Methods */
public StringStream::__construct(string $contents)
public StringStream::__toString(): string
public StringStream::close(): void
public StringStream::detach()
public StringStream::getSize(): ?int
public StringStream::tell(): int
public StringStream::eof(): bool
public StringStream::isSeekable(): bool
public StringStream::seek($offset, $whence = SEEK_SET): void
public StringStream::rewind(): void
public StringStream::isWritable(): bool
public StringStream::write($string): int
public StringStream::isReadable(): bool
public StringStream::read($length): string
public StringStream::getContents(): string
public StringStream::getMetadata($key = null)
}Methods#
| Method | Description |
|---|---|
__construct | Creates a stream with $contents. |
__toString | Returns the whole content, and moves the read position to its end. |
close | Closes the stream and any underlying resources. |
detach | Separates any underlying resources from the stream. |
getSize | Get the size of the stream if known. |
tell | Returns the current position of the file read/write pointer |
eof | Returns true if the stream is at the end of the stream. |
isSeekable | Returns whether or not the stream is seekable. |
seek | Seek to a position in the stream. |
rewind | Seek to the beginning of the stream. |
isWritable | Returns whether or not the stream is writable. |
write | Write data to the stream. |
isReadable | Returns whether or not the stream is readable. |
read | Read data from the stream. |
getContents | Returns the remaining contents in a string |
getMetadata | Get stream metadata as an associative array or retrieve a specific key. |
Examples#
$stream = new StringStream('Hello');
$stream->read(2); // "He"
$stream->getSize(); // 5See also#
UnbufferedStreamA PSR-7 stream for a body that is still being produced, read once and in order.BufferedStreamA seekable PSR-7 stream for a body that is still being produced, kept in memory and then in a temporary file.