util

package
v0.0.0-...-b7e086b Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindAnyTempFileDirectory

func FindAnyTempFileDirectory(preferred string) (string, error)

Try to find any temporary file directory, opting for 'preferred' if that is specified, and falling back to other guesses.

Types

type TempFiles

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

TempFiles assigns temporary filenames, and automatically deletes old temporary files. We don't need to be too worried about aggressive deletion of temp files, because if a temp file is still being sent to a client, and we delete it, then the OS will do the right thing and not actually erase the file until the last handle is closed.

We manage two classes of temporary files:

  1. Once off: These are intended to be created, used, and deleted.
  2. Named: These are intended to be named with a hash, or something similarly unique. Named files live longer. This was created to cache transcoded videos with improved random seek behaviour in a browser <video> element. Naturally, we want this kind of thing to stick around for a while.

func NewTempFiles

func NewTempFiles(root string, logger log.Log) (*TempFiles, error)

Wipes/recreates the root directory

func (*TempFiles) GetNamed

func (t *TempFiles) GetNamed(name string) (filename string, exists bool)

Get a temporary filename for a named item. If you ask for the same name twice, you'll get back the same path. This function will guarantee that the named file will not be deleted for at least guaranteedLifetimeNamed. If the file already exists, then 'exists' is true.

func (*TempFiles) GetOnceOff

func (t *TempFiles) GetOnceOff() string

Get a new temporary filename for a once-off file

Jump to

Keyboard shortcuts

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