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
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+18k Golang : How to log each HTTP request to your web server?
+12.3k Golang : Validate email address
+13.2k Golang : How to calculate the distance between two coordinates using Haversine formula
+44.9k Golang : Use wildcard patterns with filepath.Glob() example
+6.9k Mac/Linux/Windows : Get CPU information from command line
+5.9k AWS S3 : Prevent Hotlinking policy
+23.9k Golang : Fix type interface{} has no field or no methods and type assertions example
+14k Golang : concatenate(combine) strings
+24.5k Golang : GORM read from database example
+16.1k Golang : Generate universally unique identifier(UUID) example
+7.3k Golang : Calculate how many weeks left to go in a given year