Standard library / bytes

bytes.NewBuffer()

Creates a buffer taking ownership of buf; do not use buf after the call. Use a zero-value Buffer or NewBuffer(make([]byte,0,n)) for initially empty storage. Expected stdout: 'go!\n'.

Formal Syntax & Structure

go syntaxgo
func NewBuffer(buf []byte) *Buffer

Parameters & Attributes

NameTypeDescription
buf[]byteInitial buffer contents; ownership is transferred.

Return Value

*Buffer

Creates a buffer taking ownership of buf; do not use buf after the call. Use a zero-value Buffer or NewBuffer(make([]byte,0,n)) for initially empty storage.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt")
func main() {  b := bytes.NewBuffer([]byte("go"))  b.WriteString("!")  fmt.Println(b.String())}
Go Reference