Created
December 25, 2019 21:59
-
-
Save steevehook/8e6f79aa627fee0a63d6949a572d9d68 to your computer and use it in GitHub Desktop.
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
func findJSONEnd(file *os.File, end byte) int64 { | |
fileInfo, err := file.Stat() | |
if err != nil { | |
log.Fatalf("could not read file stat: %v", err) | |
} | |
size := fileInfo.Size() | |
var ret int64 | |
for i := 1; i <= int(size); i++ { | |
bs := make([]byte, 1) | |
r, err := file.Seek(-int64(i), io.SeekEnd) | |
if err != nil { | |
log.Fatalf("could not seek at: %d: %v", -int64(i), err) | |
} | |
_, err = file.Read(bs) | |
if err != nil { | |
log.Fatalf("could read from file: %v", err) | |
} | |
if bs[0] == end { | |
ret = r | |
} | |
} | |
return ret | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment