public function read($bytes=0)
    {
        // If the connection wrote into the resource the handle will be placed
        // at the end and nothing will be returned
        if ($this->didWrite) {
            $this->stream = null;
        }

        if (!$bytes) {
            return $this->stream()->toString();
        }

        $stream = $this->stream();
        $stream->setChunkSize($bytes);

        if (!$stream->isOpen()) {
            $stream->rewind();
        } else {
            $stream->next();
        }

        return $stream->current();
    }