Skip to content

Instantly share code, notes, and snippets.

@wthorp
Created August 15, 2018 10:35
Show Gist options
  • Save wthorp/ac037078809d3fc9b22b085f73daa292 to your computer and use it in GitHub Desktop.
Save wthorp/ac037078809d3fc9b22b085f73daa292 to your computer and use it in GitHub Desktop.
file.ReadAt() always reads at offset 0
package main
import (
"fmt"
"io"
"os"
)
func main() {
file, err := os.Open("test.go")
buffer := make([]byte, 32, 32)
//var err error
bytesRead := 0
offset := int64(0)
for bytesRead, err = file.ReadAt(buffer, offset); bytesRead > 0 && err != io.EOF; offset += int64(bytesRead) {
fmt.Printf("%s", string(buffer[0:bytesRead]))
fmt.Printf("%d %d\n", bytesRead, offset)
if offset > 473 {
fmt.Printf("Offset > EOF")
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment