]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Improve metainfo pprinting since BT v2 support
authorMatt Joiner <anacrolix@gmail.com>
Mon, 19 May 2025 04:50:28 +0000 (14:50 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 19 May 2025 04:50:28 +0000 (14:50 +1000)
file.go
iter.go [new file with mode: 0644]
metainfo/bep47.go
metainfo/file-tree.go
metainfo/fileinfo.go

diff --git a/file.go b/file.go
index 26c3812319d987b2db30eec94a6fa6d6f6eefba6..e3739724cb9d07c1dddbd7fd487997ccab27a69b 100644 (file)
--- a/file.go
+++ b/file.go
@@ -1,13 +1,12 @@
 package torrent
 
 import (
-       "crypto/sha256"
-
        "github.com/RoaringBitmap/roaring"
        g "github.com/anacrolix/generics"
        "github.com/anacrolix/missinggo/v2/bitmap"
 
        "github.com/anacrolix/torrent/metainfo"
+       infohash_v2 "github.com/anacrolix/torrent/types/infohash-v2"
 )
 
 // Provides access to regions of torrent data that correspond to its files.
@@ -19,7 +18,7 @@ type File struct {
        fi          metainfo.FileInfo
        displayPath string
        prio        PiecePriority
-       piecesRoot  g.Option[[sha256.Size]byte]
+       piecesRoot  g.Option[infohash_v2.T]
 }
 
 func (f *File) String() string {
diff --git a/iter.go b/iter.go
new file mode 100644 (file)
index 0000000..10cbafc
--- /dev/null
+++ b/iter.go
@@ -0,0 +1 @@
+package torrent
index 884d88d65a4d68bce5484224ca41403afc509028..e8f04c8ccf86e197b6c135258e9ba23929d107c0 100644 (file)
@@ -2,7 +2,7 @@ package metainfo
 
 // See BEP 47. This is common to both Info and FileInfo.
 type ExtendedFileAttrs struct {
-       Attr        string   `bencode:"attr,omitempty"`
-       SymlinkPath []string `bencode:"symlink path,omitempty"`
-       Sha1        string   `bencode:"sha1,omitempty"`
+       Attr        string   `bencode:"attr,omitempty" json:"attr,omitempty"`
+       SymlinkPath []string `bencode:"symlink path,omitempty" json:"symlink path,omitempty"`
+       Sha1        string   `bencode:"sha1,omitempty" json:"sha1,omitempty"`
 }
index 08039e6dd1970170269fdaafab20c9503c8bbbdf..27c87d2c4222be02898d97c802b4dbedeebdc540 100644 (file)
@@ -8,6 +8,7 @@ import (
        g "github.com/anacrolix/generics"
 
        "github.com/anacrolix/torrent/bencode"
+       infohash_v2 "github.com/anacrolix/torrent/types/infohash-v2"
 )
 
 const FileTreePropertiesKey = ""
@@ -144,7 +145,7 @@ func (ft *FileTree) Walk(path []string, f func(path []string, ft *FileTree)) {
        }
 }
 
-func (ft *FileTree) PiecesRootAsByteArray() (ret g.Option[[32]byte]) {
+func (ft *FileTree) PiecesRootAsByteArray() (ret g.Option[infohash_v2.T]) {
        if ft.File.PiecesRoot == "" {
                return
        }
index 867a56d04d3cd0e94d5d5b38fa957d41d25e5804..9b501fde6314729041c0b5d9915d423c37c3e36b 100644 (file)
@@ -4,6 +4,8 @@ import (
        "strings"
 
        g "github.com/anacrolix/generics"
+
+       infohash_v2 "github.com/anacrolix/torrent/types/infohash-v2"
 )
 
 // Information specific to a single file inside the MetaInfo structure.
@@ -14,14 +16,14 @@ type FileInfo struct {
        Path   []string `bencode:"path"` // BEP3
        // Unofficial extension by BiglyBT? https://github.com/BiglySoftware/BiglyBT/issues/1274. Might
        // be a safer bet when available: https://github.com/anacrolix/torrent/pull/915.
-       PathUtf8 []string `bencode:"path.utf-8,omitempty"`
+       PathUtf8 []string `bencode:"path.utf-8,omitempty" json:"path.utf-8,omitempty"`
 
-       ExtendedFileAttrs
+       ExtendedFileAttrs `json:",omitempty"`
 
        // BEP 52. This isn't encoded in a v1 FileInfo, but is exposed here for APIs that expect to deal
        // v1 files.
-       PiecesRoot    g.Option[[32]byte] `bencode:"-"`
-       TorrentOffset int64              `bencode:"-"`
+       PiecesRoot    g.Option[infohash_v2.T] `bencode:"-" json:"-"`
+       TorrentOffset int64                   `bencode:"-" json:"-"`
 }
 
 func (fi *FileInfo) DisplayPath(info *Info) string {