tempfile

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2018 License: BSD-3-Clause Imports: 6 Imported by: 6

README

tempfile

An alternative implementation of ioutil.TempFile that provides a little more control over the temporary files being created. It allows the caller to provide a file suffix and/or file mode to set the permissions to something other than the default 0600.

Examples

// Make a temp file in /var/tmp with the default file mode 0600. This is
// equivalent to what ioutil.TempFile does.
f, err := tempfile.New("/var/tmp", "myfile")
if err != nil {
  panic(err)
}
defer os.Remove(f.Name())
defer f.Close()

// Make a temporaty file with the given prefix and suffix
f, err = tempfile.NewSuffix("", "myfile", ".tmp")
...

// Create a world-readable temporary file in the OS' temp dir by providing
// a file mode.
f, err = tempfile.NewMode("", "myfile", 0644)
...

// Combining all of the above
f, err = tempfile.NewSuffixAndMode("", "myfile", ".ext", 0644)
...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(dir, prefix string) (f *os.File, err error)

New creates a new temporary file in the specified directory the same way ioutils.TempFile does. If dir is an empty string, it'll be created in the OS' temp directory. The caller is responsible for removing the file. Drop-in replacement for ioutils.TempFile

func NewMode

func NewMode(dir, prefix string, perm os.FileMode) (f *os.File, err error)

NewMode does the same as New() but allows the caller to provide a file mode to give the file permissions different from the default 0600.

func NewSuffix

func NewSuffix(dir, prefix, suffix string) (f *os.File, err error)

NewSuffix does the same as New() but allows a suffix to be added to the name.

func NewSuffixAndMode

func NewSuffixAndMode(dir, prefix, suffix string, perm os.FileMode) (f *os.File, err error)

NewSuffixAndMode does the same as New(), but allows the caller to provide a suffix as well as a file mode to be used for the temporary file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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