Created
August 15, 2018 10:35
-
-
Save wthorp/ac037078809d3fc9b22b085f73daa292 to your computer and use it in GitHub Desktop.
file.ReadAt() always reads at offset 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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