file/io.go
func CopytoTemp(source, prefix string) (tmpFile string, err error) {
	if prefix == "" {
		prefix = PREFIX_TEMP
	}

	src, err := os.Open(source)
	if err != nil {
		return "", err
	}
	defer func() {
		err2 := src.Close()
		if err2 != nil && err == nil {
			err = err2
		}
	}()

	dest, err := ioutil.TempFile("", prefix)
	if err != nil {
		return "", err
	}
	defer func() {
		err2 := dest.Close()
		if err2 != nil && err == nil {
			err = err2
		}
	}()

	if _, err = io.Copy(dest, src); err != nil {
		return "", err
	}
	return dest.Name(), nil
}
func CopytoTemp(source, prefix string) (tmpFile string, err error) {
	if prefix == "" {
		prefix = PREFIX_TEMP
	}

	src, err := os.Open(source)
	if err != nil {
		return "", err
	}
	defer func() {
		err2 := src.Close()
		if err2 != nil && err == nil {
			err = err2
		}
	}()

	dest, err := ioutil.TempFile("", prefix)
	if err != nil {
		return "", err
	}
	defer func() {
		err2 := dest.Close()
		if err2 != nil && err == nil {
			err = err2
		}
	}()

	if _, err = io.Copy(dest, src); err != nil {
		return "", err
	}
	return dest.Name(), nil
}
func CopytoTemp ( source , prefix string ) ( tmpFile string , err error ) { if prefix == " " { prefix = PREFIX_TEMP } src , err := os . Open ( source ) if err != nil { return " " , err } defer func ( ) { err2 := src . Close ( ) if err2 != nil && err == nil { err = err2 } } ( ) dest , err := ioutil . TempFile ( " " , prefix ) if err != nil { return " " , err } defer func ( ) { err2 := dest . Close ( ) if err2 != nil && err == nil { err = err2 } } ( ) if _ , err = io . Copy ( dest , src ) ; err != nil { return " " , err } return dest . Name ( ) , nil }
// CopytoTemp creates a temporary file from the source file into the default
// directory for temporary files (see os.TempDir), whose name begins with prefix.
// If prefix is the empty string, uses the default value PREFIX_TEMP.
// Returns the temporary file name.
CopytoTemp creates a temporary file from the source file into the default directory for temporary files ( see os . TempDir ) whose name begins with prefix . If prefix is the empty string uses the default value PREFIX_TEMP . Returns the temporary file name .