Buffered Writers
Batch writes.
Why Buffer Writes
Like reads, every small write can trigger a syscall. bufio.Writer collects writes in memory and flushes them in large chunks.
Critical: buffered data is lost unless you Flush().
Creating a bufio.Writer
Wrap any io.Writer. Here we wrap os.Stdout.
package main
import (
"bufio"
"os"
)
func main() {
w := bufio.NewWriter(os.Stdout)
w.WriteString("Hello buffered\n")
w.Flush()
}All lessons in this course
- Buffered Readers
- Scanners
- Buffered Writers
- Streaming Large Files