gopass: github.com/justwatchcom/gopass/pkg/tempfile Index | Examples | Files

package tempfile

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

Index

Examples

Package Files

file.go mount_linux.go

type File Uses

type File struct {
    // contains filtered or unexported fields
}

File is a temporary file

func New Uses

func New(ctx context.Context, prefix string) (*File, error)

New returns a new tempfile wrapper

func (*File) Close Uses

func (t *File) Close() error

Close implements io.WriteCloser

func (*File) Name Uses

func (t *File) Name() string

Name returns the name of the tempfile

func (*File) Remove Uses

func (t *File) Remove(ctx context.Context) error

Remove attempts to remove the tempfile

func (*File) Write Uses

func (t *File) Write(p []byte) (int, error)

Write implement io.Writer

Package tempfile imports 6 packages (graph). Updated 2020-07-07. Refresh now. Tools for package owners.