tempfiles

package module
v0.0.0-...-bbd2bf7 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2021 License: GPL-3.0 Imports: 5 Imported by: 0

README

path-tmp

Temporary file management for Golang. Based on my path library (soon to be separated into a repository).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(l Like) (vf path.ValidFile, err error)

Types

type Builder

type Builder struct {
	RootDir               string
	MainDir               string
	RandomNumberGenerator rand.Rand
}

func (Builder) Build

func (b Builder) Build() (f Files, err error)

func (Builder) With

func (b Builder) With(opts ...Option) (bb Builder)

type CreateFail

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

CreateFail describes file creation failure.

func (CreateFail) Error

func (e CreateFail) Error() (s string)

func (CreateFail) Unwrap

func (e CreateFail) Unwrap() (err error)

type Files

type Files struct {
	// Path to the root directory
	RootDir path.Dir

	// random number generator for generating random file names
	rand.Rand
	// contains filtered or unexported fields
}

Files is the main struct for managing temporary files in a single directory.

func FromDir

func FromDir(rootDir path.Dir, rng rand.Rand) (f Files)

FromDir sets up temporary file management for the specified directory with the given randum number generator.

func FromRand

func FromRand(rng rand.Rand) (f Files, err error)

FromRand sets up temporary file management with the specified random number generator. Directory name will be randomly generated using the generator.

func New

func New(dir, prefix string, rng rand.Rand) (f Files, err error)

func NewDefault

func NewDefault() (f Files, err error)

NewDefault sets up temporary file management with default parameters. random number generator will be produced using the current unix time stamp.

func (*Files) Get

func (f *Files) Get() (vf path.File, err error)

Get retreives a new temporary file to be used. First it searches for a file that is not in use. If no such file is found a new file will be created and registered in the receivers fileset.

func (Files) Mutexed

func (f Files) Mutexed() (m Mutexed)

Mutexed converts to mutex guarded temporary file manager.

func (*Files) NewFile

func (f *Files) NewFile() (vf path.File)

NewFile creates a new file to be used in the temporary file directory. Returns error if file creation has failed.

func (*Files) Put

func (f *Files) Put(vf path.File)

Put signals to the receiver that the temporary file is no longer in use. Should be used in conjunction with Get.

var t = NewDefaultTempFiles()
f, err := t.Get()
if err != nil {
    // error handling
}
defer t.Put(f)
// use f

func (*Files) Remove

func (f *Files) Remove() (err error)

Remove removes the temporary directory containing the temporary files.

func (*Files) Search

func (f *Files) Search() (vf path.File, found bool)

Search searchs for a valid file that is not in use managed by the receiver. The second return argument marks whether a file that is not in use was found.

type KeepAlive

type KeepAlive struct {
	Like
}

func (KeepAlive) Remove

func (_ KeepAlive) Remove() (err error)

type Like

type Like interface {
	Get() (path.File, error)
	Put(path.File)
	Remove() error
}

type MainDir

type MainDir string

func (MainDir) ApplyToTempFiles

func (r MainDir) ApplyToTempFiles(b *Builder)

type Mutexed

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

Mutexed is concurrent safe Files, guarded by mutex

func (*Mutexed) Get

func (m *Mutexed) Get() (vf path.File, err error)

Get retreives a tempfile to be used in a concurrent safe way.

func (*Mutexed) Put

func (m *Mutexed) Put(vf path.File)

Put signals that a tempfile can be reused in a concurrent safe way.

func (*Mutexed) Search

func (m *Mutexed) Search() (vf path.File, found bool)

Search searches for a tempfile to be used in a concurrent safe way.

type Option

type Option interface {
	ApplyToTempFiles(*Builder)
}

type RNG

type RNG rand.Rand

func (RNG) ApplyToTempFiles

func (r RNG) ApplyToTempFiles(b *Builder)

type RootDir

type RootDir string

func (RootDir) ApplyToTempFiles

func (r RootDir) ApplyToTempFiles(b *Builder)

type Set

type Set map[path.File]empty

Set represents a set of temporary files that can be used

type Status

type Status bool

Status represents whether a temporary filepath is in use or not.

const (
	InUse    Status = true
	NotInUse Status = false
)

type WithExtension

type WithExtension struct {
	Like
	// contains filtered or unexported fields
}

func (WithExtension) Get

func (w WithExtension) Get() (f path.File, err error)

Jump to

Keyboard shortcuts

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