Stream

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();

withFile

Return an instance with file stream.

$stream = $stream->withFile($filename, $mode);

withPipe

Return an instance with pipe stream.

$stream = $stream->withPipe($command, $mode);

withTemp

Return an instance with temporary stream.

$stream = $stream->withTemp();

withMemory

Return an instance with memory stream.

$stream = $stream->withMemory();

getResource

Get resource of the stream.

$resource = $stream->getResource();

getUri

Get uri of the stream metadata.

$uri = $stream->getUri();

close

Closes the stream and any underlying resources.

$stream->close();

detach

Separates any underlying resources from the stream.

$stream = $stream->detach();

getSize

Get the size of the stream if known.

$size = $stream->getSize();

tell

Returns the current position of the file read/write pointer

$pointer = $stream->tell();

eof

Returns true if the stream is at the end of the stream.

$eof = $stream->eof();

isSeekable

Returns whether or not the stream is seekable.

$is_seekable = $stream->isSeekable();

seek

Seek to a position in the stream.

$stream->seek($offset, $whence = SEEK_SET);

rewind

Seek to the beginning of the stream.

$stream->rewind();

isWritable

Returns whether or not the stream is writable.

$is_writable = $stream->isWritable();

write

Write data to the stream.

$bytes_written = $stream->write($string);

isReadable

Returns whether or not the stream is readable.

$is_readable = $stream->isReadable();

read

Read data from the stream.

$read_string = $stream->read($length);

getContents

Returns the remaining contents in a string

$content = $stream->getContents();

getMetadata

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);