A Buffer is a variable-sized buffer
of bytes
with [Buffer.Read]
and [Buffer.Write]
methods.
Buffer
is an empty buffer
ready to use.type Buffer struct { buf []byte // contents are the bytes buf[off : len(buf)] off int // read at &buf[off], write at &buf[len(buf)] lastRead readOp // last read operation, so that Unread* can work correctly. }
[]byte
)io.Reader
is an interface that wraps the basic Read
method.
Read
reads up to len(p)
bytes into p
number of bytes
read (0 <= n <= len(p))
and any error
encounteredtype Reader interface { Read(p []byte) (n int, err error) }
It is useful when
import ( "bytes" ) func main() []byte { buf := new(bytes.Buffer) return buf.Bytes() }