func (lines *Buffer) WriteFile(filepath string) error {
	// # TODO: add a twin method that uses fs.FS
	f, err := os.OpenFile(filepath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, fs.FileMode(0644))
	if err != nil {
		return err
	}
	defer f.Close()

	_, err = f.Write(lines.buf.Bytes())
	if err != nil {
		return err
	}

	lines.buf.Truncate(0)

	return err
}
// WriteFile writes all lines written to
// the buffer so far to a file with given path.
//
// After the file is written successfully, WriteFile
// truncates the internal lines buffer, so that you can recycle
// the same Buffer as if it was newly created.
//
// If an error occurrs during the writing of the file,
// no truncation of the buffer is done, so that you can
// retry the method call later.
WriteFile writes all lines written to
the buffer so far to a file with given path.

After the file is written successfully, WriteFile
truncates the internal lines buffer, so that you can recycle
the same Buffer as if it was newly created.

If an error occurrs during the writing of the file,
no truncation of the buffer is done, so that you can
retry the method call later.
// WriteFile writes all lines written to // the buffer so far to a file with given path . // // After the file is written successfully WriteFile // truncates the internal lines buffer so that you can recycle // the same Buffer as if it was newly created . // // If an error occurrs during the writing of the file // no truncation of the buffer is done so that you can // retry the method call later .
func (lines *Buffer) WriteFile(filepath string) error {
	f, err := os.OpenFile(filepath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, fs.FileMode(0644))
	if err != nil {
		return err
	}
	defer f.Close()
	_, err = f.Write(lines.buf.Bytes())
	if err != nil {
		return err
	}
	lines.buf.Truncate(0)
	return err
}
func ( lines * Buffer ) WriteFile ( filepath string ) error { f , err := os . OpenFile ( filepath , os . O_CREATE | os . O_EXCL | os . O_WRONLY , fs . FileMode ( 0644 ) ) if err != nil { return err } defer f . Close ( ) _ , err = f . Write ( lines . buf . Bytes ( ) ) if err != nil { return err } lines . buf . Truncate ( 0 ) return err }
WriteFile writes all lines written to
the buffer so far to a file with given path.
WriteFile writes all lines written to the buffer so far to a file with given path .
// # TODO: add a twin method that uses fs.FS