public function write($data)
    {
        if (!is_string($data)) {
            throw new \InvalidArgumentException("The data is not a string.");
        }

        $this->open();

        if (!ftruncate($this->handle, 0)) {
            $this->writeErrors = true;
            throw new \RuntimeException("Could not truncate file " . $this->filePath);
        }
        
        fseek($this->handle, 0);
        
        $res = fwrite($this->handle, $data);
        if (strlen($data) !== $res) {
            $this->writeErrors = true;
            throw new \RuntimeException("Could not write to file " . $this->filePath);
        }
    }