github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/file/copy.go (about)

     1  // Copyright 2021 The TrueBlocks Authors. All rights reserved.
     2  // Use of this source code is governed by a license that can
     3  // be found in the LICENSE file.
     4  
     5  package file
     6  
     7  import (
     8  	"io"
     9  	"os"
    10  )
    11  
    12  func Copy(destPath, sourcePath string) (int64, error) {
    13  	source, err := os.OpenFile(sourcePath, os.O_RDONLY, 0)
    14  	if err != nil {
    15  		return 0, err
    16  	}
    17  	defer source.Close()
    18  
    19  	dest, err := os.OpenFile(destPath, os.O_WRONLY|os.O_CREATE, 0644)
    20  	if err != nil {
    21  		return 0, err
    22  	}
    23  	defer dest.Close()
    24  
    25  	return io.Copy(dest, source)
    26  }