Skip to content

Commit 287a147

Browse files
committed
Added a simple file copy helper
1 parent 9f7547d commit 287a147

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

goext/file_extensions.go

+15
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,18 @@ func FileExists(filePath string) (bool, error) {
3535
}
3636
return false, err
3737
}
38+
39+
// CopyFile is a simple file copy from source to destination.
40+
func CopyFile(src string, dst string) (int64, error) {
41+
srcFile, err := os.Open(src)
42+
if err != nil {
43+
return -1, err
44+
}
45+
defer srcFile.Close()
46+
dstFile, err := os.Create(dst)
47+
if err != nil {
48+
return -1, err
49+
}
50+
defer dstFile.Close()
51+
return dstFile.ReadFrom(srcFile)
52+
}

0 commit comments

Comments
 (0)