September 2017
Intermediate to advanced
466 pages
9h 33m
English
This subsection will present a technique for copying files that uses the io.Copy() function. What is special about the io.Copy() function is the fact that is does not give you any flexibility in the process. The name of the program will be notGoodCP.go and will be presented in three parts. Note that a more appropriate filename for notGoodCP.go would have been copyEntireFileAtOnce.go or copyByReadingInputFileAllAtOnce.go!
The first part of the Go code of notGoodCP.go is the following:
package main import ( "fmt" "io" "os" )
The second part is as follows:
func Copy(src, dst string) (int64, error) { sourceFileStat, err := os.Stat(src) if err != nil { return 0, err } if !sourceFileStat.Mode().IsRegular() { return 0, fmt.Errorf("%s ...Read now
Unlock full access