Golang io.ReadAtLeast function example

package io

Golang io.ReadAtLeast function usage example

 package main

 import (
 "fmt"
 "io"
 "strings"
 )

 func main() {
 reader := strings.NewReader("GoodBye World!")

 buff := make([]byte, 32)

 n, err := io.ReadAtLeast(reader, buff, 8) // read at least 8 bytes into buffer

 fmt.Printf("\n%s ", buff)

 fmt.Printf("\n Number of bytes copied : %d with error : %v", n, err)
 }

Output :

GoodBye World!

Number of bytes copied : 14 with error :

Reference :

http://golang.org/pkg/io/#ReadAtLeast

Advertisement