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
+10.2k Golang : How to profile or log time spend on execution?
+8.1k Golang : Variadic function arguments sanity check example
+15.3k Golang : Get query string value on a POST request
+7.6k Javascript : Push notifications to browser with Push.js
+7k Golang : constant 20013 overflows byte error message
+5.2k Golang : Convert lines of string into list for delete and insert operation
+13.4k Golang : Verify token from Google Authenticator App
+14.2k Golang : Fix image: unknown format error
+7.8k Golang : Example of how to detect which type of script a word belongs to
+31.6k Golang : Get local IP and MAC address
+8.3k Swift : Convert (cast) Character to Integer?
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)