From 22424e6fa01cafdeb42134620f70f528825c47e5 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 6 Jul 2016 02:08:36 +0200 Subject: wip --- meta/torrent.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'meta/torrent.go') 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 } -- cgit v1.2.3