aboutsummaryrefslogtreecommitdiff
path: root/meta/torrent.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-07-06 03:16:54 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-07-06 03:16:54 +0200
commite7daf8c15a1b0e3afa06fc8ccc5f1fc9d4c8cbaa (patch)
treeb3024820f8191610f622efa6eda75c4e77f86a8a /meta/torrent.go
parent910a5ae2c7ac25184afed9334f271581deb31fd1 (diff)
wip
Diffstat (limited to 'meta/torrent.go')
-rw-r--r--meta/torrent.go35
1 files changed, 4 insertions, 31 deletions
diff --git a/meta/torrent.go b/meta/torrent.go
index 7ab4bec..20496be 100644
--- a/meta/torrent.go
+++ b/meta/torrent.go
@@ -1,7 +1,6 @@
package meta
import (
- "bytes"
"crypto/sha1"
"errors"
"fmt"
@@ -22,11 +21,6 @@ func (f File) Name() string {
return path.Join(f.Path...)
}
-type Piece struct {
- Length int
- CheckSum [sha1.Size]byte
-}
-
type Info struct {
Files []File `bencode:"files"`
Length int `bencode:"length"`
@@ -62,34 +56,12 @@ func (i Info) GetPieces() []Piece {
p[k].Length = length
}
off := k * sha1.Size
- copy(p[k].CheckSum[:], i.Pieces[off:off+sha1.Size])
+ copy(p[k].Sum[:], i.Pieces[off:off+sha1.Size])
+ p[k].Offset = k * i.PieceLength
}
return p
}
-func (i Info) NPieces() int {
- return len(i.Pieces) / sha1.Size
-}
-
-func (i Info) Check(b []byte, n int) bool {
- sum := sha1.Sum(b)
- off := n * sha1.Size
- return bytes.Equal(i.Pieces[off:off+sha1.Size], sum[:])
-}
-
-func (i Info) CheckSum(n int) []byte {
- off := n * sha1.Size
- return i.Pieces[off : off+sha1.Size]
-}
-
-func (i Info) CheckSums() [][]byte {
- cs := make([][]byte, i.NPieces())
- for n := 0; n < i.NPieces(); n++ {
- cs[n] = i.CheckSum(n)
- }
- return cs
-}
-
func (i Info) FullPath(n int) (string, error) {
if i.isSingleFile() {
return i.Name, nil
@@ -121,11 +93,12 @@ func (i Info) FindFile(off int) (int, int) {
* 0 1 2 3 4 5 6 7 #file
*/
+// FIXME WriteAt ...
func (i Info) WriteAt(b []byte, off int64) (n int, err error) {
return 0, ErrNotImplemented
}
-// ReadAt ...
+// FIXME ReadAt ...
func (i Info) ReadAt(b []byte, off int64) (n int, err error) {
if i.isSingleFile() {
fd, err := os.OpenFile(i.Name, os.O_RDWR|os.O_CREATE, 0644)