aboutsummaryrefslogtreecommitdiff
path: root/meta
diff options
context:
space:
mode:
Diffstat (limited to 'meta')
-rw-r--r--meta/info.go11
-rw-r--r--meta/piece.go19
2 files changed, 7 insertions, 23 deletions
diff --git a/meta/info.go b/meta/info.go
index 51378ed..778c394 100644
--- a/meta/info.go
+++ b/meta/info.go
@@ -19,22 +19,13 @@ type Info struct {
Pieces Pieces `bencode:"pieces"`
Private bool `bencode:"private"` // BEP-0027
RootHash []byte `bencode:"root hash"` // BEP-0030
- Raw []byte `bencode:"-"`
+ Raw []byte `bencode:"-"` // raw representation of bencoded structure
}
func (i Info) Hash() [sha1.Size]byte {
return sha1.Sum(i.Raw)
}
-// NPieces returns number of all pieces
-func (i Info) NPieces() int {
- full, last := i.Full(), i.Last()
- if last > 0 {
- return full + 1
- }
- return full
-}
-
// Full returns count of full pieces
func (i Info) Full() int {
return int(i.TotalLength() / int64(i.PieceLength))
diff --git a/meta/piece.go b/meta/piece.go
index ee39d36..3878818 100644
--- a/meta/piece.go
+++ b/meta/piece.go
@@ -2,11 +2,16 @@ package meta
import (
"crypto/sha1"
- "fmt"
"dim13.org/btget/bencode"
)
+type Piece [sha1.Size]byte
+
+func (p Piece) Check(b []byte) bool {
+ return sha1.Sum(b) == p
+}
+
type Pieces []Piece
func (p *Pieces) UnmarshalBencode(b []byte) (int, error) {
@@ -23,15 +28,3 @@ func (p *Pieces) UnmarshalBencode(b []byte) (int, error) {
}
return n, nil
}
-
-type Piece [sha1.Size]byte
-
-func (p Piece) Check(b []byte) bool {
- return sha1.Sum(b) == p
-}
-
-type Percent float64
-
-func (p Percent) String() string {
- return fmt.Sprintf("%6.2f%%", p)
-}