Add InfoHash.HexString convenience

This commit is contained in:
Matt Joiner 2014-12-01 16:34:45 -06:00
parent 8a0be03eec
commit 18d6f81184
2 changed files with 13 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package torrent
import ( import (
"crypto" "crypto"
"errors" "errors"
"fmt"
"math/rand" "math/rand"
"os" "os"
"path/filepath" "path/filepath"
@ -32,6 +33,10 @@ func (ih *InfoHash) AsString() string {
return string(ih[:]) return string(ih[:])
} }
func (ih *InfoHash) HexString() string {
return fmt.Sprintf("%x", ih[:])
}
type piece struct { type piece struct {
Hash pieceSum Hash pieceSum
PendingChunkSpecs map[chunkSpec]struct{} PendingChunkSpecs map[chunkSpec]struct{}

View File

@ -67,3 +67,11 @@ func TestAppendToCopySlice(t *testing.T) {
t.FailNow() t.FailNow()
} }
} }
func TestTorrentString(t *testing.T) {
tor := &torrent{}
s := tor.InfoHash.HexString()
if s != "0000000000000000000000000000000000000000" {
t.FailNow()
}
}