Skip to content

Commit 933a253

Browse files
committed
Added various constructors
1 parent 631fc5d commit 933a253

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

constructors.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package paths
2+
3+
import (
4+
"io/ioutil"
5+
"os"
6+
"runtime"
7+
)
8+
9+
// NullPath return the path to the /dev/null equivalent for the current OS
10+
func NullPath() *Path {
11+
if runtime.GOOS == "windows" {
12+
return New("nul")
13+
}
14+
return New("/dev/null")
15+
}
16+
17+
// TempDir returns the default path to use for temporary files
18+
func TempDir() *Path {
19+
return New(os.TempDir())
20+
}
21+
22+
// MkTempDir creates a new temporary directory in the directory
23+
// dir with a name beginning with prefix and returns the path of
24+
// the new directory. If dir is the empty string, TempDir uses the
25+
// default directory for temporary files
26+
func MkTempDir(dir, prefix string) (*Path, error) {
27+
path, err := ioutil.TempDir(dir, prefix)
28+
if err != nil {
29+
return nil, err
30+
}
31+
return New(path), nil
32+
}

0 commit comments

Comments
 (0)