Golang io.SectionReader.Size function example
package io
Golang io.SectionReader.Size function usage example
package main
import (
"bytes"
"fmt"
"io"
)
func main() {
reader := bytes.NewReader([]byte("abcdefghijklmnopqrstuvwxyz"))
// read from position 2 to 8
// remember...counting starts from zero
sectionReader := io.NewSectionReader(reader, 0, 8)
fmt.Printf("Read up to %d characters(bytes)\n", sectionReader.Size())
buff := make([]byte, 7)
// read section into buff
n, err := sectionReader.Read(buff)
if err != nil {
fmt.Println(err)
}
fmt.Printf("Read %d characters(bytes) of %s \n", n, string(buff[:]))
}
Output :
Read up to 8 characters(bytes)
Read 7 characters(bytes) of abcdefg
Reference :
Advertisement
Something interesting
Tutorials
+8.8k Golang : Executing and evaluating nested loop in html template
+24.1k Golang : Upload to S3 with official aws-sdk-go package
+27.6k PHP : Convert(cast) string to bigInt
+5.1k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+11.7k Golang : How to detect a server/machine network interface capabilities?
+23.1k Golang : simulate tail -f or read last line from log file example
+17.6k Convert JSON to CSV in Golang
+19.1k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+9.4k Golang : Web(Javascript) to server-side websocket example
+5.3k Golang : Generate Interleaved 2 inch by 5 inch barcode
+7.9k Setting $GOPATH environment variable for Unix/Linux and Windows
+6.6k Golang : Totalize or add-up an array or slice example