Skip to content

Commit

Permalink
add tempfile utility
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino committed Sep 25, 2023
1 parent 13e1319 commit c914ce3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,17 @@ func Exists(path string) bool {
_, err := os.Stat(path)
return !os.IsNotExist(err)
}

func TmpFile(name string, contents []byte) (string, error) {
f, err := os.CreateTemp("", name)
if err != nil {
return "", err
}
defer f.Close()

if _, err := f.Write(contents); err != nil {
return "", err
}

return f.Name(), nil
}

0 comments on commit c914ce3

Please sign in to comment.