Golang bytes.Reader.Len() function example

package bytes

Len returns the number of bytes of the unread portion of the slice.

Golang bytes.Reader.Len() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {
 reader := bytes.NewReader([]byte("abc"))

 fmt.Println(reader.Len())

 var b [2]byte
 reader.Read(b[:])

 // should be 1 after Read 2 bytes
 fmt.Println(reader.Len())


 }

Output :

3

1

Reference :

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

Advertisement