Tuesday 11 October 2022
#go doesn’t have a function to copy files. the following is a simple implementation.
It seams it uses one Copy
function so I guess this is suitable for small files as large files will take too long and there is no way to know the progress or cancel it.
So use it for files that you expect to be small.
1func copyFile(src, dst string) error {
2 in, err := os.Open(src)
3 if err != nil {
4 return err
5 }
6 defer in.Close()
7
8 out, err := os.Create(dst)
9 if err != nil {
10 return err
11 }
12 defer out.Close()
13
14 _, err = io.Copy(out, in)
15 if err != nil {
16 return err
17 }
18 return out.Close()
19}
See Also
- Access unexported struct fields in Go
- Converting Ruby sinatra project to Go
- Country code to flag emojie in Go
- Go FileSystem with fallback
- Go function logging technique
- Go init function
- Go slice that doesn't grow past capacity
- Golang Bleve Experience
- Golang
- 🌻 Home
- Learning Go
- Mau
- ⌨️ Programming
- Replacing Golang Regexp matching with a premitive faster solution
- Xlog
- json