In this section, you will learn how to read exactly the amount of data you want. This technique is particularly useful when reading binary files, where you have to decode the data you read in a particular way. Nevertheless, this technique still works with text files.
The logic behind this technique is as follows: you create a byte slice with the size you need and use that byte slice for reading. To make this more interesting, this functionality is going to be implemented as a function with two parameters. One parameter will be used to specify the amount of data that you want to read, and the other parameter, which will have the *os.File type, will be used to access the desired file. The return value of that function will be the data you have read.
The name of the Go program for this topic will be readSize.go and it will be presented in four parts...