tempfile

package
v1.15.15 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 5 Imported by: 12

Documentation

Overview

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

Example
ctx := config.NewContextInMemory()

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 := os.ReadFile(tempfile.Name())
if err != nil {
	panic(err)
}

fmt.Println(string(out))
Output:

foobar

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNotInit = fmt.Errorf("not initialized")

ErrNotInit is returned when the file is not initialized.

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 implements io.Writer.

Jump to

Keyboard shortcuts

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