September 2017
Intermediate to advanced
466 pages
9h 33m
English
Both io.Writer and io.Reader are interfaces that embed the io.Write() and io.Read() methods, respectively. The use of io.Writer and io.Reader will be illustrated in readerWriter.go, which will be presented in four parts. The program computes the characters of its input file and writes the number of characters to another file: if you are dealing with Unicode characters that take more than one byte per character, you might consider that the program is reading bytes. The output filename has the name of the original file plus the .Count extension.
The first part is the following:
package main import ( "fmt" "io" "os" )
The second part is the following:
func countChars(r io.Reader) int { buf := make([]byte, 16) total ...Read now
Unlock full access