Standard library / bytes

bytes.Buffer.Bytes()

Returns a slice of unread bytes sharing buffer storage. Valid until the next modification; copy for independent retention. Expected stdout: 'Go\n'.

Formal Syntax & Structure

go syntaxgo
func (b *Buffer) Bytes() []byte

Return Value

[]byte

Returns a slice of unread bytes sharing buffer storage. Valid until the next modification; copy for independent retention.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt")
func main() {  b := bytes.NewBufferString("go")  p := b.Bytes()  p[0] = 'G'  fmt.Println(b.String())}
Go Reference