Skip to content

Commit

Permalink
use CopyBuffer to copy the file from src to dest
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelm41 committed Dec 7, 2021
1 parent 53dd259 commit 0f91b93
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,8 @@ func CopyFile(origFilePath, destFilePath string) error {

// make a buffer to keep chunks that are read
buf := make([]byte, copyChunkSize)
for {
// read a chunk
n, err := srcReader.Read(buf)
if err != nil && err != io.EOF {
return err
}

if n == 0 {
break
}

// write a chunk
if _, err := destWriter.Write(buf[:n]); err != nil {
return err
}
if _, err := io.CopyBuffer(destWriter, srcReader, buf); err != nil {
return err
}

if err := destWriter.Flush(); err != nil {
Expand Down

0 comments on commit 0f91b93

Please sign in to comment.