Golang io.SectionReader.ReadAt function example
package io
Golang io.SectionReader.ReadAt 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, 2, 8)
buff := make([]byte, 7)
// read section at postion 2 into buff
n, err := sectionReader.ReadAt(buff, 2)
if err != nil {
fmt.Println(err)
}
fmt.Printf("Read %d bytes of %s \n", n, string(buff[:]))
}
Output :
EOF
Read 6 bytes of efghij
Reference :
Advertisement
Something interesting
Tutorials
+6.9k Golang : Calculate BMI and risk category
+8.9k Golang : Sort lines of text example
+30.5k Get client IP Address in Go
+7.9k Golang : Trim everything onward after a word
+8.3k Useful methods to access blocked websites
+16.1k Golang : Generate universally unique identifier(UUID) example
+7.7k Golang : Generate human readable password
+7.3k Golang : Calculate how many weeks left to go in a given year
+10.3k Golang : Embed secret text string into binary(executable) file
+6.3k Golang : Test input string for unicode example
+9k Golang : Capture text return from exec function example