Bufio
bufio is Go’s standard-library package providing buffered input and output wrappers and utilities for incrementally processing streams.
Go in Action, Second Edition
bufio is Go's standard library package for buffered input and output, including scanner-based tokenization.
- How it is used
- Buffers file, network, and stream I/O while supporting line-oriented reading, tokenization, look-ahead, and efficient output.
- 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 you can do after
- Operate buffered readers and writers, process input incrementally, inspect prefixes, handle EOF, and flush output correctly.
Go in Practice, Second Edition
The Go bufio package provides buffered input and output wrappers and utilities for processing streams incrementally.
- How it is used
- Processes large, line-delimited files incrementally through buffered scanning instead of reading complete contents at once.
- How deep it goes
- Demonstrates Scanner and ScanLines in runnable code, while deferring deeper optimization and distributed processing.
- Examples
- Uses a structured.log file containing newline-delimited JSON records and extracts each record's level.
- What you can do after
- Build line-oriented Go processors that scan files incrementally and handle malformed records without stopping the entire stream.
Also covered in
Related concepts
- bufferingimplements · Buffering is the temporary storage of data between processing or transfer steps, often to accommodate differences in rates or reduce operation costs.
- bufio.Scannerhas part · bufio.Scanner is a Go type that reads input and advances through it as successive tokens.
- io.Writerimplements · io.Writer is a Go interface for writing bytes from a caller-provided sequence to a destination, reporting the number of bytes written and any error.
- io.Readeruses · io.Reader is a Go interface for reading bytes from a data source into a caller-provided buffer, reporting the number of bytes read and any error.
Questions about bufio
What is bufio?
bufio is Go’s standard-library package providing buffered input and output wrappers and utilities for incrementally processing streams.
Which Manning books explain bufio?
Go in Action, Second Edition and Go in Practice, Second Edition.
What are the parts of bufio?
Bufio includes bufio.Scanner, NewReaderSize and ScanWords.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

