From: Matt Joiner Date: Fri, 23 Oct 2015 01:42:19 +0000 (+1100) Subject: cmd/torrent: Expose --mmap X-Git-Tag: v1.0.0~1006 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=b8da06a88533c28971fd6eb24bc293ec25a19277;p=btrtrc.git cmd/torrent: Expose --mmap --- diff --git a/cmd/torrent/main.go b/cmd/torrent/main.go index 05ea9e5b..1b06efb6 100644 --- a/cmd/torrent/main.go +++ b/cmd/torrent/main.go @@ -16,6 +16,7 @@ import ( "github.com/jessevdk/go-flags" "github.com/anacrolix/torrent" + "github.com/anacrolix/torrent/data/mmap" "github.com/anacrolix/torrent/metainfo" ) @@ -72,6 +73,7 @@ func main() { 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 @@ -87,6 +89,15 @@ func main() { 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 { fmt.Fprintln(os.Stderr, "no torrents specified")