# Class HttpSoft\Message\Stream

Class, that implements Psr\Http\Message\StreamInterface.

Source code on GitHub.

use HttpSoft\Message\Stream;

// Create instance from temporary resource.

$stream = new Stream('php://temp', 'wb+');

$stream->getMetadata('uri'); // 'php://temp'
$stream->getMetadata('mode'); // 'w+b'
$stream->getContents(); // ''
$stream->getSize(); // null

$stream->isReadable(); // true
$stream->isSeekable(); // true
$stream->isWritable(); // true

$stream->write('content');
$stream->__toString(); // 'content'
// equivalently to:
(string) $stream; // echo $stream;

$stream->close();
$stream->isReadable(); // false
$stream->isSeekable(); // false
$stream->isWritable(); // false

// Create instance from existing file.

$stream = new Stream('path/to/file', 'r');

$stream->getMetadata('uri'); // 'path/to/file'
$stream->getMetadata('mode'); // 'r'
$stream->getContents(); // 'File content'
$stream->getSize(); // 12

// Create instance from existing resource.

$resource = fopen('path/to/file', 'r');
$stream = new Stream($resource);

$stream->getMetadata('uri'); // 'path/to/file'
$stream->getMetadata('mode'); // 'r'
$stream->getContents(); // 'File content'
$stream->getSize(); // 12

# Public methods

See the original detailed description of the methods in the Psr\Http\Message\StreamInterface.

/**
 * @param string|resource $stream
 * @param string $mode
 */
public function __construct($stream = 'php://temp', string $mode = 'wb+');

All other methods with descriptions are in the used trait (HttpSoft\Message\StreamTrait).