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
+11.6k Get form post value in Go
+10.1k Golang : Identifying Golang HTTP client request
+26.9k Golang : Force your program to run with root permissions
+14k Golang : Reverse IP address for reverse DNS lookup example
+16.1k Golang : How to check if input from os.Args is integer?
+11.6k Golang : Surveillance with web camera and OpenCV
+19.6k Golang : Set or Add HTTP Request Headers
+8.3k Golang : Number guessing game with user input verification example
+4.7k Chrome : How to block socketloop.com links in Google SERP?
+9.2k Golang : How to check if a string with spaces in between is numeric?
+8.3k Golang : Check if integer is power of four example
+14.6k Golang : How to get URL port?