README | 4 ++-- cmd/repack/main.go | 30 ++++++++++++++++++++++++++++++ cmd/search/main.go | 20 +++++++------------- diff --git a/README b/README index 70eaa9dd2d27c084a4a47f8f8414387c85a48ccd5487a77c89d68a0bbd8707c5..d4dad7fc3c031d5ef6e8715e10004838af18af6c44feeff6a1ecc8ddb0d76fd9 100644 --- a/README +++ b/README @@ -16,9 +16,9 @@ quickly feed in further commands. That XML is huge, so you can get some troubles searching in it quickly. So here are the indexer, that extracts titles, sizes, hashes and XML offsets: - $ cmd/index < rutracker-XXX.xml > rutracker.gob + $ cmd/index < rutracker-XXX.xml | cmd/repack > rutracker.gob -On my computer is works for several minutes, that is pretty fast. +On my computer that takes seven minutes. After that, you can search the desired title like that: diff --git a/cmd/repack/main.go b/cmd/repack/main.go new file mode 100644 index 0000000000000000000000000000000000000000..6e6690fa44e0a785cf116751db122e63dccab52c9d68f9e3317f6bf332c2ed8a --- /dev/null +++ b/cmd/repack/main.go @@ -0,0 +1,30 @@ +package main + +import ( + "bufio" + "encoding/gob" + "io" + "os" + + "go.stargrave.org/rutrackerer" +) + +func main() { + gobDec := gob.NewDecoder(bufio.NewReader(os.Stdin)) + torrents := make([]*rutrackerer.Torrent, 0, 1<<20) + var err error + for { + var torrent rutrackerer.Torrent + if err = gobDec.Decode(&torrent); err != nil { + if err == io.EOF { + break + } + panic(err) + } + torrents = append(torrents, &torrent) + } + gobEnc := gob.NewEncoder(os.Stdout) + if err = gobEnc.Encode(torrents); err != nil { + panic(err) + } +} diff --git a/cmd/search/main.go b/cmd/search/main.go index bd3941da9028358e634a4b4206823ff99785069d6e8a9147eb296c4364083172..61607b2972cd61677553eb779f09a8e5ef5f75ae9b20b6587056f25f3e9036b3 100644 --- a/cmd/search/main.go +++ b/cmd/search/main.go @@ -5,7 +5,6 @@ "bufio" "encoding/gob" "encoding/hex" "fmt" - "io" "os" "os/exec" "strconv" @@ -28,7 +27,11 @@ } if err = cmd.Start(); err != nil { panic(err) } - torrents := make([]*rutrackerer.Torrent, 0, 1<<20) + var torrents []*rutrackerer.Torrent + gobDec := gob.NewDecoder(bufio.NewReader(os.Stdin)) + if err = gobDec.Decode(&torrents); err != nil { + panic(err) + } printer := make(chan struct{}) go func() { scanner := bufio.NewScanner(grepStdout) @@ -63,17 +66,8 @@ panic(err) } close(printer) }() - gobDec := gob.NewDecoder(bufio.NewReader(os.Stdin)) - for { - var torrent rutrackerer.Torrent - if err = gobDec.Decode(&torrent); err != nil { - if err == io.EOF { - break - } - panic(err) - } - torrents = append(torrents, &torrent) - if _, err = grepStdin.Write([]byte(torrent.Title + "\n")); err != nil { + for _, t := range torrents { + if _, err = grepStdin.Write([]byte(t.Title + "\n")); err != nil { panic(err) } }