liveBook · Manning

Bufio

As explained in Go in Action, Second Edition

bufio is Go's standard library package for buffered input and output, including scanner-based tokenization.

bufio provides buffered input and output for Go programs. It processes data in manageable chunks, reducing memory use and the system-call overhead of repeated unbuffered operations. section 2.8 section 10.6

The package wraps existing io.Reader and io.Writer implementations with specialized types: Reader for buffered reads and look-ahead, Writer for buffered output, and Scanner for convenient token-based reading. section 2.8 section 10.6

Buffered processing in a converter

A JSON/XML conversion pipeline can write through bufio.Writer, defer or explicitly call Flush, read from an io.Reader, detect the format, convert the data, and write the result efficiently.

Figure 10.4 Comparison of unbuffered and buffered I/O, showing performance benefits

Compare unbuffered operations with buffered batching to see why fewer system calls improve throughput, especially for large files and streams. section 10.6

How Go in Action, Second Edition covers it

How deep it goes
Explains buffering, system-call reduction, core types, line reads, peeking, writing, error handling, and flushing.
Examples
Demonstrates line scanning, input-format detection with Peek, buffered writing, and JSON/XML conversion.
What it assumes
Builds on io.Reader and io.Writer while introducing buffering, Scanner, line reads, peeking, and flushing.
What you can do after
Operate buffered readers and writers, process input incrementally, inspect prefixes, handle EOF, and flush output correctly.
How it connects
Connects buffering with io.Reader, io.Writer, Scanner, file processing, network connections, and JSON/XML conversion.

Also explained in

Compare how 2 books explain bufio →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Action, Second Edition. The section links point to the parts of the book it draws on.