aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-07-06 02:08:36 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-07-06 02:08:36 +0200
commit22424e6fa01cafdeb42134620f70f528825c47e5 (patch)
treec7817929d5f272ba96329446d983d3c2af1d9aa6
parented314439d5acc345e5101d61afb366c55c2921f8 (diff)
wip
-rw-r--r--meta/torrent.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/meta/torrent.go b/meta/torrent.go
index 9d77e5c..c46a105 100644
--- a/meta/torrent.go
+++ b/meta/torrent.go
@@ -37,7 +37,7 @@ type Info struct {
Private bool `bencode:"private"`
}
-func (i Info) GetLength() int {
+func (i Info) TotalLength() int {
if i.Length > 0 {
return i.Length
}
@@ -49,7 +49,7 @@ func (i Info) GetLength() int {
}
func (i Info) GetPieces() []Piece {
- length := i.GetLength()
+ length := i.TotalLength()
n := length / i.PieceLength
last := length % i.PieceLength
if last > 0 {
@@ -192,10 +192,14 @@ func (i Info) isSingleFile() bool {
return len(i.Files) == 0
}
-// PieceCount returns count of full pieces and size of last piece
-func (i Info) PieceCount() (int, int) {
- length := i.GetLength()
- return length / i.PieceLength, length % i.PieceLength
+// Last returns size of last truncated piece
+func (i Info) Last() int {
+ return i.TotalLength() % i.PieceLength
+}
+
+// Full returns count of full pieces
+func (i Info) Full() int {
+ return i.TotalLength() / i.PieceLength
}
func (i Info) String() string {
@@ -207,9 +211,8 @@ func (i Info) String() string {
}
s += fmt.Sprintf(" %s (%d)\n", p, f.Length)
}
- s += fmt.Sprintf("%s (%d) ", i.Name, i.GetLength())
- full, last := i.PieceCount()
- s += fmt.Sprintf("%d × %d + %d\n", full, i.PieceLength, last)
+ s += fmt.Sprintf("%s (%d) ", i.Name, i.TotalLength())
+ s += fmt.Sprintf("%d × %d + %d\n", i.Full(), i.PieceLength, i.Last())
return s
}