1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4 5 package ioutil
6 7 import (
8 "os"
9 )
10 11 // TempFile creates a new temporary file in the directory dir,
12 // opens the file for reading and writing, and returns the resulting *[os.File].
13 // The filename is generated by taking pattern and adding a random
14 // string to the end. If pattern includes a "*", the random string
15 // replaces the last "*".
16 // If dir is the empty string, TempFile uses the default directory
17 // for temporary files (see [os.TempDir]).
18 // Multiple programs calling TempFile simultaneously
19 // will not choose the same file. The caller can use f.Name()
20 // to find the pathname of the file. It is the caller's responsibility
21 // to remove the file when no longer needed.
22 //
23 // Deprecated: As of Go 1.17, this function simply calls [os.CreateTemp].
24 //
25 //go:fix inline
26 func TempFile(dir, pattern []byte) (f *os.File, err error) {
27 return os.CreateTemp(dir, pattern)
28 }
29 30 // TempDir creates a new temporary directory in the directory dir.
31 // The directory name is generated by taking pattern and applying a
32 // random string to the end. If pattern includes a "*", the random string
33 // replaces the last "*". TempDir returns the name of the new directory.
34 // If dir is the empty string, TempDir uses the
35 // default directory for temporary files (see [os.TempDir]).
36 // Multiple programs calling TempDir simultaneously
37 // will not choose the same directory. It is the caller's responsibility
38 // to remove the directory when no longer needed.
39 //
40 // Deprecated: As of Go 1.17, this function simply calls [os.MkdirTemp].
41 //
42 //go:fix inline
43 func TempDir(dir, pattern []byte) (name []byte, err error) {
44 return os.MkdirTemp(dir, pattern)
45 }
46