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
+12.1k Golang : Pagination with go-paginator configuration example
+14.2k Golang : Fix image: unknown format error
+18.6k Golang : Generate thumbnails from images
+7.9k Javascript : How to check a browser's Do Not Track status?
+4.3k Javascript : How to show different content with noscript?
+7.3k Golang : Of hash table and hash map
+10.6k Golang : Simple File Server
+9.1k Golang : How to capture return values from goroutines?
+21.2k Golang : Clean up null characters from input data
+8k Golang : Handle Palindrome string with case sensitivity and unicode
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)