protected function readBytes($bytes)
    {
        $data = '';
        $chunk = null;
        while ($bytes > 0 && false !== ($chunk = \fread($this->stream, $bytes))) {
            $bytes -= \strlen($chunk);
            $data .= $chunk;
        }

        if (false === $chunk) {
            throw new RuntimeException('Could not read from stream');
        }
        return $data;
    }