]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add InfoHash.HexString convenience
authorMatt Joiner <anacrolix@gmail.com>
Mon, 1 Dec 2014 22:34:45 +0000 (16:34 -0600)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 1 Dec 2014 22:34:45 +0000 (16:34 -0600)
misc.go
torrent_test.go

diff --git a/misc.go b/misc.go
index b96faf06573ea3d19c3e275df9ba7e2f567a5077..6b589e2490c0606fc8283aa781a44729bc1f01c8 100644 (file)
--- 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{}
index eedb4beadd8a9274adb31428a41831220327d587..ffe43ca7cdd231848b94325386924ef26a875b91 100644 (file)
@@ -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()
+       }
+}