Set the stream to write to
@param mixed $stream Stream to write to
503142
public function setStream($stream = null)
    {
        // String passed in? Try converting it to a stream
        if (is_string($stream)) {
            $stream = @fopen($stream, 'a');
        }

        // Make sure the stream is a resource
        if (!is_resource($stream)) {
            throw new \InvalidArgumentException('Invalid Stream');
        }

        // Store it
        $this->stream = $stream;

        // Afford chaining
        return $this;
    }
478401
public function writeVarint(Stream $stream, $value)
    {
        // Small values do not need to be encoded
        if ($value >= 0 && $value < 0x80) {
            $this->writeByte($stream, $value);

            return;
        }

        $values = null;

        // Build an array of bytes with the encoded values
        if ($value > 0) {
            $values = [];

            while ($value > 0) {
                $values[] = 0x80 | ($value & 0x7f);
                $value    = $value >> 7;
            }
        }

        if ($values === null) {
            $values = $this->negativeEncoder->encodeVarint($value);
        }

        // Remove the MSB flag from the last byte
        $values[count($values) - 1] &= 0x7f;

        // Convert the byte sized ints to actual bytes in a string
        $values = array_merge(['C*'], $values);
        $bytes  = call_user_func_array('pack', $values);

        $this->writeBytes($stream, $bytes);
    }
1093660
public function write($string)
    {
        if (!$this->isWritable()) {
            throw new \RuntimeException("Stream isn't writable");
        }
        
        $ret = fwrite($this->handle, $string);
        
        if ($ret === false) {
            throw new \RuntimeException("Failed to write to stream");
        }
        
        return $ret;
    }
1131909
public function pipe($stream)
    {
        $offset = $stream->tell();
        $result = stream_copy_to_stream($this->resource(), $stream->resource());
        if ($stream->isSeekable()) {
            $stream->seek($offset);
        }
        return $result;
    }
1006274
public function loadBinaryStream($stream)
    {
        if (($contents = stream_get_contents($stream)) === false) {
            throw IOException::notReadable('<stream>');
        }
        $this->parse($contents, CFPropertyList::FORMAT_BINARY);
    }
692012
public function writeString(Stream $stream, $value)
    {
        $this->writeVarint($stream, mb_strlen($value, '8bit'));
        $this->writeBytes($stream, $value);
    }
20637
public void write(PrintStream stream) {
        this.output = stream;
        dispatch(base, false);
        stream.flush();
    }
509153
public function setBody($body)
    {
        $this->body = empty($body) ?
            null :
            Stream::factory($body);
    }
204090
public function writeFixed64(Stream $stream, $value)
    {
        $bytes = pack('V*', $value & 0xffffffff, $value / (0xffffffff + 1));

        $this->writeBytes($stream, $bytes, 8);
    }
1344057
public function addReadStream($stream, callable $listener)
    {
        $this->emit('addReadStream', [$stream, $listener]);
        $this->loop->addReadStream($stream, function ($stream) use ($listener) {
            $this->emit('readStreamTick', [$stream, $listener]);
            $listener($stream, $this);
        });
    }
547187
public function writeUTF($stream)
    {
        $this->writeInt($this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream));
        $this->_stream.= $stream;
        return $this;
    }
59198
public void writeToStream(OutputStream stream, Object object) throws SerializationException {
        try {
            mapper.writeValue(stream, object);
        } catch (IOException ex) {
            throw new SerializationException("Exception during serialization", ex);
        }
    }
440738
private static function writeStream(StreamInterface $stream, $path)
    {
        $dir = dirname($path);

        if (!is_dir($dir)) {
            mkdir($dir, 0777, true);
        }

        $handle = fopen($path, 'wb+');

        if (false === $handle) {
            throw new RuntimeException('Unable to write to designated path');
        }

        $stream->rewind();

        while (!$stream->eof()) {
            fwrite($handle, $stream->read(4096));
        }

        fclose($handle);
    }
958394
private function writePartContentTo(StreamInterface $stream)
    {
        $contentStream = $this->part->getContentStream();
        if ($contentStream !== null) {
            $copyStream = $this->streamFactory->newNonClosingStream($stream);
            $es = $this->getTransferEncodingDecoratorForStream($copyStream);
            $cs = $this->getCharsetDecoratorForStream($es);
            Psr7\copy_to_stream($contentStream, $cs);
            $cs->close();
        }
    }
207716
public function putContent($content)
    {
        // write to io stream
        $this->size = fwrite($this->inputStream, $content);
        // rewind file pointer
        rewind($this->inputStream);
    }
1233151
public function removeReadStream($stream)
    {
        $key = (int) $stream;

        if (isset($this->streamsRead[$key])) {
            unset($this->streamsRead[$key]);
        }
        if (isset($this->streamsDuplex[$key]) && !isset($this->streamsWrite[$key])) {
            unset($this->streamsDuplex[$key]);
        }

        GlobalState::set('eventloop.streams.read.current', count($this->streamsRead));
        GlobalState::set('eventloop.streams.total.current', count($this->streamsDuplex));

        $this->loop->removeReadStream($stream);
    }
771
public function writePartHeadersTo(StreamInterface $stream)
    {
        foreach ($this->getPartHeadersIterator() as $header) {
            $stream->write("${header[0]}: ${header[1]}\r\n");
        }
        $stream->write("\r\n");
    }