tempfile

package
v0.66.8 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: MIT Imports: 5 Imported by: 12

Documentation

Overview

Package tempfile is a wrapper around ioutil.TempDir, providing an OO pattern as well as secure placement on a temporary ramdisk.

Example
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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

File is a temporary file

func New

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

New returns a new tempfile wrapper

func (*File) Close

func (t *File) Close() error

Close implements io.WriteCloser

func (*File) Name

func (t *File) Name() string

Name returns the name of the tempfile

func (*File) Remove

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

Remove attempts to remove the tempfile

func (*File) Write

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

Write implement io.Writer

Jump to

Keyboard shortcuts

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