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.
$stream = new Stream();
Return an instance with file stream.
$stream = $stream->withFile($filename, $mode);
Return an instance with pipe stream.
$stream = $stream->withPipe($command, $mode);
Return an instance with temporary stream.
$stream = $stream->withTemp();
Return an instance with memory stream.
$stream = $stream->withMemory();
Get resource of the stream.
$resource = $stream->getResource();
Get uri of the stream metadata.
$uri = $stream->getUri();
Closes the stream and any underlying resources.
Separates any underlying resources from the stream.
$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.
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);