Created
March 29, 2019 15:07
-
-
Save ph/c043c90dfd3ac3627bb8044d5ab48fda to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
"os" | |
"time" | |
) | |
const logFile = "/tmp/file.txt" | |
func main() { | |
stats, err := os.Stat(logFile) | |
if err != nil { | |
panic(err) | |
} | |
size := stats.Size() | |
fmt.Printf("Openfile of size: %d\n", size) | |
f, err := os.OpenFile(logFile, os.O_RDONLY, 0600) | |
if err != nil { | |
panic(err) | |
} | |
defer f.Close() | |
seekTo := size - 100 | |
fmt.Printf("Start seeking to %d\n", seekTo) | |
start := time.Now() | |
f.Seek(seekTo, os.SEEK_SET) | |
b := make([]byte, 1024) | |
if _, err := f.Read(b); err != nil { | |
panic(err) | |
} | |
end := time.Now() | |
fmt.Println(b) | |
fmt.Printf("Seek took: %s\n", end.Sub(start)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment