tempfile

package module
v0.0.0-...-33beb05 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2018 License: BSD-3-Clause Imports: 5 Imported by: 17

README

Go Report Card go-doc

tempfile

An implementation of ioutil.TempFile, but also with an additional parameter for a deterministic suffix.

This is a workaround for https://github.com/golang/go/issues/4896.

Example

import "github.com/tink-ab/tempfile"

myFile, err := tempfile.TempFile("", "my-prefix", "my-suffix")
if err != nil {
    handleError(err)
}
defer myFile.Close()
defer func() {
    if err := os.Remove(myFile.Name()); err != nil {
        handleRemovalError(err)
    }
}()

doSomethingWith(myFile)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TempFile

func TempFile(dir, prefix string, suffix string) (f *os.File, err error)

TempFile creates a new temporary file in the directory dir with a name beginning with prefix and ending with suffix, opens the file for reading and writing, and returns the resulting *os.File. If dir is the empty string, TempFile uses the default directory for temporary files (see os.TempDir). Multiple programs calling TempFile simultaneously will not choose the same file. The caller can use f.Name() to find the pathname of the file. It is the caller's responsibility to remove the file when no longer needed.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL