Skip to content

Instantly share code, notes, and snippets.

@bom-d-van
Forked from elazarl/cp.go
Created May 3, 2013 13:26
Show Gist options
  • Save bom-d-van/5509102 to your computer and use it in GitHub Desktop.
Save bom-d-van/5509102 to your computer and use it in GitHub Desktop.
package cp
import (
"io"
"os"
)
func cp(dst, src string) error {
s, err := os.Open(src)
if err != nil {
return err
}
// no need to check errors on read only file, we already got everything
// we need from the filesystem, so nothing can go wrong now.
defer s.Close()
d, err := os.Create(dst)
if err != nil {
return err
}
if _, err := io.Copy(d, s); err != nil {
d.Close()
return err
}
return d.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment