aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/path.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-26 17:24:44 +0800
committerobscuren <geffobscura@gmail.com>2014-07-26 17:24:44 +0800
commit41bd38147c2e5968283facf641b2444c09f53d14 (patch)
tree69353d4174e2a244c48eb1faa37d74077b9495d2 /ethutil/path.go
parent92ffc1cc4c7227de93d933181a30c57c5730c41f (diff)
downloadgo-tangerine-41bd38147c2e5968283facf641b2444c09f53d14.tar.gz
go-tangerine-41bd38147c2e5968283facf641b2444c09f53d14.tar.zst
go-tangerine-41bd38147c2e5968283facf641b2444c09f53d14.zip
Clean up and util methods
Diffstat (limited to 'ethutil/path.go')
-rw-r--r--ethutil/path.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/ethutil/path.go b/ethutil/path.go
index 97f58ab7e..27022bcfa 100644
--- a/ethutil/path.go
+++ b/ethutil/path.go
@@ -1,6 +1,8 @@
package ethutil
import (
+ "io/ioutil"
+ "os"
"os/user"
"strings"
)
@@ -18,3 +20,41 @@ func ExpandHomePath(p string) (path string) {
return
}
+
+func FileExist(filePath string) bool {
+ _, err := os.Stat(filePath)
+ if err != nil && os.IsNotExist(err) {
+ return false
+ }
+
+ return true
+}
+
+func ReadAllFile(filePath string) (string, error) {
+ file, err := os.Open(filePath)
+ if err != nil {
+ return "", err
+ }
+
+ data, err := ioutil.ReadAll(file)
+ if err != nil {
+ return "", err
+ }
+
+ return string(data), nil
+}
+
+func WriteFile(filePath string, content []byte) error {
+ fh, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE, os.ModePerm)
+ if err != nil {
+ return err
+ }
+ defer fh.Close()
+
+ _, err = fh.Write(content)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}