Compare commits

...

2 Commits

Author SHA1 Message Date
Jeffrey Paul b1f0eb2769 Merge branch 'master' of git.eeqj.de:sneak/goutil 2020-09-21 14:53:43 -07:00
Jeffrey Paul 5d77a9a3d3 add file copy function 2020-09-21 14:53:35 -07:00
1 changed files with 26 additions and 0 deletions

26
util.go
View File

@ -2,6 +2,7 @@ package goutil
import (
"errors"
"io"
"math"
"os"
"regexp"
@ -43,3 +44,28 @@ func Mkdirp(p string) error {
}
return nil
}
// straight outta stackoverflow
// https://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file-in-golang
func CopyFile(src, dst string) (err error) {
in, err := os.Open(src)
if err != nil {
return
}
defer in.Close()
out, err := os.Create(dst)
if err != nil {
return
}
defer func() {
cerr := out.Close()
if err == nil {
err = cerr
}
}()
if _, err = io.Copy(out, in); err != nil {
return
}
err = out.Sync()
return
}