O'Reilly logo

Go: Design Patterns for Real-World Projects by Mat Ryer, Mario Castro Contreras, Vladimir Vivien

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required