From e7daf8c15a1b0e3afa06fc8ccc5f1fc9d4c8cbaa Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 6 Jul 2016 03:16:54 +0200 Subject: wip --- meta/torrent.go | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) (limited to 'meta/torrent.go') 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) -- cgit v1.2.3