Standard library / bufio

bufio.Writer.AvailableBuffer()

Returns an empty slice with available buffer capacity for appending bytes, then passing it immediately to Write. Invalidated by the next write. Expected stdout: 'abc\n'.

Formal Syntax & Structure

go syntaxgo
func (b *Writer) AvailableBuffer() []byte

Return Value

[]byte

Returns an empty slice with available buffer capacity for appending bytes, then passing it immediately to Write.

Working Example

Example Snippetgo
package main
import (  "bufio"  "bytes"  "fmt")
func main() {  var b bytes.Buffer  w := bufio.NewWriterSize(&b, 8)  p := append(w.AvailableBuffer(), "abc"...)  w.Write(p)  w.Flush()  fmt.Println(b.String())}
Go Reference