public function write(string $string): StreamInterface
    {
        if ( ! is_resource($this->stream) ) {
            throw new StreamException('Stream is not longer available');
        }

        if ( ! $this->writable ) {
            throw new StreamException('Stream is not writable');
        }

        $this->size = null;
        $result = fwrite($this->stream, $string);

        if ( $result === false ) {
            throw new StreamException('Unable to write to stream');
        }

        return $this;
    }