Buffered IO

Most IO operations covered so far have been unbuffered. This implies that each read and write operation could be negatively impacted by the latency of the underlying OS to handle IO requests. Buffered operations, on the other hand, reduces latency by buffering data in internal memory during IO operations. The bufio package (https://golang.org/pkg/bufio/) offers functions for buffered read and write IO operations.

Buffered writers and readers

The bufio package offers several functions to do buffered writing of IO streams using an io.Writer interface. The following snippet creates a text file and writes to it using buffered IO:

func main() { rows := []string{ "The quick brown fox", "jumps over the lazy dog", } fout, err := os.Create("./filewrite.data") ...

Get Learning Go Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.