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
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example
+8.3k Golang : Configure Apache and NGINX to access your Go service example
+16k Golang : Get sub string example
+5.6k Unix/Linux : How to find out the hard disk size?
+12.8k Golang : http.Get example
+27.6k PHP : Convert(cast) string to bigInt
+7.9k Javascript : Put image into Chrome browser's console
+11.3k Golang : How to flush a channel before the end of program?
+6.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+7k Golang : Takes a plural word and makes it singular
+7.5k Golang : Detect sample rate, channels or latency with PortAudio
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream