aboutsummaryrefslogtreecommitdiff
path: root/meta/torrent.go
diff options
context:
space:
mode:
Diffstat (limited to 'meta/torrent.go')
-rw-r--r--meta/torrent.go34
1 files changed, 10 insertions, 24 deletions
diff --git a/meta/torrent.go b/meta/torrent.go
index 886668f..002480c 100644
--- a/meta/torrent.go
+++ b/meta/torrent.go
@@ -5,12 +5,10 @@ import (
"crypto/sha1"
"errors"
"fmt"
- "io/ioutil"
+ "log"
"os"
"path"
"time"
-
- "dim13.org/btget/bencode"
)
var ErrNotImplemented = errors.New("not implemented")
@@ -31,32 +29,19 @@ type Info struct {
Private bool `bencode:"private"`
}
-func New(fname string) (Torrent, error) {
- var tor Torrent
- body, err := ioutil.ReadFile(fname)
- if err != nil {
- return Torrent{}, err
- }
- err = bencode.Unmarshal(body, &tor)
- if err != nil {
- return Torrent{}, err
- }
- return tor, nil
-}
-
func (i Info) NPieces() int {
- return len(i.Pieces) / 20
+ return len(i.Pieces) / sha1.Size
}
func (i Info) Check(b []byte, n int) bool {
sum := sha1.Sum(b)
- off := n * 20
- return bytes.Equal(i.Pieces[off:off+20], sum[:])
+ off := n * sha1.Size
+ return bytes.Equal(i.Pieces[off:off+sha1.Size], sum[:])
}
func (i Info) CheckSum(n int) []byte {
- off := n * 20
- return i.Pieces[off : off+20]
+ off := n * sha1.Size
+ return i.Pieces[off : off+sha1.Size]
}
func (i Info) CheckSums() [][]byte {
@@ -98,16 +83,17 @@ func (i Info) Offset(piece int) int {
return i.PieceLength * piece
}
-func (i Info) FileOffset(piece int) (int, int, bool) {
+func (i Info) FileOffset(piece int) (int, int) {
off := i.PieceLength * piece
for n, l := range i.Files {
if l.Length < off {
off -= l.Length
} else {
- return n, off, off+i.PieceLength > i.Length
+ log.Println(n, off, i.PieceLength-off)
+ return n, off
}
}
- return 0, off, false
+ return 0, off
}
/*