2016-07-22 18:15:38 +00:00
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
2010-12-03 04:34:57 +00:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package ioutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2018-09-24 21:46:21 +00:00
|
|
|
// TempFile creates a new temporary file in the directory dir,
|
|
|
|
// opens the file for reading and writing, and returns the resulting *os.File.
|
|
|
|
// The filename is generated by taking pattern and adding a random
|
|
|
|
// string to the end. If pattern includes a "*", the random string
|
|
|
|
// replaces the last "*".
|
2010-12-03 04:34:57 +00:00
|
|
|
// If dir is the empty string, TempFile uses the default directory
|
|
|
|
// for temporary files (see os.TempDir).
|
|
|
|
// Multiple programs calling TempFile simultaneously
|
2016-07-22 18:15:38 +00:00
|
|
|
// 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
|
2012-11-21 07:03:38 +00:00
|
|
|
// to remove the file when no longer needed.
|
2021-07-30 14:28:58 -07:00
|
|
|
//
|
|
|
|
// As of Go 1.17, this function simply calls os.CreateTemp.
|
2018-09-24 21:46:21 +00:00
|
|
|
func TempFile(dir, pattern string) (f *os.File, err error) {
|
2021-07-30 14:28:58 -07:00
|
|
|
return os.CreateTemp(dir, pattern)
|
2020-01-02 15:05:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TempDir creates a new temporary directory in the directory dir.
|
|
|
|
// The directory name is generated by taking pattern and applying a
|
|
|
|
// random string to the end. If pattern includes a "*", the random string
|
|
|
|
// replaces the last "*". TempDir returns the name of the new directory.
|
|
|
|
// If dir is the empty string, TempDir uses the
|
2011-03-16 23:05:44 +00:00
|
|
|
// default directory for temporary files (see os.TempDir).
|
|
|
|
// Multiple programs calling TempDir simultaneously
|
2016-07-22 18:15:38 +00:00
|
|
|
// will not choose the same directory. It is the caller's responsibility
|
2011-03-16 23:05:44 +00:00
|
|
|
// to remove the directory when no longer needed.
|
2021-07-30 14:28:58 -07:00
|
|
|
//
|
|
|
|
// As of Go 1.17, this function simply calls os.MkdirTemp.
|
2020-01-02 15:05:27 -08:00
|
|
|
func TempDir(dir, pattern string) (name string, err error) {
|
2021-07-30 14:28:58 -07:00
|
|
|
return os.MkdirTemp(dir, pattern)
|
2011-03-16 23:05:44 +00:00
|
|
|
}
|