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 (
"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{}

View 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()
}
}