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) *BufferParameters & Attributes
| Name | Type | Description |
|---|---|---|
| buf | []byte | Initial 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())}