Standard library / bytes
bytes.Buffer.AvailableBuffer()
Returns an empty slice with available capacity, intended for appending then immediately passing it to Buffer.Write. Valid only until the next write. Expected stdout: 'go\n'.
Formal Syntax & Structure
go syntaxgo
func (b *Buffer) AvailableBuffer() []byteReturn Value
[]byte
Returns an empty slice with available capacity, intended for appending then immediately passing it to Buffer.Write. Valid only until the next write.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt")
func main() { var b bytes.Buffer b.Grow(8) p := append(b.AvailableBuffer(), 'g', 'o') b.Write(p) fmt.Println(b.String())}