Compare commits
2 Commits
3239644cc2
...
b1f0eb2769
Author | SHA1 | Date | |
---|---|---|---|
b1f0eb2769 | |||
5d77a9a3d3 |
26
util.go
26
util.go
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user