Documentation ¶
Overview ¶
Package tmpfile provides a cross platform facility for creating temporary files that are automatically cleaned up (even in the event of an unexpected process exit).
tmpfile provides support for at least Linux, OSX, and Windows. Generally any POSIX system that adheres to the semantics of unlink (https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html) should work. Special handling is provided for other platforms.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New creates a new temporary file in the directory dir using ioutil.TempFile and then unlinks the file with os.Remove to ensure the file is deleted when the calling process exists.
If dir is the empty string it will default to using os.TempDir() as the directory for storing the temporary files.
The target directory dir must already exist or an error will result. New does not create or remove the directory dir.
Example (Default) ¶
// Use the system default temp directory (as returned by os.TempDir(). // This is equivalent to New(os.TempDir(), "example-"). f, err := New("", "example-") if err != nil { panic(err) } defer f.Close()
Output:
Example (Dir) ¶
// Use a local directory for the temporary files. This directory must // already exist. f, err := New("ephemeral", "example-") if err != nil { panic(err) } defer f.Close()
Output:
Types ¶
This section is empty.