Skip to content

calebcase/tmpfile

Repository files navigation

Documentation Test Status

Cross Platform Temporary Files

This library attempts to bridge the gap between the what is provided in ioutil.TempFile and the best practice of ensuring temporary files are always deleted when the application exits.

The normal way to do this on a POSIX system is to use the behavior of unlink to immediately remove the directory entry for the temporary file. The OS then ensures that when all open file handles on the file are close that the file resources are removed. Unfortunately, despite Go having os.Remove this does not work on Windows because on Windows it is necessary to open the files with special flags (FILE_SHARE_DELETE, FILE_FLAG_DELETE_ON_CLOSE) to enable removing a file that is open (and ioutil does not do this).

Example usage:

package main

import "github.com/calebcase/tmpfile"

func main() {
	f, err := tmpfile.New("", "example-*")
	if err != nil {
		panic(err)
	}
	defer f.Close()

	f.WriteString("Example Data")
}

About

No description, website, or topics provided.

Resources

License

MIT, BSD-3-Clause licenses found

Licenses found

MIT
LICENSE
BSD-3-Clause
LICENSE.golang

Stars

Watchers

Forks

Packages

No packages published

Languages