mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-01-23 10:35:44 +00:00
Faster CopyFile
This commit is contained in:
parent
31c670252c
commit
45dba68b15
1 changed files with 22 additions and 3 deletions
25
pkg/os/os.go
25
pkg/os/os.go
|
|
@ -51,12 +51,31 @@ func GetUserHome() (string, error) {
|
|||
return me.HomeDir, nil
|
||||
}
|
||||
|
||||
func CopyFile(from string, to string) error {
|
||||
bytesRead, err := os.ReadFile(from)
|
||||
func CopyFile(from string, to string) (err error) {
|
||||
f, err := os.Open(from)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.WriteFile(to, bytesRead, 0755)
|
||||
defer func() {
|
||||
if err2 := f.Close(); err2 != nil {
|
||||
err = errors.Join(err, err2)
|
||||
}
|
||||
}()
|
||||
|
||||
destFile, err := os.Create(to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err2 := destFile.Close(); err != nil {
|
||||
err = errors.Join(err, err2)
|
||||
}
|
||||
}()
|
||||
|
||||
n, err := f.WriteTo(destFile)
|
||||
if n == 0 {
|
||||
return errors.New("nothing was written")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue