Golang bytes.Buffer.Len() function example

package bytes

Len returns the number of bytes of the unread portion of the buffer. Bytes.Buffer.Len() function is the same as len(buffer.Bytes()).

Golang bytes.Len() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {
 buff := bytes.NewBufferString("abcdefghi")

 fmt.Printf("%d\n", len(buff.Bytes()))

 fmt.Printf("%d\n", buff.Len())

 }

Output :

9

9

Reference :

http://golang.org/pkg/bytes/#Buffer.Len

Advertisement