tempfile

package module
v0.0.0-...-48f0f8a Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2015 License: MIT Imports: 5 Imported by: 1

README

ioutil.TempFile with suffix

Usage

package main

import (
	"log"
	"os"

	"github.com/mash/go-tempfile-suffix"
)

func main() {
	f, err := tempfile.TempFileWithSuffix("", "prefix", ".suffix")
	if f != nil {
		defer func() {
			f.Close()
			os.Remove(f.Name())
		}()
	}
	if err != nil {
		log.Printf("error: %s", err.Error())
		return
	}
	log.Printf("got tempfile: %s", f.Name())
	// 2015/07/31 18:37:20 got tempfile: /var/folders/gc/694vhx9n0q57vw71w6__rf4h0000gn/T/prefix905642731.suffix
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TempFileWithSuffix

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

TempFile creates a new temporary file in the directory dir with a name beginning with prefix, opens the file for reading and writing, and returns the resulting *os.File. If dir is the empty string, TempFile uses the default directory for temporary files (see os.TempDir). Multiple programs calling TempFile simultaneously will not choose the same file. The caller can use f.Name() to find the pathname of the file. It is the caller's responsibility to remove the file when no longer needed.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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