cmd/torrent/main.go | 11 +++++++++++ diff --git a/cmd/torrent/main.go b/cmd/torrent/main.go index 05ea9e5baf70f3343eae991e3caf58e2f4074676..1b06efb64b8d57594ff44e3b47d3ad4d88a04844 100644 --- a/cmd/torrent/main.go +++ b/cmd/torrent/main.go @@ -16,6 +16,7 @@ "github.com/dustin/go-humanize" "github.com/jessevdk/go-flags" "github.com/anacrolix/torrent" + "github.com/anacrolix/torrent/data/mmap" "github.com/anacrolix/torrent/metainfo" ) @@ -72,6 +73,7 @@ log.SetFlags(log.LstdFlags | log.Lshortfile) var rootGroup struct { Client torrent.Config `group:"Client Options"` TestPeers []string `long:"test-peer" description:"address of peer to inject to every torrent"` + MMap bool `long:"mmap" description:"memory-map the torrent files"` } // Don't pass flags.PrintError because it's inconsistent with printing. // https://github.com/jessevdk/go-flags/issues/132 @@ -86,6 +88,15 @@ } testPeers, err := resolvedPeerAddrs(rootGroup.TestPeers) if err != nil { log.Fatal(err) + } + if rootGroup.MMap { + rootGroup.Client.TorrentDataOpener = func(info *metainfo.Info) torrent.Data { + ret, err := mmap.TorrentData(info, "") + if err != nil { + log.Fatalf("error opening torrent data for %q: %s", info.Name, err) + } + return ret + } } if len(posArgs) == 0 {