From 18d6f81184b0fe3205a5ce6baf499373654b1f3b Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 1 Dec 2014 16:34:45 -0600 Subject: [PATCH] Add InfoHash.HexString convenience --- misc.go | 5 +++++ torrent_test.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/misc.go b/misc.go index b96faf06..6b589e24 100644 --- a/misc.go +++ b/misc.go @@ -3,6 +3,7 @@ package torrent import ( "crypto" "errors" + "fmt" "math/rand" "os" "path/filepath" @@ -32,6 +33,10 @@ func (ih *InfoHash) AsString() string { return string(ih[:]) } +func (ih *InfoHash) HexString() string { + return fmt.Sprintf("%x", ih[:]) +} + type piece struct { Hash pieceSum PendingChunkSpecs map[chunkSpec]struct{} diff --git a/torrent_test.go b/torrent_test.go index eedb4bea..ffe43ca7 100644 --- a/torrent_test.go +++ b/torrent_test.go @@ -67,3 +67,11 @@ func TestAppendToCopySlice(t *testing.T) { t.FailNow() } } + +func TestTorrentString(t *testing.T) { + tor := &torrent{} + s := tor.InfoHash.HexString() + if s != "0000000000000000000000000000000000000000" { + t.FailNow() + } +} -- 2.44.0