From: Matt Joiner Date: Mon, 1 Dec 2014 22:34:45 +0000 (-0600) Subject: Add InfoHash.HexString convenience X-Git-Tag: v1.0.0~1451 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=18d6f81184b0fe3205a5ce6baf499373654b1f3b;p=btrtrc.git Add InfoHash.HexString convenience --- 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() + } +}