protected function assertAttached(): void
    {
        if (!isset($this->stream)) {
            throw new \BadMethodCallException("Stream is not attached");
        }

        if (!is_resource($this->stream)) {
            throw new \RuntimeException("Stream has closed unexpectedly");
        }
    }