moving writeToDisk to helpers to make it more accessible

This commit is contained in:
spf13
2014-05-01 13:13:11 -04:00
parent f271faea06
commit 58f8b43fee
3 changed files with 29 additions and 26 deletions

View File

@@ -15,12 +15,14 @@ package helpers
import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"regexp"
"strings"
"unicode"
"github.com/spf13/viper"
)
@@ -151,3 +153,24 @@ func FindCWD() (string, error) {
return path, nil
}
func WriteToDisk(inpath string, r io.Reader) (err error) {
dir, _ := filepath.Split(inpath)
ospath := filepath.FromSlash(dir)
if ospath != "" {
err = os.MkdirAll(ospath, 0777) // rwx, rw, r
if err != nil {
panic(err)
}
}
file, err := os.Create(inpath)
if err != nil {
return
}
defer file.Close()
_, err = io.Copy(file, r)
return
}