import "github.com/justwatchcom/gopass/pkg/tempfile"
Package tempfile is a wrapper around ioutil.TempDir, providing an OO pattern as well as secure placement on a temporary ramdisk.
Code:
ctx := context.Background() tempfile, err := New(ctx, "gopass-secure-") if err != nil { panic(err) } defer func() { if err := tempfile.Remove(ctx); err != nil { panic(err) } }() fmt.Fprintln(tempfile, "foobar") if err := tempfile.Close(); err != nil { panic(err) } out, err := ioutil.ReadFile(tempfile.Name()) if err != nil { panic(err) } fmt.Println(string(out))
Output:
foobar
type File struct {
// contains filtered or unexported fields
}
File is a temporary file
New returns a new tempfile wrapper
Close implements io.WriteCloser
Name returns the name of the tempfile
Remove attempts to remove the tempfile
Write implement io.Writer
Package tempfile imports 6 packages (graph) and is imported by 1 packages. Updated 2021-01-24. Refresh now. Tools for package owners.