Bytes and Slices
Explore how to use Go's bytes package to work with slices of bytes efficiently. Understand the Buffer type and its methods to read, write, and concatenate strings in a memory-friendly way, improving your Go programming skills.
We'll cover the following...
We'll cover the following...
The bytes package
Slices of bytes are so common that Go has a bytes package with manipulation functions for that kind of type. It is very analogous to the strings package. Moreover, it contains a very handy type Buffer:
import "bytes"
type Buffer struct {
...
}
It is a variable-sized buffer of bytes with Read and Write methods because reading and writing an unknown number of bytes is best done buffered. ...