aboutsummaryrefslogtreecommitdiff
path: root/meta
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-06-12 21:24:43 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-06-12 21:24:43 +0200
commite0c077f328c0880cb8326de4f7718aaeae140796 (patch)
tree955f378e7d97a27710f1b5933a087d082f74cb55 /meta
parentb2c50217ea7fc15e46b7b113f996ee72b7adbd94 (diff)
Piece Count
Diffstat (limited to 'meta')
-rw-r--r--meta/torrent.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/meta/torrent.go b/meta/torrent.go
index 33eebd2..358ed01 100644
--- a/meta/torrent.go
+++ b/meta/torrent.go
@@ -12,10 +12,6 @@ type File struct {
Path []string `bencode:"path"`
}
-func (f File) String() string {
- return fmt.Sprintf("%s (%d)", path.Join(f.Path...), f.Length)
-}
-
type Info struct {
Length int `bencode:"length"`
MD5Sum []byte `bencode:"md5sum,optional"`
@@ -26,16 +22,30 @@ type Info struct {
Private bool `bencode:"private"`
}
+func (i Info) SingleFile() bool {
+ return len(i.Files) > 0
+}
+
+// returns pieceCoung and size of last piece
+func (i Info) pieceCount() int {
+ n := i.Length / i.PieceLength
+ if i.Length%i.PieceLength > 0 {
+ n++
+ }
+ return n
+}
+
func (i Info) String() string {
var s string
if l := len(i.Files); l > 0 {
s += fmt.Sprintln("files:", l)
for _, f := range i.Files {
- s += fmt.Sprintln(f)
+ s += fmt.Sprintf(" %s (%d)\n", path.Join(i.Name, path.Join(f.Path...)), f.Length)
+ i.Length += f.Length
}
}
s += fmt.Sprintf("%s (%d)\n", i.Name, i.Length)
- s += fmt.Sprintf("chunks: %d * %d + %d\n",
+ s += fmt.Sprintf("chunks: %d × %d + %d\n",
i.Length/i.PieceLength, i.PieceLength, i.Length%i.PieceLength)
return s
}