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
+32.2k Golang : Convert []string to []byte examples
+30.5k Golang : Generate random string
+8.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+20.9k PHP : Convert(cast) int to double/float
+7.2k Golang : Dealing with postal or zip code example
+5.2k Responsive Google Adsense
+14.4k Golang : How to convert a number to words
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+17.7k How to enable MariaDB/MySQL logs ?
+6.3k Golang : Selection sort example
+5.4k Python : Delay with time.sleep() function example
+5.6k PHP : Fix Call to undefined function curl_init() error