Describes a data stream.
Typically, an instance will wrap a PHP stream; this interface provides a wrapper around the most common operations, including serialization of the entire stream to a string.
Simple Stream Implementation.
$stream = new \Samy\Psr7\Stream();
Describes Stream interface.
Closes the stream and any underlying resources.
Separates any underlying resources from the stream. After the stream has been detached, the stream is in an unusable state.
$stream = $stream->detach();
Get the size of the stream if known.
$size = $stream->getSize();
Returns the current position of the file read/write pointer.
$pointer = $stream->tell();
Returns true if the stream is at the end of the stream.
$eof = $stream->eof();
Returns whether or not the stream is seekable.
$is_seekable = $stream->isSeekable();
Seek to a position in the stream.
$stream->seek($offset, $whence = SEEK_SET);
Seek to the beginning of the stream. If the stream is not seekable, this method will raise an exception; otherwise, it will perform a seek(0).
Returns whether or not the stream is writable.
$is_writable = $stream->isWritable();
Write data to the stream.
$bytes_written = $stream->write($string);
Returns whether or not the stream is readable.
$is_readable = $stream->isReadable();
Read data from the stream.
$read_string = $stream->read($length);
Returns the remaining contents in a string.
$content = $stream->getContents();
Get stream metadata as an associative array or retrieve a specific key. The keys returned are identical to the keys returned from PHP's stream_get_meta_data() function.
$content = $stream->getMetadata($key = null);
Return an instance with pipe stream.
$stream = $stream->withPipe($command, $mode);
Return an instance with file stream.
$stream = $stream->withFile($filename, $mode);
Return an instance with temporary stream.
$stream = $stream->withTemp($mode);
Return an instance with memory stream.
$stream = $stream->withMemory($mode);
Retrieve resource of the stream.
$resource = $stream->getResource();
Retrieve uri of the stream metadata.
$uri = $stream->getUri();