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.7k Golang : missing Mercurial command
+14.2k Golang : Fix image: unknown format error
+23.5k Golang : Get ASCII code from a key press(cross-platform) example
+19.5k Golang : How to Set or Add Header http.ResponseWriter?
+4.9k Unix/Linux : secure copying between servers with SCP command examples
+14.6k Golang : Send email with attachment(RFC2822) using Gmail API example
+15.6k Golang : How to convert(cast) IP address to string?
+5.3k PHP : Hide PHP version information from curl
+5.4k Gogland : Datasource explorer
+17.6k Golang : Upload/Receive file progress indicator
+15.2k Golang : How to check if IP address is in range
+13.5k Golang : Count number of runes in string