Standard library / bufio

bufio.Writer.Write()

Accepts bytes into the buffer or destination; errors can surface later on Flush. Returns accepted count and error. Expected stdout: '3 abc <nil>\n'.

Formal Syntax & Structure

go syntaxgo
func (b *Writer) Write(p []byte) (nn int, err error)

Parameters & Attributes

NameTypeDescription
p[]byteByte slice supplied by the caller.

Return Value

(nn int, err error)

Accepts bytes into the buffer or destination; errors can surface later on Flush.

Working Example

Example Snippetgo
package main
import (  "bufio"  "bytes"  "fmt")
func main() {  var b bytes.Buffer  w := bufio.NewWriter(&b)  n, e := w.Write([]byte("abc"))  w.Flush()  fmt.Println(n, b.String(), e)}
Go Reference