From 55ef14362847e64d24ae6b6395b1ce2d7299c3ce Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 14 Aug 2025 17:13:48 +1000 Subject: [PATCH] Small improvements to cmd/torrent2 metainfo pprint --- cmd/torrent2/main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/torrent2/main.go b/cmd/torrent2/main.go index b215ee1c..ff26dea5 100644 --- a/cmd/torrent2/main.go +++ b/cmd/torrent2/main.go @@ -72,6 +72,8 @@ func mainErr() error { assertOk(err) info, err := mi.UnmarshalInfo() assertOk(err) + fmt.Printf("name: %q\n", info.Name) + fmt.Printf("# files:\n") files := info.UpvertedFiles() pieceIndex := 0 for _, f := range files { @@ -82,9 +84,14 @@ func mainErr() error { hash = a.HexString() } fmt.Printf( - "%s: %q: pieces (%v-%v)\n", + "%s: %v: pieces (%v-%v)\n", hash, - f.BestPath(), + func() any { + if info.IsDir() { + return fmt.Sprintf("%q", f.BestPath()) + } + return "(single file torrent)" + }(), pieceIndex, endIndex-1, ) -- 2.51.0