Golang bytes.Buffer.WriteByte() function example

package bytes

WriteByte appends the input byte to the buffer, growing the buffer as needed. The returned error is always nil, but is included to match bufio.Writer's WriteByte. If the buffer becomes too large, WriteByte will panic with ErrTooLarge.

Golang bytes.Buffer.WriteByte() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {
 buff := bytes.NewBuffer(nil) // create empty buffer

 buff.WriteByte('a')
 buff.WriteRune('中')
 buff.WriteByte('b')

 fmt.Printf("%s \n", string(buff.Bytes()))
 }

Output :

a中b

Reference :

http://golang.org/pkg/bytes/#Buffer.WriteByte

Advertisement