private function drain($stream, $dest)
    {
        if (is_resource($stream)) {
            if (!is_resource($dest)) {
                $stream = Stream::factory($stream);
            } else {
                stream_copy_to_stream($stream, $dest);
                fclose($stream);
                rewind($dest);
                return $dest;
            }
        }

        // Stream the response into the destination stream
        $dest = is_string($dest)
            ? new Stream(Utils::open($dest, 'r+'))
            : Stream::factory($dest);

        Utils::copyToStream($stream, $dest);
        $dest->seek(0);
        $stream->close();

        return $dest;
    }
private function drain($stream, $dest)
    {
        if (is_resource($stream)) {
            if (!is_resource($dest)) {
                $stream = Stream::factory($stream);
            } else {
                stream_copy_to_stream($stream, $dest);
                fclose($stream);
                rewind($dest);
                return $dest;
            }
        }

        // Stream the response into the destination stream
        $dest = is_string($dest)
            ? new Stream(Utils::open($dest, 'r+'))
            : Stream::factory($dest);

        Utils::copyToStream($stream, $dest);
        $dest->seek(0);
        $stream->close();

        return $dest;
    }
private function drain ( $ stream , $ dest ) { if ( is_resource ( $ stream ) ) { if ( ! is_resource ( $ dest ) ) { $ stream = Stream :: factory ( $ stream ) ; } else { stream_copy_to_stream ( $ stream , $ dest ) ; fclose ( $ stream ) ; rewind ( $ dest ) ; return $ dest ; } } // Stream the response into the destination stream $ dest = is_string ( $ dest ) ? new Stream ( Utils :: open ( $ dest , 'r+' ) ) : Stream :: factory ( $ dest ) ; Utils :: copyToStream ( $ stream , $ dest ) ; $ dest -> seek ( 0 ) ; $ stream -> close ( ) ; return $ dest ; }
Drains the stream into the "save_to" client option.

@param resource                        $stream
@param string|resource|StreamInterface $dest

@return Stream
@throws \RuntimeException when the save_to option is invalid.
Drains the stream into the save_to client option .