github.com/blend/go-sdk@v1.20220411.3/sourceutil/copy.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package sourceutil
     9  
    10  import (
    11  	"context"
    12  	"io"
    13  	"os"
    14  )
    15  
    16  // Copy copies a file from a source to a destination.
    17  func Copy(ctx context.Context, destination, source string) error {
    18  	// Debugf(ctx, "copying %s to %s", source, destination)
    19  	sourceReader, err := os.Open(source)
    20  	if err != nil {
    21  		return err
    22  	}
    23  	defer sourceReader.Close()
    24  	destinationWriter, err := os.Create(destination)
    25  	if err != nil {
    26  		return err
    27  	}
    28  	defer destinationWriter.Close()
    29  	_, err = io.Copy(destinationWriter, sourceReader)
    30  	if err != nil {
    31  		return err
    32  	}
    33  	return nil
    34  }