September 2017
Intermediate to advanced
466 pages
9h 33m
English
Byte slices are a kind of slices used for file reading and writing. Putting it simply, they are slices of bytes used as a buffer during file reading and writing operations. This section will present a small Go example where a byte slice is used for writing to a file and reading from a file. As you will see byte slices all over this chapter, make sure that you understand the presented example. The related Go code is saved as byteSlice.go and will be presented in three parts.
The first part is as follows:
package main import ( "fmt" "io/ioutil" "os" )
The second part of byteSlice.go is as follows:
func main() { if len(os.Args) != 2 { fmt.Println("Please provide a filename") os.Exit(1) } filename := os.Args[1] aByteSlice := []byte("Mihalis ...Read now
Unlock full access