Created
March 14, 2017 12:36
-
-
Save ma6174/e6f431eb1818f2092ca93ebd06373901 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
package main | |
import ( | |
"encoding/binary" | |
"io" | |
"log" | |
"os" | |
) | |
func readInt32(rd io.Reader) (int32, error) { | |
var i int32 | |
if err := binary.Read(rd, binary.LittleEndian, &i); err != nil { | |
return 0, err | |
} | |
return i, nil | |
} | |
func main() { | |
f, err := os.Open(os.Args[1]) | |
if err != nil { | |
log.Fatal(err) | |
} | |
var count uint64 | |
for { | |
n, err := readInt32(f) | |
if err != nil { | |
if err == io.EOF { | |
break | |
} | |
log.Fatal(err) | |
} | |
_, err = f.Seek(int64(n-4), 1) | |
if err != nil { | |
log.Fatal(err) | |
} | |
count += 1 | |
if count%100000000 == 0 { | |
log.Println(count) | |
} | |
} | |
log.Println("count:", count) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment