public function read($length)
{
if (!$this->resource) {
throw new RuntimeException('No resource available; cannot read');
}
if (!$this->isReadable()) {
throw new RuntimeException('Stream is not readable');
}
$result = fread($this->resource, $length);
if (false === $result) {
throw new RuntimeException('Error reading stream');
}
return $result;
}