public static function toString(StreamInterface $stream)
    {
        if (!$stream->isReadable()) {
            return '';
        }

        if ($stream->isSeekable()) {
            $pos     = $stream->tell();
            $content = $stream->__toString();

            $stream->seek($pos);
        } else {
            $content = $stream->__toString();
        }

        return $content;
    }