protected function _ensureWritable()
    {
        if (!$this->valid()) {
            throw new RuntimeException('Cannot write on a closed stream.');
        }
        if (!$this->isWritable()) {
            $mode = $this->meta('mode');
            throw new RuntimeException("Cannot write on a non-writable stream (mode is `'{$mode}'`).");
        }
    }